Statistics
| Branch: | Tag: | Revision:

root / static / js / tinymce / plugins / pagebreak / editor_plugin_src.js @ 6ecbf4ec

History | View | Annotate | Download (2.2 kB)

1
/**
2
 * editor_plugin_src.js
3
 *
4
 * Copyright 2009, Moxiecode Systems AB
5
 * Released under LGPL License.
6
 *
7
 * License: http://tinymce.moxiecode.com/license
8
 * Contributing: http://tinymce.moxiecode.com/contributing
9
 */
10

    
11
(function() {
12
        tinymce.create('tinymce.plugins.PageBreakPlugin', {
13
                init : function(ed, url) {
14
                        var pb = '<img src="' + url + '/img/trans.gif" class="mcePageBreak mceItemNoResize" />', cls = 'mcePageBreak', sep = ed.getParam('pagebreak_separator', '<!-- pagebreak -->'), pbRE;
15

    
16
                        pbRE = new RegExp(sep.replace(/[\?\.\*\[\]\(\)\{\}\+\^\$\:]/g, function(a) {return '\\' + a;}), 'g');
17

    
18
                        // Register commands
19
                        ed.addCommand('mcePageBreak', function() {
20
                                ed.execCommand('mceInsertContent', 0, pb);
21
                        });
22

    
23
                        // Register buttons
24
                        ed.addButton('pagebreak', {title : 'pagebreak.desc', cmd : cls});
25

    
26
                        ed.onInit.add(function() {
27
                                if (ed.settings.content_css !== false)
28
                                        ed.dom.loadCSS(url + "/css/content.css");
29

    
30
                                if (ed.theme.onResolveName) {
31
                                        ed.theme.onResolveName.add(function(th, o) {
32
                                                if (o.node.nodeName == 'IMG' && ed.dom.hasClass(o.node, cls))
33
                                                        o.name = 'pagebreak';
34
                                        });
35
                                }
36
                        });
37

    
38
                        ed.onClick.add(function(ed, e) {
39
                                e = e.target;
40

    
41
                                if (e.nodeName === 'IMG' && ed.dom.hasClass(e, cls))
42
                                        ed.selection.select(e);
43
                        });
44

    
45
                        ed.onNodeChange.add(function(ed, cm, n) {
46
                                cm.setActive('pagebreak', n.nodeName === 'IMG' && ed.dom.hasClass(n, cls));
47
                        });
48

    
49
                        ed.onBeforeSetContent.add(function(ed, o) {
50
                                o.content = o.content.replace(pbRE, pb);
51
                        });
52

    
53
                        ed.onPostProcess.add(function(ed, o) {
54
                                if (o.get)
55
                                        o.content = o.content.replace(/<img[^>]+>/g, function(im) {
56
                                                if (im.indexOf('class="mcePageBreak') !== -1)
57
                                                        im = sep;
58

    
59
                                                return im;
60
                                        });
61
                        });
62
                },
63

    
64
                getInfo : function() {
65
                        return {
66
                                longname : 'PageBreak',
67
                                author : 'Moxiecode Systems AB',
68
                                authorurl : 'http://tinymce.moxiecode.com',
69
                                infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/pagebreak',
70
                                version : tinymce.majorVersion + "." + tinymce.minorVersion
71
                        };
72
                }
73
        });
74

    
75
        // Register plugin
76
        tinymce.PluginManager.add('pagebreak', tinymce.plugins.PageBreakPlugin);
77
})();