annotate WebContent/jscripts/tiny_mce/plugins/pagebreak/editor_plugin_src.js @ 8:11baadcdd2c8

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