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

PHP Demo Application - Source Code

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



/*
Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
/**
 * @file Blockquote.
 */
(function()
{
	    function getStateeditorpath )
	    {
		        var firstBlock path.block || path.blockLimit;
		        if ( !firstBlock || firstBlock.getName() == 'body' )
		            return CKEDITOR.TRISTATE_OFF;
		        // See if the first block has a blockquote parent.
		        if ( firstBlock.getAscendant'blockquote'true ) )
		            return CKEDITOR.TRISTATE_ON;
		        return CKEDITOR.TRISTATE_OFF;
		    }
	    function onSelectionChangeevt )
	    {
		        var editor evt.editor,
		            command editor.getCommand'blockquote' );
		        command.state getStateeditorevt.data.path );
		        command.fire'state' );
		    }
	    function noBlockLeftbqBlock )
	    {
		        for ( var 0length bqBlock.getChildCount(), child ;
		 length && ( child bqBlock.getChild) ) ;
		 i++ )
		        {
			            if ( child.type == CKEDITOR.NODE_ELEMENT && child.isBlockBoundary() )
			                return false;
			        }
		        return true;
		    }
	    var commandObject =
	    {
		        exec : function( editor )
		        {
			            var state editor.getCommand'blockquote' ).state,
			                selection editor.getSelection(),
			                range selection && selection.getRangestrue )[0];
			            if ( !range )
			                return;
			            var bookmarks selection.createBookmarks();
			            // Kludge for #1592: if the bookmark nodes are in the beginning of
			            // blockquote, then move them to the nearest block element in the
			            // blockquote.
			            if ( CKEDITOR.env.ie )
			            {
				                var bookmarkStart bookmarks[0].startNode,
				                    bookmarkEnd bookmarks[0].endNode,
				                    cursor;
				                if ( bookmarkStart && bookmarkStart.getParent().getName() == 'blockquote' )
				                {
					                    cursor bookmarkStart;
					                    while ( ( cursor cursor.getNext() ) )
					                    {
						                        if ( cursor.type == CKEDITOR.NODE_ELEMENT &&
						                                cursor.isBlockBoundary() )
						                        {
							                            bookmarkStart.movecursortrue );
							                            break;
							                        }
						                    }
					                }
				                if ( bookmarkEnd
				                        && bookmarkEnd.getParent().getName() == 'blockquote' )
				                {
					                    cursor bookmarkEnd;
					                    while ( ( cursor cursor.getPrevious() ) )
					                    {
						                        if ( cursor.type == CKEDITOR.NODE_ELEMENT &&
						                                cursor.isBlockBoundary() )
						                        {
							                            bookmarkEnd.movecursor );
							                            break;
							                        }
						                    }
					                }
				            }
			            var iterator range.createIterator(),
			                block;
			            if ( state == CKEDITOR.TRISTATE_OFF )
			            {
				                var paragraphs [];
				                while ( ( block iterator.getNextParagraph() ) )
				                    paragraphs.pushblock );
				                // If no paragraphs, create one from the current selection position.
				                if ( paragraphs.length )
				                {
					                    var para editor.document.createElementeditor.config.enterMode == CKEDITOR.ENTER_P 'p' 'div' ),
					                        firstBookmark bookmarks.shift();
					                    range.insertNodepara );
					                    para.append( new CKEDITOR.dom.text'\ufeff'editor.document ) );
					                    range.moveToBookmarkfirstBookmark );
					                    range.selectNodeContentspara );
					                    range.collapsetrue );
					                    firstBookmark range.createBookmark();
					                    paragraphs.pushpara );
					                    bookmarks.unshiftfirstBookmark );
					                }
				                // Make sure all paragraphs have the same parent.
				                var commonParent paragraphs[0].getParent(),
				                    tmp [];
				                for ( var ;
				 paragraphs.length ;
				 i++ )
				                {
					                    block paragraphs[i];
					                    commonParent commonParent.getCommonAncestorblock.getParent() );
					                }
				                // The common parent must not be the following tags: table, tbody, tr, ol, ul.
				                var denyTags = { table 1tbody 1tr 1ol 1ul 1
					};
				                while ( denyTagscommonParent.getName() ] )
				                    commonParent commonParent.getParent();
				                // Reconstruct the block list to be processed such that all resulting blocks
				                // satisfy parentNode.equals( commonParent ).
				                var lastBlock null;
				                while ( paragraphs.length )
				                {
					                    block paragraphs.shift();
					                    while ( !block.getParent().equalscommonParent ) )
					                        block block.getParent();
					                    if ( !block.equalslastBlock ) )
					                        tmp.pushblock );
					                    lastBlock block;
					                }
				                // If any of the selected blocks is a blockquote, remove it to prevent
				                // nested blockquotes.
				                while ( tmp.length )
				                {
					                    block tmp.shift();
					                    if ( block.getName() == 'blockquote' )
					                    {
						                        var docFrag = new CKEDITOR.dom.documentFragmenteditor.document );
						                        while ( block.getFirst() )
						                        {
							                            docFrag.appendblock.getFirst().remove() );
							                            paragraphs.pushdocFrag.getLast() );
							                        }
						                        docFrag.replaceblock );
						                    }
					                    else
					                        paragraphs.pushblock );
					                }
				                // Now we have all the blocks to be included in a new blockquote node.
				                var bqBlock editor.document.createElement'blockquote' );
				                bqBlock.insertBeforeparagraphs[0] );
				                while ( paragraphs.length )
				                {
					                    block paragraphs.shift();
					                    bqBlock.appendblock );
					                }
				            }
			            else if ( state == CKEDITOR.TRISTATE_ON )
			            {
				                var moveOutNodes [],
				                    database {};
				                while ( ( block iterator.getNextParagraph() ) )
				                {
					                    var bqParent null,
					                        bqChild null;
					                    while ( block.getParent() )
					                    {
						                        if ( block.getParent().getName() == 'blockquote' )
						                        {
							                            bqParent block.getParent();
							                            bqChild block;
							                            break;
							                        }
						                        block block.getParent();
						                    }
					                    // Remember the blocks that were recorded down in the moveOutNodes array
					                    // to prevent duplicates.
					                    if ( bqParent && bqChild && !bqChild.getCustomData'blockquote_moveout' ) )
					                    {
						                        moveOutNodes.pushbqChild );
						                        CKEDITOR.dom.element.setMarkerdatabasebqChild'blockquote_moveout'true );
						                    }
					                }
				                CKEDITOR.dom.element.clearAllMarkersdatabase );
				                var movedNodes [],
				                    processedBlockquoteBlocks [];
				                database {};
				                while ( moveOutNodes.length )
				                {
					                    var node moveOutNodes.shift();
					                    bqBlock node.getParent();
					                    // If the node is located at the beginning or the end, just take it out
					                    // without splitting. Otherwise, split the blockquote node and move the
					                    // paragraph in between the two blockquote nodes.
					                    if ( !node.getPrevious() )
					                        node.remove().insertBeforebqBlock );
					                    else if ( !node.getNext() )
					                        node.remove().insertAfterbqBlock );
					                    else
					                    {
						                        node.breakParentnode.getParent() );
						                        processedBlockquoteBlocks.pushnode.getNext() );
						                    }
					                    // Remember the blockquote node so we can clear it later (if it becomes empty).
					                    if ( !bqBlock.getCustomData'blockquote_processed' ) )
					                    {
						                        processedBlockquoteBlocks.pushbqBlock );
						                        CKEDITOR.dom.element.setMarkerdatabasebqBlock'blockquote_processed'true );
						                    }
					                    movedNodes.pushnode );
					                }
				                CKEDITOR.dom.element.clearAllMarkersdatabase );
				                // Clear blockquote nodes that have become empty.
				                for ( processedBlockquoteBlocks.length ;
				 >= ;
				 i-- )
				                {
					                    bqBlock processedBlockquoteBlocks[i];
					                    if ( noBlockLeftbqBlock ) )
					                        bqBlock.remove();
					                }
				                if ( editor.config.enterMode == CKEDITOR.ENTER_BR )
				                {
					                    var firstTime true;
					                    while ( movedNodes.length )
					                    {
						                        node movedNodes.shift();
						                        if ( node.getName() == 'div' )
						                        {
							                            docFrag = new CKEDITOR.dom.documentFragmenteditor.document );
							                            var needBeginBr firstTime && node.getPrevious() &&
							                                    !( node.getPrevious().type == CKEDITOR.NODE_ELEMENT && node.getPrevious().isBlockBoundary() );
							                            if ( needBeginBr )
							                                docFrag.appendeditor.document.createElement'br' ) );
							                            var needEndBr node.getNext() &&
							                                !( node.getNext().type == CKEDITOR.NODE_ELEMENT && node.getNext().isBlockBoundary() );
							                            while ( node.getFirst() )
							                                node.getFirst().remove().appendTodocFrag );
							                            if ( needEndBr )
							                                docFrag.appendeditor.document.createElement'br' ) );
							                            docFrag.replacenode );
							                            firstTime false;
							                        }
						                    }
					                }
				            }
			            selection.selectBookmarksbookmarks );
			            editor.focus();
			        }
		    };
	    CKEDITOR.plugins.add'blockquote',
	    {
		        init : function( editor )
		        {
			            editor.addCommand'blockquote'commandObject );
			            editor.ui.addButton'Blockquote',
			                {
				                    label editor.lang.blockquote,
				                    command 'blockquote'
				                } );
			            editor.on'selectionChange'onSelectionChange );
			        },
		        requires : [ 'domiterator' ]
		    } );
	})();





PHP Demo Source Code Index