button.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Generated by CoffeeScript 1.11.1
  2. (function($) {
  3. $(function() {
  4. $('body').on('grav-editor-ready', function() {
  5. var Instance;
  6. Instance = Grav["default"].Forms.Fields.EditorField.Instance;
  7. Instance.addButton({
  8. vimeo: {
  9. identifier: 'vimeo-video',
  10. title: GravVimeoPlugin.translations.EDITOR_BUTTON_TOOLTIP,
  11. label: '<i class="fa fa-fw fa-vimeo"></i>',
  12. modes: ['gfm', 'markdown'],
  13. action: function(e) {
  14. e.button.on('click.editor.vimeo', function() {
  15. var i, l, pos, posend, ref, ref1, text, videoId;
  16. videoId = prompt(GravVimeoPlugin.translations.EDITOR_BUTTON_PROMPT);
  17. if (videoId) {
  18. text = "[plugin:vimeo](https://vimeo.com/" + videoId + ")";
  19. pos = e.codemirror.getDoc().getCursor(true);
  20. posend = e.codemirror.getDoc().getCursor(false);
  21. for (l = i = ref = pos.line, ref1 = posend.line; ref <= ref1 ? i <= ref1 : i >= ref1; l = ref <= ref1 ? ++i : --i) {
  22. e.codemirror.replaceRange(text + e.codemirror.getLine(l), {
  23. line: l,
  24. ch: 0
  25. }, {
  26. line: l,
  27. ch: e.codemirror.getLine(l).length
  28. });
  29. }
  30. e.codemirror.setCursor({
  31. line: posend.line,
  32. ch: e.codemirror.getLine(posend.line).length
  33. });
  34. e.codemirror.focus();
  35. }
  36. });
  37. }
  38. }
  39. });
  40. });
  41. });
  42. })(jQuery);