window.Spina = {}
Trix.config.blockAttributes = $.extend Trix.config.blockAttributes, {
heading2:
tagName: "h2"
terminal: true
breakOnReturn: true
group: false
heading3:
tagName: "h3"
terminal: true
breakOnReturn: true
group: false
heading4:
tagName: "h4"
terminal: true
breakOnReturn: true
group: false
heading5:
tagName: "h5"
terminal: true
breakOnReturn: true
group: false
heading6:
tagName: "h6"
terminal: true
breakOnReturn: true
group: false
}
Trix.config.lang = $.extend Trix.config.lang, {
image: "Image"
heading1: "H1"
heading2: "H2"
heading3: "H3"
heading4: "H4"
heading5: "H5"
heading6: "H6"
}
Trix.config.toolbar =
getDefaultHTML: -> """
"""
class Spina.TrixAttachment
@imageSelect: (e) ->
toolbar_id = $(this).closest('trix-toolbar').attr('id')
$.getScript("<%= Spina::Engine.routes.url_helpers.admin_media_picker_path %>" + "?input=#{toolbar_id}&mode=trix")
@imageInsert: (e) ->
labels = []
labels.push "✍️ #{e.detail.alt}" if e.detail.alt != ""
labels.push "🔗 #{e.detail.link_to_url}" if e.detail.link_to_url != ""
label = labels.join(" ")
if e.detail.link_to_url != ""
attachment = new Trix.Attachment({content: "
"})
else
attachment = new Trix.Attachment({content: "
"})
this.editor.insertAttachment(attachment)
document.addEventListener 'trix-file-accept', (e) ->
e.preventDefault()
$(document).on 'click', '[data-trix-attribute="image"]', Spina.TrixAttachment.imageSelect
$(document).on 'image-insert', 'trix-editor', Spina.TrixAttachment.imageInsert
$(document).on 'click', 'a.trix-attachment-spina-image', (e) ->
e.preventDefault()