CLICK HERE TO BUY IT TODAY! OR GET IT FREE VIA TRIALPAY  

PHP Demo Application - Source Code

/Framework/Model/Vendor/CkEditor/_source/plugins/bidi/plugin.js



/*
Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
(function()
{
	    var guardElements = { table:1ul:1ol:1blockquote:1div:1
		};
	    var directSelectionGuardElements {};
	    CKEDITOR.tools.extenddirectSelectionGuardElementsguardElements, { tr:1p:1div:1li:1
		} );
	    function onSelectionChangeevt )
	    {
		        var editor evt.editor,
		            path evt.data.path;
		        var useComputedState editor.config.useComputedState,
		            selectedElement;
		        useComputedState useComputedState === undefined || useComputedState;
		        if ( useComputedState )
		        {
			            var selection editor.getSelection(),
			                ranges selection.getRanges();
			            selectedElement ranges && ranges].getEnclosedNode();
			            // If this is not our element of interest, apply to fully selected elements from guardElements.
			            if ( !selectedElement || selectedElement
			                    && !( selectedElement.type == CKEDITOR.NODE_ELEMENT && selectedElement.getName() in directSelectionGuardElements )
			                )
			                selectedElement getFullySelectedselectionguardElements );
			        }
		        selectedElement selectedElement || path.block || path.blockLimit;
		        if ( !selectedElement || selectedElement.getName() == 'body' )
		            return;
		        var selectionDir useComputedState ?
		            selectedElement.getComputedStyle'direction' ) :
		            selectedElement.getStyle'direction' ) || selectedElement.getAttribute'dir' );
		        editor.getCommand'bidirtl' ).setStateselectionDir == 'rtl' CKEDITOR.TRISTATE_ON CKEDITOR.TRISTATE_OFF );
		        editor.getCommand'bidiltr' ).setStateselectionDir == 'ltr' CKEDITOR.TRISTATE_ON CKEDITOR.TRISTATE_OFF );
		        var chromeRoot editor.container.getChild);
		        if ( selectionDir != editor.lang.dir )
		            chromeRoot.addClass'cke_mixed_dir_content' );
		        else
		            chromeRoot.removeClass'cke_mixed_dir_content' );
		    }
	    function switchDirelementdireditor )
	    {
		        var dirBefore element.getComputedStyle'direction' ),
		            currentDir element.getStyle'direction' ) || element.getAttribute'dir' ) || '';
		        element.removeStyle'direction' );
		        if ( currentDir.toLowerCase() == dir )
		            element.removeAttribute'dir' );
		        else
		            element.setAttribute'dir'dir );
		        // If the element direction changed, we need to switch the margins of
		        // the element and all its children, so it will get really reflected
		        // like a mirror. (#5910)
		        var dirAfter element.getComputedStyle'direction' );
		        if ( dirAfter != dirBefore )
		        {
			            var range = new CKEDITOR.dom.rangeelement.getDocument() );
			            range.setStartBeforeelement );
			            range.setEndAfterelement );
			            var walker = new CKEDITOR.dom.walkerrange );
			            var node;
			            while ( ( node walker.next() ) )
			            {
				                if ( node.type == CKEDITOR.NODE_ELEMENT )
				                {
					                    // A child with dir defined is to be ignored.
					                    if ( !node.equalselement ) && node.hasAttribute'dir' ) )
					                    {
						                        range.setStartAfternode );
						                        walker = new CKEDITOR.dom.walkerrange );
						                        continue;
						                    }
					                    // Switch the margins.
					                    var marginLeft node.getStyle'margin-right' ),
					                        marginRight node.getStyle'margin-left' );
					                    marginLeft node.setStyle'margin-left'marginLeft ) : node.removeStyle'margin-left' );
					                    marginRight node.setStyle'margin-right'marginRight ) : node.removeStyle'margin-right' );
					                }
				            }
			        }
		        editor.forceNextSelectionCheck();
		    }
	    function getFullySelectedselectionelements )
	    {
		        var selectedElement selection.getCommonAncestor();
		        while( selectedElement.type == CKEDITOR.NODE_ELEMENT
		                && !( selectedElement.getName() in elements )
		                && selectedElement.getParent().getChildCount() == 1
		            )
		            selectedElement selectedElement.getParent();
		        return selectedElement.type == CKEDITOR.NODE_ELEMENT
		            && ( selectedElement.getName() in elements )
		            && selectedElement;
		    }
	    function bidiCommanddir )
	    {
		        return function( editor )
		        {
			            var selection editor.getSelection(),
			                enterMode editor.config.enterMode,
			                ranges selection.getRanges();
			            if ( ranges && ranges.length )
			            {
				                // Apply do directly selected elements from guardElements.
				                var selectedElement ranges].getEnclosedNode();
				                // If this is not our element of interest, apply to fully selected elements from guardElements.
				                if ( !selectedElement || selectedElement
				                        && !( selectedElement.type == CKEDITOR.NODE_ELEMENT && selectedElement.getName() in directSelectionGuardElements )
				                    )
				                    selectedElement getFullySelectedselectionguardElements );
				                if ( selectedElement )
				                {
					                    if ( !selectedElement.isReadOnly() )
					                        switchDirselectedElementdireditor );
					                }
				                else
				                {
					                    // Creates bookmarks for selection, as we may split some blocks.
					                    var bookmarks selection.createBookmarks();
					                    var iterator,
					                        block;
					                    for ( var ranges.length ;
					 >= ;
					 i-- )
					                    {
						                        // Array of elements processed as guardElements.
						                        var processedElements [];
						                        // Walker searching for guardElements.
						                        var walker = new CKEDITOR.dom.walkerranges] );
						                        walker.evaluator = function( node ){
							                            return node.type == CKEDITOR.NODE_ELEMENT
							                                && node.getName() in guardElements
							                                && !( node.getName() == ( enterMode == CKEDITOR.ENTER_P ) ? 'p' 'div'
							                                    && node.getParent().type == CKEDITOR.NODE_ELEMENT
							                                    && node.getParent().getName() == 'blockquote'
							                                );
							                        };
						                        while ( ( block walker.next() ) )
						                        {
							                            switchDirblockdireditor );
							                            processedElements.pushblock );
							                        }
						                        iterator ranges].createIterator();
						                        iterator.enlargeBr enterMode != CKEDITOR.ENTER_BR;
						                        while ( ( block iterator.getNextParagraphenterMode == CKEDITOR.ENTER_P 'p' 'div' ) ) )
						                        {
							                            if ( block.isReadOnly() )
							                                continue;
							                            var _break 0;
							                            // Check if block have been already processed by the walker above.
							                            for ( var ii 0;
							 ii processedElements.length;
							 ii++ )
							                            {
								                                var parent block.getParent();
								                                while( parent && parent.getName() != 'body' )
								                                {
									                                    if ( ( parent.$.isSameNode && parent.$.isSameNodeprocessedElementsii ].$ ) )
									                                            || parent.$ == processedElementsii ].$ )
									                                    {
										                                        _break 1;
										                                        break;
										                                    }
									                                    parent parent.getParent();
									                                }
								                                if ( _break )
								                                    break;
								                            }
							                            if ( !_break )
							                            {
								                                switchDirblockdireditor );
								                            }
							                        }
						                    }
					                    editor.forceNextSelectionCheck();
					                    // Restore selection position.
					                    selection.selectBookmarksbookmarks );
					                }
				                editor.focus();
				            }
			        };
		    }
	    CKEDITOR.plugins.add'bidi',
	    {
		        requires : [ 'styles''button' ],
		        init : function( editor )
		        {
			            // All buttons use the same code to register. So, to avoid
			            // duplications, let's use this tool function.
			            var addButtonCommand = function( buttonNamebuttonLabelcommandNamecommandExec )
			            {
				                editor.addCommandcommandName, new CKEDITOR.commandeditor, { exec commandExec
					}) );
				                editor.ui.addButtonbuttonName,
				                    {
					                        label buttonLabel,
					                        command commandName
					                    });
				            };
			            var lang editor.lang.bidi;
			            addButtonCommand'BidiLtr'lang.ltr'bidiltr'bidiCommand'ltr' ) );
			            addButtonCommand'BidiRtl'lang.rtl'bidirtl'bidiCommand'rtl' ) );
			            editor.on'selectionChange'onSelectionChange );
			        }
		    });
	})();





PHP Demo Source Code Index