plugin.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * plugin.js
  3. *
  4. * Copyright, Moxiecode Systems AB
  5. * Released under LGPL License.
  6. *
  7. * License: http://www.tinymce.com/license
  8. * Contributing: http://www.tinymce.com/contributing
  9. */
  10. /*global tinymce:true */
  11. tinymce.PluginManager.add('code', function(editor) {
  12. function showDialog() {
  13. editor.windowManager.open({
  14. title: "Source code",
  15. body: {
  16. type: 'textbox',
  17. name: 'code',
  18. multiline: true,
  19. minWidth: editor.getParam("code_dialog_width", 600),
  20. minHeight: editor.getParam("code_dialog_height", Math.min(tinymce.DOM.getViewPort().h - 200, 500)),
  21. value: editor.getContent({source_view: true}),
  22. spellcheck: false,
  23. style: 'direction: ltr; text-align: left'
  24. },
  25. onSubmit: function(e) {
  26. // We get a lovely "Wrong document" error in IE 11 if we
  27. // don't move the focus to the editor before creating an undo
  28. // transation since it tries to make a bookmark for the current selection
  29. editor.focus();
  30. editor.undoManager.transact(function() {
  31. editor.setContent(e.data.code);
  32. });
  33. editor.selection.setCursorLocation();
  34. editor.nodeChanged();
  35. }
  36. });
  37. }
  38. editor.addCommand("mceCodeEditor", showDialog);
  39. editor.addButton('code', {
  40. icon: 'code',
  41. tooltip: 'Source code',
  42. onclick: showDialog
  43. });
  44. editor.addMenuItem('code', {
  45. icon: 'code',
  46. text: 'Source code',
  47. context: 'tools',
  48. onclick: showDialog
  49. });
  50. });