editor-br-debug.js revision 99c4d05a4bdb506516f0dca00fc8bf4b86c93bd1
83N/AYUI.add('editor-br', function(Y) {
83N/A
83N/A
83N/A
83N/A /**
83N/A * Plugin for Editor to normalize BR's.
83N/A * @class Plugin.EditorBR
83N/A * @extends Base
83N/A * @constructor
83N/A * @module editor
83N/A * @submodule editor-br
83N/A */
83N/A
83N/A
83N/A var EditorBR = function() {
83N/A EditorBR.superclass.constructor.apply(this, arguments);
83N/A }, HOST = 'host', LI = 'li';
83N/A
83N/A
83N/A Y.extend(EditorBR, Y.Base, {
3817N/A /**
83N/A * Frame keyDown handler that normalizes BR's when pressing ENTER.
83N/A * @private
83N/A * @method _onKeyDown
83N/A */
83N/A _onKeyDown: function(e) {
4610N/A if (e.stopped) {
618N/A e.halt();
83N/A return;
83N/A }
844N/A if (e.keyCode == 13) {
4610N/A var host = this.get(HOST), inst = host.getInstance(),
83N/A sel = new inst.EditorSelection(),
1258N/A last = '';
83N/A
4610N/A if (sel) {
2899N/A if (Y.UA.ie) {
3817N/A if (!sel.anchorNode || (!sel.anchorNode.test(LI) && !sel.anchorNode.ancestor(LI))) {
3817N/A var host = this.get(HOST);
3817N/A host.execCommand('inserthtml', inst.EditorSelection.CURSOR);
83N/A e.halt();
83N/A }
83N/A }
4610N/A if (Y.UA.webkit) {
4610N/A if (!sel.anchorNode.test(LI) && !sel.anchorNode.ancestor(LI)) {
4610N/A host.frame._execCommand('insertlinebreak', null);
4610N/A e.halt();
4610N/A }
4610N/A }
4610N/A }
3291N/A }
3291N/A },
1591N/A /**
1591N/A * Adds listeners for keydown in IE and Webkit. Also fires insertbeonreturn for supporting browsers.
83N/A * @private
3477N/A * @method _afterEditorReady
3477N/A */
1591N/A _afterEditorReady: function() {
83N/A var inst = this.get(HOST).getInstance();
1591N/A try {
83N/A inst.config.doc.execCommand('insertbronreturn', null, true);
3291N/A } catch (bre) {}
83N/A
4337N/A if (Y.UA.ie || Y.UA.webkit) {
4337N/A inst.on('keydown', Y.bind(this._onKeyDown, this), inst.config.doc);
83N/A }
3817N/A },
/**
* Adds a nodeChange listener only for FF, in the event of a backspace or delete, it creates an empy textNode
* inserts it into the DOM after the e.changedNode, then removes it. Causing FF to redraw the content.
* @private
* @method _onNodeChange
* @param {Event} e The nodeChange event.
*/
_onNodeChange: function(e) {
switch (e.changedType) {
case 'backspace-up':
case 'backspace-down':
case 'delete-up':
/*
* This forced FF to redraw the content on backspace.
* On some occasions FF will leave a cursor residue after content has been deleted.
* Dropping in the empty textnode and then removing it causes FF to redraw and
* remove the "ghost cursors"
*/
var inst = this.get(HOST).getInstance();
var d = e.changedNode;
var t = inst.config.doc.createTextNode(' ');
d.appendChild(t);
d.removeChild(t);
break;
}
},
initializer: function() {
var host = this.get(HOST);
if (host.editorPara) {
Y.error('Can not plug EditorBR and EditorPara at the same time.');
return;
}
host.after('ready', Y.bind(this._afterEditorReady, this));
if (Y.UA.gecko) {
host.on('nodeChange', Y.bind(this._onNodeChange, this));
}
}
}, {
/**
* editorBR
* @static
* @property NAME
*/
NAME: 'editorBR',
/**
* editorBR
* @static
* @property NS
*/
NS: 'editorBR',
ATTRS: {
host: {
value: false
}
}
});
Y.namespace('Plugin');
Y.Plugin.EditorBR = EditorBR;
}, '@VERSION@' ,{skinnable:false, requires:['editor-base']});