button.coffee 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. (($) ->
  2. $ ->
  3. $('body').on 'grav-editor-ready', ->
  4. Instance = Grav.default.Forms.Fields.EditorField.Instance
  5. Instance.addButton vimeo:
  6. identifier: 'vimeo-video'
  7. title: GravVimeoPlugin.translations.EDITOR_BUTTON_TOOLTIP
  8. label: '<i class="fa fa-fw fa-vimeo"></i>'
  9. modes: [
  10. 'gfm',
  11. 'markdown'
  12. ]
  13. action: (e) ->
  14. e.button.on 'click.editor.vimeo', ->
  15. videoId = prompt(GravVimeoPlugin.translations.EDITOR_BUTTON_PROMPT);
  16. if videoId
  17. text = "[plugin:vimeo](https://vimeo.com/#{videoId})"
  18. pos = e.codemirror.getDoc().getCursor(true)
  19. posend = e.codemirror.getDoc().getCursor(false)
  20. for l in [pos.line..posend.line]
  21. e.codemirror.replaceRange( text + e.codemirror.getLine(l), { line: l, ch: 0 }, { line: l, ch: e.codemirror.getLine(l).length })
  22. e.codemirror.setCursor({ line: posend.line, ch: e.codemirror.getLine(posend.line).length })
  23. e.codemirror.focus()
  24. return
  25. return
  26. return
  27. return
  28. return
  29. ) jQuery