bgneal@312: /**
bgneal@312: * editor_plugin_src.js
bgneal@312: *
bgneal@312: * Copyright 2009, Moxiecode Systems AB
bgneal@312: * Released under LGPL License.
bgneal@312: *
bgneal@312: * License: http://tinymce.moxiecode.com/license
bgneal@312: * Contributing: http://tinymce.moxiecode.com/contributing
bgneal@312: */
bgneal@312:
bgneal@312: (function() {
bgneal@312: tinymce.create('tinymce.plugins.PageBreakPlugin', {
bgneal@312: init : function(ed, url) {
bgneal@312: var pb = '', cls = 'mcePageBreak', sep = ed.getParam('pagebreak_separator', ''), pbRE;
bgneal@312:
bgneal@312: pbRE = new RegExp(sep.replace(/[\?\.\*\[\]\(\)\{\}\+\^\$\:]/g, function(a) {return '\\' + a;}), 'g');
bgneal@312:
bgneal@312: // Register commands
bgneal@312: ed.addCommand('mcePageBreak', function() {
bgneal@312: ed.execCommand('mceInsertContent', 0, pb);
bgneal@312: });
bgneal@312:
bgneal@312: // Register buttons
bgneal@312: ed.addButton('pagebreak', {title : 'pagebreak.desc', cmd : cls});
bgneal@312:
bgneal@312: ed.onInit.add(function() {
bgneal@312: if (ed.settings.content_css !== false)
bgneal@312: ed.dom.loadCSS(url + "/css/content.css");
bgneal@312:
bgneal@312: if (ed.theme.onResolveName) {
bgneal@312: ed.theme.onResolveName.add(function(th, o) {
bgneal@312: if (o.node.nodeName == 'IMG' && ed.dom.hasClass(o.node, cls))
bgneal@312: o.name = 'pagebreak';
bgneal@312: });
bgneal@312: }
bgneal@312: });
bgneal@312:
bgneal@312: ed.onClick.add(function(ed, e) {
bgneal@312: e = e.target;
bgneal@312:
bgneal@312: if (e.nodeName === 'IMG' && ed.dom.hasClass(e, cls))
bgneal@312: ed.selection.select(e);
bgneal@312: });
bgneal@312:
bgneal@312: ed.onNodeChange.add(function(ed, cm, n) {
bgneal@312: cm.setActive('pagebreak', n.nodeName === 'IMG' && ed.dom.hasClass(n, cls));
bgneal@312: });
bgneal@312:
bgneal@312: ed.onBeforeSetContent.add(function(ed, o) {
bgneal@312: o.content = o.content.replace(pbRE, pb);
bgneal@312: });
bgneal@312:
bgneal@312: ed.onPostProcess.add(function(ed, o) {
bgneal@312: if (o.get)
bgneal@312: o.content = o.content.replace(/]+>/g, function(im) {
bgneal@312: if (im.indexOf('class="mcePageBreak') !== -1)
bgneal@312: im = sep;
bgneal@312:
bgneal@312: return im;
bgneal@312: });
bgneal@312: });
bgneal@312: },
bgneal@312:
bgneal@312: getInfo : function() {
bgneal@312: return {
bgneal@312: longname : 'PageBreak',
bgneal@312: author : 'Moxiecode Systems AB',
bgneal@312: authorurl : 'http://tinymce.moxiecode.com',
bgneal@312: infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/pagebreak',
bgneal@312: version : tinymce.majorVersion + "." + tinymce.minorVersion
bgneal@312: };
bgneal@312: }
bgneal@312: });
bgneal@312:
bgneal@312: // Register plugin
bgneal@312: tinymce.PluginManager.add('pagebreak', tinymce.plugins.PageBreakPlugin);
bgneal@312: })();