/static/scripts/tiny_mce/plugins/pagebreak/editor_plugin_src.js

http://n23.googlecode.com/ · JavaScript · 74 lines · 55 code · 11 blank · 8 comment · 10 complexity · 1d155d39c2bff2f1e53b1e190e782842 MD5 · raw file

  1. /**
  2. * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
  3. *
  4. * @author Moxiecode
  5. * @copyright Copyright Š 2004-2008, Moxiecode Systems AB, All rights reserved.
  6. */
  7. (function() {
  8. tinymce.create('tinymce.plugins.PageBreakPlugin', {
  9. init : function(ed, url) {
  10. var pb = '<img src="' + url + '/img/trans.gif" class="mcePageBreak mceItemNoResize" />', cls = 'mcePageBreak', sep = ed.getParam('pagebreak_separator', '<!-- pagebreak -->'), pbRE;
  11. pbRE = new RegExp(sep.replace(/[\?\.\*\[\]\(\)\{\}\+\^\$\:]/g, function(a) {return '\\' + a;}), 'g');
  12. // Register commands
  13. ed.addCommand('mcePageBreak', function() {
  14. ed.execCommand('mceInsertContent', 0, pb);
  15. });
  16. // Register buttons
  17. ed.addButton('pagebreak', {title : 'pagebreak.desc', cmd : cls});
  18. ed.onInit.add(function() {
  19. if (ed.settings.content_css !== false)
  20. ed.dom.loadCSS(url + "/css/content.css");
  21. if (ed.theme.onResolveName) {
  22. ed.theme.onResolveName.add(function(th, o) {
  23. if (o.node.nodeName == 'IMG' && ed.dom.hasClass(o.node, cls))
  24. o.name = 'pagebreak';
  25. });
  26. }
  27. });
  28. ed.onClick.add(function(ed, e) {
  29. e = e.target;
  30. if (e.nodeName === 'IMG' && ed.dom.hasClass(e, cls))
  31. ed.selection.select(e);
  32. });
  33. ed.onNodeChange.add(function(ed, cm, n) {
  34. cm.setActive('pagebreak', n.nodeName === 'IMG' && ed.dom.hasClass(n, cls));
  35. });
  36. ed.onBeforeSetContent.add(function(ed, o) {
  37. o.content = o.content.replace(pbRE, pb);
  38. });
  39. ed.onPostProcess.add(function(ed, o) {
  40. if (o.get)
  41. o.content = o.content.replace(/<img[^>]+>/g, function(im) {
  42. if (im.indexOf('class="mcePageBreak') !== -1)
  43. im = sep;
  44. return im;
  45. });
  46. });
  47. },
  48. getInfo : function() {
  49. return {
  50. longname : 'PageBreak',
  51. author : 'Moxiecode Systems AB',
  52. authorurl : 'http://tinymce.moxiecode.com',
  53. infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/pagebreak',
  54. version : tinymce.majorVersion + "." + tinymce.minorVersion
  55. };
  56. }
  57. });
  58. // Register plugin
  59. tinymce.PluginManager.add('pagebreak', tinymce.plugins.PageBreakPlugin);
  60. })();