editor-bidi-debug.js revision 27a34eacb64bad3093c357e104c7bee249343ec1
/**
* Plugin for Editor to support BiDirectional (bidi) text operations.
* @module editor
* @submodule editor-bidi
*/
/**
* Plugin for Editor to support BiDirectional (bidi) text operations.
* @class Plugin.EditorBidi
* @extends Base
* @constructor
*/
var EditorBidi = function() {
/**
* Place holder for the last direction when checking for a switch
* @private
* @property lastDirection
*/
lastDirection: null,
/**
* Tells us that an initial bidi check has already been performed
* @private
* @property firstEvent
*/
firstEvent: null,
/**
* Method checks to see if the direction of the text has changed based on a nodeChange event.
* @private
* @method _checkForChange
*/
_checkForChange: function() {
if (sel.isCollapsed) {
if (direction !== this.lastDirection) {
this.lastDirection = direction;
}
} else {
this.lastDirection = null;
}
},
/**
* Checked for a change after a specific nodeChange event has been fired.
* @private
* @method _afterNodeChange
*/
_afterNodeChange: function(e) {
// If this is the first event ever, or an event that can result in a context change
this._checkForChange();
this.firstEvent = false;
}
},
/**
* Checks for a direction change after a mouseup occurs.
* @private
* @method _afterMouseUp
*/
_afterMouseUp: function(e) {
this._checkForChange();
this.firstEvent = false;
},
initializer: function() {
this.firstEvent = true;
}
}, {
/**
* The events to check for a direction change on
* @property EVENTS
* @static
*/
EVENTS: {
'backspace-up': true,
'pageup-up': true,
'pagedown-down': true,
'end-up': true,
'home-up': true,
'left-up': true,
'up-up': true,
'right-up': true,
'down-up': true,
'delete-up': true
},
/**
* More elements may be needed. BODY *must* be in the list to take care of the special case.
*
* blockParent could be changed to use inst.Selection.BLOCKS
* instead, but that would make Y.Plugin.EditorBidi.blockParent
* unusable in non-RTE contexts (it being usable is a nice
* side-effect).
* @property BLOCKS
* @static
*/
/**
* Template for creating a block element
* @static
* @property DIV_WRAPPER
*/
DIV_WRAPPER: '<DIV></DIV>',
/**
* Returns a block parent for a given element
* @static
* @method blockParent
*/
if (!parent) {
}
}
// This shouldn't happen if the RTE handles everything
// according to spec: we should get to a P before BODY. But
// we don't want to set the direction of BODY even if that
// happens, so we wrap everything in a DIV.
// The code is based on YUI3's Y.Selection._wrapBlock function.
if (index === 0) {
firstChild = node;
} else {
}
});
}
return parent;
},
/**
* The data key to store on the node.
* @static
* @property _NODE_SELECTED
*/
_NODE_SELECTED: 'bidiSelected',
/**
* Generates a list of all the block parents of the current NodeList
* @static
* @method addParents
*/
addParents: function(nodeArray) {
}
// This works automagically, since new parents added get processed
// later themselves. So if there's a node early in the process that
// we haven't discovered some of its siblings yet, thus resulting in
// its parent not added, the parent will be added later, since those
// siblings will be added to the array and then get processed.
// Don't add the parent if the parent is the BODY element.
// We don't want to change the direction of BODY. Also don't
// do it if the parent is already in the list.
addParent = true;
addParent = false;
return true; // stop more processing
}
});
if (addParent) {
}
}
}
}
return nodeArray;
},
/**
* editorBidi
* @static
* @property NAME
*/
NAME: 'editorBidi',
/**
* editorBidi
* @static
* @property NS
*/
NS: 'editorBidi',
ATTRS: {
host: {
value: false
}
}
});
Y.namespace('Plugin');
/**
* bidi execCommand override for setting the text direction of a node.
* @for Plugin.ExecCommand
* @property COMMANDS.bidi
*/
//TODO -- This should not add this command unless the plugin is added to the instance..
var inst = this.getInstance(),
if (!ns) {
Y.error('bidi execCommand is not available without the EditorBiDi plugin.');
return;
}
if (!direction) {
//If no direction is set, auto-detect the proper setting to make it "toggle"
direction = 'rtl';
} else {
direction = 'ltr';
}
}
b.remove();
}
}
returnValue = block;
} else { // some text is selected
selectedBlocks = [];
});
selectedBlocks.each(function(n) {
var d = direction;
if (!d) {
d = 'rtl';
} else {
d = 'ltr';
}
}
n.setAttribute(DIR, d);
});
}
return returnValue;
};