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

PHP Demo Application - Source Code

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



/*
Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
/**
 * @file DOM iterator, which iterates over list items, lines and paragraphs.
 */
CKEDITOR.plugins.add'domiterator' );
(function()
{
	    /**
	     * @name CKEDITOR.dom.iterator
	     */
	    function iteratorrange )
	    {
		        if ( arguments.length )
		            return;
		        this.range range;
		        this.forceBrBreak false;
		        // Whether include <br>s into the enlarged range.(#3730).
		        this.enlargeBr true;
		        this.enforceRealBlocks false;
		        this.|| ( this.{} );
		    }
	    var beginWhitespaceRegex = /^[\r\n\]+$/,
	        isBookmark CKEDITOR.dom.walker.bookmark();
	    iterator.prototype = {
		        getNextParagraph : function( blockTag )
		        {
			            // The block element to be returned.
			            var block;
			            // The range object used to identify the paragraph contents.
			            var range;
			            // Indicats that the current element in the loop is the last one.
			            var isLast;
			            // Indicate at least one of the range boundaries is inside a preformat block.
			            var touchPre;
			            // Instructs to cleanup remaining BRs.
			            var removePreviousBrremoveLastBr;
			            // This is the first iteration. Let's initialize it.
			            if ( !this._.lastNode )
			            {
				                range this.range.clone();
				                // Shrink the range to exclude harmful "noises" (#4087, #4450, #5435).
				                range.shrinkCKEDITOR.NODE_ELEMENTtrue );
				                touchPre range.endContainer.hasAscendant'pre'true )
				                    || range.startContainer.hasAscendant'pre'true );
				                range.enlargethis.forceBrBreak && !touchPre || !this.enlargeBr ?
				                               CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS CKEDITOR.ENLARGE_BLOCK_CONTENTS );
				                var walker = new CKEDITOR.dom.walkerrange ),
				                    ignoreBookmarkTextEvaluator CKEDITOR.dom.walker.bookmarktruetrue );
				                // Avoid anchor inside bookmark inner text.
				                walker.evaluator ignoreBookmarkTextEvaluator;
				                this._.nextNode walker.next();
				                // TODO: It's better to have walker.reset() used here.
				                walker = new CKEDITOR.dom.walkerrange );
				                walker.evaluator ignoreBookmarkTextEvaluator;
				                var lastNode walker.previous();
				                this._.lastNode lastNode.getNextSourceNodetrue );
				                // We may have an empty text node at the end of block due to [3770].
				                // If that node is the lastNode, it would cause our logic to leak to the
				                // next block.(#3887)
				                if ( this._.lastNode &&
				                        this._.lastNode.type == CKEDITOR.NODE_TEXT &&
				                        !CKEDITOR.tools.trimthis._.lastNode.getText( ) ) &&
				                        this._.lastNode.getParent().isBlockBoundary() )
				                {
					                    var testRange = new CKEDITOR.dom.rangerange.document );
					                    testRange.moveToPositionthis._.lastNodeCKEDITOR.POSITION_AFTER_END );
					                    if ( testRange.checkEndOfBlock() )
					                    {
						                        var path = new CKEDITOR.dom.elementPathtestRange.endContainer );
						                        var lastBlock path.block || path.blockLimit;
						                        this._.lastNode lastBlock.getNextSourceNodetrue );
						                    }
					                }
				                // Probably the document end is reached, we need a marker node.
				                if ( !this._.lastNode )
				                {
					                    this._.lastNode this._.docEndMarker range.document.createText'' );
					                    this._.lastNode.insertAfterlastNode );
					                }
				                // Let's reuse this variable.
				                range null;
				            }
			            var currentNode this._.nextNode;
			            lastNode this._.lastNode;
			            this._.nextNode null;
			            while ( currentNode )
			            {
				                // closeRange indicates that a paragraph boundary has been found,
				                // so the range can be closed.
				                var closeRange false,
				                        parentPre currentNode.hasAscendant'pre' );
				                // includeNode indicates that the current node is good to be part
				                // of the range. By default, any non-element node is ok for it.
				                var includeNode = ( currentNode.type != CKEDITOR.NODE_ELEMENT ),
				                    continueFromSibling false;
				                // If it is an element node, let's check if it can be part of the
				                // range.
				                if ( !includeNode )
				                {
					                    var nodeName currentNode.getName();
					                    if ( currentNode.isBlockBoundarythis.forceBrBreak &&
					                            !parentPre && { br 1
						} ) )
					                    {
						                        // <br> boundaries must be part of the range. It will
						                        // happen only if ForceBrBreak.
						                        if ( nodeName == 'br' )
						                            includeNode true;
						                        else if ( !range && !currentNode.getChildCount() && nodeName != 'hr' )
						                        {
							                            // If we have found an empty block, and haven't started
							                            // the range yet, it means we must return this block.
							                            block currentNode;
							                            isLast currentNode.equalslastNode );
							                            break;
							                        }
						                        // The range must finish right before the boundary,
						                        // including possibly skipped empty spaces. (#1603)
						                        if ( range )
						                        {
							                            range.setEndAtcurrentNodeCKEDITOR.POSITION_BEFORE_START );
							                            // The found boundary must be set as the next one at this
							                            // point. (#1717)
							                            if ( nodeName != 'br' )
							                                this._.nextNode currentNode;
							                        }
						                        closeRange true;
						                    }
					                    else
					                    {
						                        // If we have child nodes, let's check them.
						                        if ( currentNode.getFirst() )
						                        {
							                            // If we don't have a range yet, let's start it.
							                            if ( !range )
							                            {
								                                range = new CKEDITOR.dom.rangethis.range.document );
								                                range.setStartAtcurrentNodeCKEDITOR.POSITION_BEFORE_START );
								                            }
							                            currentNode currentNode.getFirst();
							                            continue;
							                        }
						                        includeNode true;
						                    }
					                }
				                else if ( currentNode.type == CKEDITOR.NODE_TEXT )
				                {
					                    // Ignore normal whitespaces (i.e. not including &nbsp;
					 or
					                    // other unicode whitespaces) before/after a block node.
					                    if ( beginWhitespaceRegex.testcurrentNode.getText() ) )
					                        includeNode false;
					                }
				                // The current node is good to be part of the range and we are
				                // starting a new range, initialize it first.
				                if ( includeNode && !range )
				                {
					                    range = new CKEDITOR.dom.rangethis.range.document );
					                    range.setStartAtcurrentNodeCKEDITOR.POSITION_BEFORE_START );
					                }
				                // The last node has been found.
				                isLast = ( ( !closeRange || includeNode ) && currentNode.equalslastNode ) );
				                // If we are in an element boundary, let's check if it is time
				                // to close the range, otherwise we include the parent within it.
				                if ( range && !closeRange )
				                {
					                    while ( !currentNode.getNext() && !isLast )
					                    {
						                        var parentNode currentNode.getParent();
						                        if ( parentNode.isBlockBoundarythis.forceBrBreak
						                                && !parentPre && { br 1
							} ) )
						                        {
							                            closeRange true;
							                            isLast isLast || ( parentNode.equalslastNode) );
							                            break;
							                        }
						                        currentNode parentNode;
						                        includeNode true;
						                        isLast = ( currentNode.equalslastNode ) );
						                        continueFromSibling true;
						                    }
					                }
				                // Now finally include the node.
				                if ( includeNode )
				                    range.setEndAtcurrentNodeCKEDITOR.POSITION_AFTER_END );
				                currentNode currentNode.getNextSourceNodecontinueFromSiblingnulllastNode );
				                isLast = !currentNode;
				                // We have found a block boundary. Let's close the range and move out of the
				                // loop.
				                if ( isLast || ( closeRange && range ) )
				                        break;
				            }
			            // Now, based on the processed range, look for (or create) the block to be returned.
			            if ( !block )
			            {
				                // If no range has been found, this is the end.
				                if ( !range )
				                {
					                    this._.docEndMarker && this._.docEndMarker.remove();
					                    this._.nextNode null;
					                    return null;
					                }
				                var startPath = new CKEDITOR.dom.elementPathrange.startContainer );
				                var startBlockLimit startPath.blockLimit,
				                    checkLimits = { div 1th 1td 1
					};
				                block startPath.block;
				                if ( !block
				                        && !this.enforceRealBlocks
				                        && checkLimitsstartBlockLimit.getName() ]
				                        && range.checkStartOfBlock()
				                        && range.checkEndOfBlock() )
				                    block startBlockLimit;
				                else if ( !block || ( this.enforceRealBlocks && block.getName() == 'li' ) )
				                {
					                    // Create the fixed block.
					                    block this.range.document.createElementblockTag || 'p' );
					                    // Move the contents of the temporary range to the fixed block.
					                    range.extractContents().appendToblock );
					                    block.trim();
					                    // Insert the fixed block into the DOM.
					                    range.insertNodeblock );
					                    removePreviousBr removeLastBr true;
					                }
				                else if ( block.getName() != 'li' )
				                {
					                    // If the range doesn't includes the entire contents of the
					                    // block, we must split it, isolating the range in a dedicated
					                    // block.
					                    if ( !range.checkStartOfBlock() || !range.checkEndOfBlock() )
					                    {
						                        // The resulting block will be a clone of the current one.
						                        block block.clone( false );
						                        // Extract the range contents, moving it to the new block.
						                        range.extractContents().appendToblock );
						                        block.trim();
						                        // Split the block. At this point, the range will be in the
						                        // right position for our intents.
						                        var splitInfo range.splitBlock();
						                        removePreviousBr = !splitInfo.wasStartOfBlock;
						                        removeLastBr = !splitInfo.wasEndOfBlock;
						                        // Insert the new block into the DOM.
						                        range.insertNodeblock );
						                    }
					                }
				                else if ( !isLast )
				                {
					                    // LIs are returned as is, with all their children (due to the
					                    // nested lists). But, the next node is the node right after
					                    // the current range, which could be an <li> child (nested
					                    // lists) or the next sibling <li>.
					                    this._.nextNode = ( block.equalslastNode ) ? null :
					                        range.getBoundaryNodes().endNode.getNextSourceNodetruenulllastNode ) );
					                }
				            }
			            if ( removePreviousBr )
			            {
				                var previousSibling block.getPrevious();
				                if ( previousSibling && previousSibling.type == CKEDITOR.NODE_ELEMENT )
				                {
					                    if ( previousSibling.getName() == 'br' )
					                        previousSibling.remove();
					                    else if ( previousSibling.getLast() && previousSibling.getLast().$.nodeName.toLowerCase() == 'br' )
					                        previousSibling.getLast().remove();
					                }
				            }
			            if ( removeLastBr )
			            {
				                // Ignore bookmark nodes.(#3783)
				                var bookmarkGuard CKEDITOR.dom.walker.bookmarkfalsetrue );
				                var lastChild block.getLast();
				                if ( lastChild && lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.getName() == 'br' )
				                {
					                    // Take care not to remove the block expanding <br> in non-IE browsers.
					                    if ( CKEDITOR.env.ie
					                         || lastChild.getPreviousbookmarkGuard )
					                         || lastChild.getNextbookmarkGuard ) )
					                        lastChild.remove();
					                }
				            }
			            // Get a reference for the next element. This is important because the
			            // above block can be removed or changed, so we can rely on it for the
			            // next interation.
			            if ( !this._.nextNode )
			            {
				                this._.nextNode = ( isLast || block.equalslastNode ) ) ? null :
				                    block.getNextSourceNodetruenulllastNode );
				            }
			            return block;
			        }
		    };
	    CKEDITOR.dom.range.prototype.createIterator = function()
	    {
		        return new iteratorthis );
		    };
	})();





PHP Demo Source Code Index