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 } class Spina.TrixAttachment @photoSelect: (e) -> console.log 'hi' editor_id = $(this).closest('trix-toolbar').data('trix-editor-id') $.get("<%= Spina::Engine.routes.url_helpers.trix_select_admin_photos_path('') %>/#{editor_id}") @photoInsert: (e, url) -> length = this.editor.getDocument().toString().length this.editor.setSelectedRange(length - 1) this.editor.insertHTML "" document.addEventListener 'trix-file-accept', (e) -> e.preventDefault() $(document).on 'click', '.js-trix-photo', Spina.TrixAttachment.photoSelect $(document).on 'photo-insert', 'trix-editor', Spina.TrixAttachment.photoInsert