/* Copyright (c) 2010, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.com/yui/license.html version: 3.3.0 build: 3167 */ YUI.add('editor-bidi',function(Y){var EditorBidi=function(){EditorBidi.superclass.constructor.apply(this,arguments);},HOST='host',DIR='dir',BODY='BODY',NODE_CHANGE='nodeChange',B_C_CHANGE='bidiContextChange',FIRST_P=BODY+' > p';Y.extend(EditorBidi,Y.Base,{lastDirection:null,firstEvent:null,_checkForChange:function(){var host=this.get(HOST),inst=host.getInstance(),sel=new inst.Selection(),node,direction;if(sel.isCollapsed){node=EditorBidi.blockParent(sel.focusNode);direction=node.getStyle('direction');if(direction!==this.lastDirection){host.fire(B_C_CHANGE,{changedTo:direction});this.lastDirection=direction;}}else{host.fire(B_C_CHANGE,{changedTo:'select'});this.lastDirection=null;}},_afterNodeChange:function(e){if(this.firstEvent||EditorBidi.EVENTS[e.changedType]){this._checkForChange();this.firstEvent=false;}},_afterMouseUp:function(e){this._checkForChange();this.firstEvent=false;},initializer:function(){var host=this.get(HOST);this.firstEvent=true;host.after(NODE_CHANGE,Y.bind(this._afterNodeChange,this));host.after('dom:mouseup',Y.bind(this._afterMouseUp,this));}},{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},BLOCKS:Y.Selection.BLOCKS+',LI,HR,'+BODY,DIV_WRAPPER:'
',blockParent:function(node,wrap){var parent=node,divNode,firstChild;if(!parent){parent=Y.one(BODY);} if(!parent.test(EditorBidi.BLOCKS)){parent=parent.ancestor(EditorBidi.BLOCKS);} if(wrap&&parent.test(BODY)){divNode=Y.Node.create(EditorBidi.DIV_WRAPPER);parent.get('children').each(function(node,index){if(index===0){firstChild=node;}else{divNode.append(node);}});firstChild.replace(divNode);divNode.prepend(firstChild);parent=divNode;} return parent;},_NODE_SELECTED:'bidiSelected',addParents:function(nodeArray){var i,parent,addParent;for(i=0;i