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