plugin.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. /*jshint unused:false */
  11. /*global tinymce:true */
  12. /**
  13. * Example plugin that adds a toolbar button and menu item.
  14. */
  15. tinymce.PluginManager.add('example', function(editor, url) {
  16. // Add a button that opens a window
  17. editor.addButton('example', {
  18. text: 'My button',
  19. icon: false,
  20. onclick: function() {
  21. // Open window
  22. editor.windowManager.open({
  23. title: 'Example plugin',
  24. body: [
  25. {type: 'textbox', name: 'title', label: 'Title'}
  26. ],
  27. onsubmit: function(e) {
  28. // Insert content when the window form is submitted
  29. editor.insertContent('Title: ' + e.data.title);
  30. }
  31. });
  32. }
  33. });
  34. // Adds a menu item to the tools menu
  35. editor.addMenuItem('example', {
  36. text: 'Example plugin',
  37. context: 'tools',
  38. onclick: function() {
  39. // Open window with a specific url
  40. editor.windowManager.open({
  41. title: 'TinyMCE site',
  42. url: url + '/dialog.html',
  43. width: 600,
  44. height: 400,
  45. buttons: [
  46. {
  47. text: 'Insert',
  48. onclick: function() {
  49. // Top most window object
  50. var win = editor.windowManager.getWindows()[0];
  51. // Insert the contents of the dialog.html textarea into the editor
  52. editor.insertContent(win.getContentWindow().document.getElementById('content').value);
  53. // Close the window
  54. win.close();
  55. }
  56. },
  57. {text: 'Close', onclick: 'close'}
  58. ]
  59. });
  60. }
  61. });
  62. });