Skip to content

Instantly share code, notes, and snippets.

@javan
Created November 8, 2015 16:45
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save javan/20e574f1cae443ba6c59 to your computer and use it in GitHub Desktop.
Save javan/20e574f1cae443ba6c59 to your computer and use it in GitHub Desktop.
buttonHTML = """<button type="button" class="attach" data-action="x-attach">Attach Files</button>"""
fileInputHTML = """<input type="file" multiple>"""
$(Trix.config.toolbar.content).find(".button_group.block_tools").append(buttonHTML)
$(document).on "trix-action-invoke", ($event) ->
if $event.originalEvent.actionName is "x-attach"
editorElement = $event.target
editorElement.focus()
$fileInput = $(fileInputHTML)
$fileInput.on "change", ->
for file in @files
editorElement.editor.insertFile(file)
$fileInput.click()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment