2009-11-21 03:26:09 +01:00
|
|
|
/**
|
2011-04-05 01:42:57 +02:00
|
|
|
* editor_plugin_src.js
|
2009-11-21 03:26:09 +01:00
|
|
|
*
|
2011-04-05 01:42:57 +02:00
|
|
|
* Copyright 2009, Moxiecode Systems AB
|
|
|
|
* Released under LGPL License.
|
|
|
|
*
|
|
|
|
* License: http://tinymce.moxiecode.com/license
|
|
|
|
* Contributing: http://tinymce.moxiecode.com/contributing
|
2009-11-21 03:26:09 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
var Event = tinymce.dom.Event;
|
|
|
|
|
|
|
|
tinymce.create('tinymce.plugins.NonEditablePlugin', {
|
|
|
|
init : function(ed, url) {
|
2011-10-29 11:43:39 +02:00
|
|
|
var t = this, editClass, nonEditClass, state;
|
2009-11-21 03:26:09 +01:00
|
|
|
|
|
|
|
t.editor = ed;
|
|
|
|
editClass = ed.getParam("noneditable_editable_class", "mceEditable");
|
|
|
|
nonEditClass = ed.getParam("noneditable_noneditable_class", "mceNonEditable");
|
|
|
|
|
|
|
|
ed.onNodeChange.addToTop(function(ed, cm, n) {
|
|
|
|
var sc, ec;
|
|
|
|
|
|
|
|
// Block if start or end is inside a non editable element
|
|
|
|
sc = ed.dom.getParent(ed.selection.getStart(), function(n) {
|
|
|
|
return ed.dom.hasClass(n, nonEditClass);
|
|
|
|
});
|
|
|
|
|
|
|
|
ec = ed.dom.getParent(ed.selection.getEnd(), function(n) {
|
|
|
|
return ed.dom.hasClass(n, nonEditClass);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Block or unblock
|
|
|
|
if (sc || ec) {
|
2011-10-29 11:43:39 +02:00
|
|
|
state = 1;
|
2009-11-21 03:26:09 +01:00
|
|
|
t._setDisabled(1);
|
|
|
|
return false;
|
2011-10-29 11:43:39 +02:00
|
|
|
} else if (state == 1) {
|
2009-11-21 03:26:09 +01:00
|
|
|
t._setDisabled(0);
|
2011-10-29 11:43:39 +02:00
|
|
|
state = 0;
|
|
|
|
}
|
2009-11-21 03:26:09 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
getInfo : function() {
|
|
|
|
return {
|
|
|
|
longname : 'Non editable elements',
|
|
|
|
author : 'Moxiecode Systems AB',
|
|
|
|
authorurl : 'http://tinymce.moxiecode.com',
|
|
|
|
infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/noneditable',
|
|
|
|
version : tinymce.majorVersion + "." + tinymce.minorVersion
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
_block : function(ed, e) {
|
|
|
|
var k = e.keyCode;
|
|
|
|
|
|
|
|
// Don't block arrow keys, pg up/down, and F1-F12
|
|
|
|
if ((k > 32 && k < 41) || (k > 111 && k < 124))
|
|
|
|
return;
|
|
|
|
|
|
|
|
return Event.cancel(e);
|
|
|
|
},
|
|
|
|
|
|
|
|
_setDisabled : function(s) {
|
|
|
|
var t = this, ed = t.editor;
|
|
|
|
|
|
|
|
tinymce.each(ed.controlManager.controls, function(c) {
|
|
|
|
c.setDisabled(s);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (s !== t.disabled) {
|
|
|
|
if (s) {
|
|
|
|
ed.onKeyDown.addToTop(t._block);
|
|
|
|
ed.onKeyPress.addToTop(t._block);
|
|
|
|
ed.onKeyUp.addToTop(t._block);
|
|
|
|
ed.onPaste.addToTop(t._block);
|
2011-10-29 11:43:39 +02:00
|
|
|
ed.onContextMenu.addToTop(t._block);
|
2009-11-21 03:26:09 +01:00
|
|
|
} else {
|
|
|
|
ed.onKeyDown.remove(t._block);
|
|
|
|
ed.onKeyPress.remove(t._block);
|
|
|
|
ed.onKeyUp.remove(t._block);
|
|
|
|
ed.onPaste.remove(t._block);
|
2011-10-29 11:43:39 +02:00
|
|
|
ed.onContextMenu.remove(t._block);
|
2009-11-21 03:26:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
t.disabled = s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Register plugin
|
|
|
|
tinymce.PluginManager.add('noneditable', tinymce.plugins.NonEditablePlugin);
|
|
|
|
})();
|