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