Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (2.3 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
        var Event = tinymce.dom.Event;
13

    
14
        tinymce.create('tinymce.plugins.NonEditablePlugin', {
15
                init : function(ed, url) {
16
                        var t = this, editClass, nonEditClass;
17

    
18
                        t.editor = ed;
19
                        editClass = ed.getParam("noneditable_editable_class", "mceEditable");
20
                        nonEditClass = ed.getParam("noneditable_noneditable_class", "mceNonEditable");
21

    
22
                        ed.onNodeChange.addToTop(function(ed, cm, n) {
23
                                var sc, ec;
24

    
25
                                // Block if start or end is inside a non editable element
26
                                sc = ed.dom.getParent(ed.selection.getStart(), function(n) {
27
                                        return ed.dom.hasClass(n, nonEditClass);
28
                                });
29

    
30
                                ec = ed.dom.getParent(ed.selection.getEnd(), function(n) {
31
                                        return ed.dom.hasClass(n, nonEditClass);
32
                                });
33

    
34
                                // Block or unblock
35
                                if (sc || ec) {
36
                                        t._setDisabled(1);
37
                                        return false;
38
                                } else
39
                                        t._setDisabled(0);
40
                        });
41
                },
42

    
43
                getInfo : function() {
44
                        return {
45
                                longname : 'Non editable elements',
46
                                author : 'Moxiecode Systems AB',
47
                                authorurl : 'http://tinymce.moxiecode.com',
48
                                infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/noneditable',
49
                                version : tinymce.majorVersion + "." + tinymce.minorVersion
50
                        };
51
                },
52

    
53
                _block : function(ed, e) {
54
                        var k = e.keyCode;
55

    
56
                        // Don't block arrow keys, pg up/down, and F1-F12
57
                        if ((k > 32 && k < 41) || (k > 111 && k < 124))
58
                                return;
59

    
60
                        return Event.cancel(e);
61
                },
62

    
63
                _setDisabled : function(s) {
64
                        var t = this, ed = t.editor;
65

    
66
                        tinymce.each(ed.controlManager.controls, function(c) {
67
                                c.setDisabled(s);
68
                        });
69

    
70
                        if (s !== t.disabled) {
71
                                if (s) {
72
                                        ed.onKeyDown.addToTop(t._block);
73
                                        ed.onKeyPress.addToTop(t._block);
74
                                        ed.onKeyUp.addToTop(t._block);
75
                                        ed.onPaste.addToTop(t._block);
76
                                } else {
77
                                        ed.onKeyDown.remove(t._block);
78
                                        ed.onKeyPress.remove(t._block);
79
                                        ed.onKeyUp.remove(t._block);
80
                                        ed.onPaste.remove(t._block);
81
                                }
82

    
83
                                t.disabled = s;
84
                        }
85
                }
86
        });
87

    
88
        // Register plugin
89
        tinymce.PluginManager.add('noneditable', tinymce.plugins.NonEditablePlugin);
90
})();