editor-bidi.js revision 9d0be4bedcaad945c505994577198223ffc4ed9e
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * Plugin for Editor to support BiDirectional (bidi) text operations.
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * @module editor
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * @submodule editor-bidi
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * Plugin for Editor to support BiDirectional (bidi) text operations.
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * @class Plugin.EditorBidi
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * @extends Base
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * @constructor
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith var EditorBidi = function() {
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith EditorBidi.superclass.constructor.apply(this, arguments);
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith }, HOST = 'host', DIR = 'dir', BODY = 'BODY', NODE_CHANGE = 'nodeChange',
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith B_C_CHANGE = 'bidiContextChange', FIRST_P = BODY + ' > p';
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * Place holder for the last direction when checking for a switch
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith * @property lastDirection
48acd4bcfce0111241afe00bec21c8d8b318f4c5Todd Kloots * Tells us that an initial bidi check has already been performed
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith * @property firstEvent
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith * Method checks to see if the direction of the text has changed based on a nodeChange event.
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith * @method _checkForChange
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith * Checked for a change after a specific nodeChange event has been fired.
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith * @method _afterNodeChange
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith // If this is the first event ever, or an event that can result in a context change
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith if (this.firstEvent || EditorBidi.EVENTS[e.changedType]) {
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith this.firstEvent = false;
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith * Checks for a direction change after a mouseup occurs.
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith * @method _afterMouseUp
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith _afterMouseUp: function(e) {
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith this.firstEvent = false;
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith * Utility method to create an empty paragraph when the document is empty.
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith * @method _fixFirstPara
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith var host = this.get(HOST), inst = host.getInstance(), sel;
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith inst.one('body').setContent('<p>' + inst.Selection.CURSOR + '</p>');
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith * nodeChange handler to handle fixing an empty document.
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith * @method _onNodeChange
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith _onNodeChange: function(e) {
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith var host = this.get(HOST), inst = host.getInstance();
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith case 'keydown':
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith case 'backspace-up':
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith case 'delete-up':
b402e20da315b3e86bd6e770942e07d182bcba1dLuke Smith if (inst.Selection.getText(item) === '' && !item.test('p')) {
48acd4bcfce0111241afe00bec21c8d8b318f4c5Todd Kloots } else if (item.test('p') && item.get('innerHTML').length === 0) {
_afterEditorReady: function() {
if (inst) {
_afterContentChange: function() {
_afterPaste: function() {
initializer: function() {
this.firstEvent = true;
EVENTS: {
if (!parent) {
return parent;
addParent = true;
addParent = false;
if (addParent) {
return nodeArray;
ATTRS: {
host: {
value: false
selectedBlocks = [];
return returnValue;