70% OFF : CLICK HERE TO BUY IT TODAY FOR ONLY $44.70 OR GET IT FREE VIA TRIALPAY  

PHP Demo Application - Source Code

/Framework/Model/Vendor/CkEditor/_source/plugins/div/dialogs/div.js



/*
 * Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
 * For licensing, see LICENSE.html or http://ckeditor.com/license
 */
(function()
{
	    /**
	     * Add to collection with DUP examination.
	     * @param {Object} collection
	     * @param {Object} element
	     * @param {Object} database
	     */
	    function addSafelycollectionelementdatabase )
	    {
		        // 1. IE doesn't support customData on text nodes;
		        // 2. Text nodes never get chance to appear twice;
		        if ( !element.is || !element.getCustomData'block_processed' ) )
		        {
			            element.is && CKEDITOR.dom.element.setMarkerdatabaseelement'block_processed'true );
			            collection.pushelement );
			        }
		    }
	    function getNonEmptyChildrenelement )
	    {
		        var retval [];
		        var children element.getChildren();
		        for ( var ;
		 children.count() ;
		 i++ )
		        {
			            var child children.getItem);
			            if ( ! ( child.type === CKEDITOR.NODE_TEXT
			                && ( /^[ \t\n\r]+$/ ).testchild.getText() ) ) )
			                retval.pushchild );
			        }
		        return retval;
		    }
	    /**
	     * Dialog reused by both 'creatediv' and 'editdiv' commands.
	     * @param {Object} editor
	     * @param {String} command    The command name which indicate what the current command is.
	     */
	    function divDialogeditorcommand )
	    {
		        // Definition of elements at which div operation should stopped.
		        var divLimitDefinition = ( function(){
			            // Customzie from specialize blockLimit elements
			            var definition CKEDITOR.tools.extend{}CKEDITOR.dtd.$blockLimit );
			            // Exclude 'div' itself.
			            delete definition.div;
			            // Exclude 'td' and 'th' when 'wrapping table'
			            if ( editor.config.div_wrapTable )
			            {
				                delete definition.td;
				                delete definition.th;
				            }
			            return definition;
			        })();
		        // DTD of 'div' element
		        var dtd CKEDITOR.dtd.div;
		        /**
		         * Get the first div limit element on the element's path.
		         * @param {Object} element
		         */
		        function getDivLimitElementelement )
		        {
			            var pathElements = new CKEDITOR.dom.elementPathelement ).elements;
			            var divLimit;
			            for ( var 0;
			 pathElements.length ;
			 i++ )
			            {
				                if ( pathElements].getName() in divLimitDefinition )
				                {
					                    divLimit pathElements];
					                    break;
					                }
				            }
			            return divLimit;
			        }
		        /**
		         * Init all fields' setup/commit function.
		         * @memberof divDialog
		         */
		        function setupFields()
		        {
			            this.foreach( function( field )
			            {
				                // Exclude layout container elements
				                if ( /^(?!vbox|hbox)/.testfield.type ) )
				                {
					                    if ( !field.setup )
					                    {
						                        // Read the dialog fields values from the specified
						                        // element attributes.
						                        field.setup = function( element )
						                        {
							                            field.setValueelement.getAttributefield.id ) || '' );
							                        };
						                    }
					                    if ( !field.commit )
					                    {
						                        // Set element attributes assigned by the dialog
						                        // fields.
						                        field.commit = function( element )
						                        {
							                            var fieldValue this.getValue();
							                            // ignore default element attribute values
							                            if ( 'dir' == field.id && element.getComputedStyle'direction' ) == fieldValue )
							                                return;
							                            if ( fieldValue )
							                                element.setAttributefield.idfieldValue );
							                            else
							                                element.removeAttributefield.id );
							                        };
						                    }
					                }
				            } );
			        }
		        /**
		         * Wrapping 'div' element around appropriate blocks among the selected ranges.
		         * @param {Object} editor
		         */
		        function createDiveditor )
		        {
			            // new adding containers OR detected pre-existed containers.
			            var containers [];
			            // node markers store.
			            var database {};
			            // All block level elements which contained by the ranges.
			            var containedBlocks []block;
			            // Get all ranges from the selection.
			            var selection editor.document.getSelection();
			            var ranges selection.getRanges();
			            var bookmarks selection.createBookmarks();
			            var iiterator;
			            // Calcualte a default block tag if we need to create blocks.
			            var blockTag editor.config.enterMode == CKEDITOR.ENTER_DIV 'div' 'p';
			            // collect all included elements from dom-iterator
			            for ( ;
			 ranges.length ;
			 i++ )
			            {
				                iterator ranges].createIterator();
				                while ( ( block iterator.getNextParagraph() ) )
				                {
					                    // include contents of blockLimit elements.
					                    if ( block.getName() in divLimitDefinition )
					                    {
						                        var jchildNodes block.getChildren();
						                        for ( ;
						 childNodes.count() ;
						 j++ )
						                            addSafelycontainedBlockschildNodes.getItem) , database );
						                    }
					                    else
					                    {
						                        // Bypass dtd disallowed elements.
						                        while ( !dtdblock.getName() ] && block.getName() != 'body' )
						                            block block.getParent();
						                        addSafelycontainedBlocksblockdatabase );
						                    }
					                }
				            }
			            CKEDITOR.dom.element.clearAllMarkersdatabase );
			            var blockGroups groupByDivLimitcontainedBlocks );
			            var ancestorblockEldivElement;
			            for ( ;
			 blockGroups.length ;
			 i++ )
			            {
				                var currentNode blockGroups][ ];
				                // Calculate the common parent node of all contained elements.
				                ancestor currentNode.getParent();
				                for ( ;
				 blockGroups].length;
				 j++ )
				                    ancestor ancestor.getCommonAncestorblockGroups][ ] );
				                divElement = new CKEDITOR.dom.element'div'editor.document );
				                // Normalize the blocks in each group to a common parent.
				                for ( 0;
				 blockGroups].length ;
				 j++ )
				                {
					                    currentNode blockGroups][ ];
					                    while ( !currentNode.getParent().equalsancestor ) )
					                        currentNode currentNode.getParent();
					                    // This could introduce some duplicated elements in array.
					                    blockGroups][ ] = currentNode;
					                }
				                // Wrapped blocks counting
				                var fixedBlock null;
				                for ( ;
				 blockGroups].length ;
				 j++ )
				                {
					                    currentNode blockGroups][ ];
					                    // Avoid DUP elements introduced by grouping.
					                    if ( !( currentNode.getCustomData && currentNode.getCustomData'block_processed' ) ) )
					                    {
						                        currentNode.is && CKEDITOR.dom.element.setMarkerdatabasecurrentNode'block_processed'true );
						                        // Establish new container, wrapping all elements in this group.
						                        if ( !)
						                            divElement.insertBeforecurrentNode );
						                        divElement.appendcurrentNode );
						                    }
					                }
				                CKEDITOR.dom.element.clearAllMarkersdatabase );
				                containers.pushdivElement );
				            }
			            selection.selectBookmarksbookmarks );
			            return containers;
			        }
		        function getDiveditor )
		        {
			            var path = new CKEDITOR.dom.elementPatheditor.getSelection().getStartElement() ),
			                blockLimit path.blockLimit,
			                div blockLimit && blockLimit.getAscendant'div'true );
			            return div;
			        }
		        /**
		         * Divide a set of nodes to different groups by their path's blocklimit element.
		         * Note: the specified nodes should be in source order naturally, which mean they are supposed to producea by following class:
		         *  * CKEDITOR.dom.range.Iterator
		         *  * CKEDITOR.dom.domWalker
		         *  @return {Array []} the grouped nodes
		         */
		        function groupByDivLimitnodes )
		        {
			            var groups [],
			                lastDivLimit null,
			                pathblock;
			            for ( var ;
			 nodes.length ;
			 i++ )
			            {
				                block nodes[i];
				                var limit getDivLimitElementblock );
				                if ( !limit.equalslastDivLimit ) )
				                {
					                    lastDivLimit limit ;
					                    groups.push[] ) ;
					                }
				                groupsgroups.length ].pushblock ) ;
				            }
			            return groups;
			        }
		        // Synchronous field values to other impacted fields is required, e.g. div styles
		        // change should also alter inline-style text.
		        function commitInternallytargetFields )
		        {
			            var dialog this.getDialog(),
			                 element dialog._element && dialog._element.clone()
			                         || new CKEDITOR.dom.element'div'editor.document );
			            // Commit this field and broadcast to target fields.
			            this.commitelementtrue );
			            targetFields [].concattargetFields );
			            var length targetFields.lengthfield;
			            for ( var 0;
			 length;
			 i++ )
			            {
				                field dialog.getContentElement.applydialogtargetFields].split':' ) );
				                field && field.setup && field.setupelementtrue );
				            }
			        }
		        // Registered 'CKEDITOR.style' instances.
		        var styles {} ;
		        /**
		         * Hold a collection of created block container elements.
		         */
		        var containers [];
		        /**
		         * @type divDialog
		         */
		        return {
			            title editor.lang.div.title,
			            minWidth 400,
			            minHeight 165,
			            contents :
			            [
			            {
				                id :'info',
				                label :editor.lang.common.generalTab,
				                title :editor.lang.common.generalTab,
				                elements :
				                [
				                    {
					                        type :'hbox',
					                        widths : [ '50%''50%' ],
					                        children :
					                        [
					                            {
						                                id :'elementStyle',
						                                type :'select',
						                                style :'width: 100%;
						',
						                                label :editor.lang.div.styleSelectLabel,
						                                'default' '',
						                                // Options are loaded dynamically.
						                                items :
						                                [
						                                    [ editor.lang.common.notSet '' ]
						                                ],
						                                onChange : function()
						                                {
							                                    commitInternally.callthis, [ 'info:class''advanced:dir''advanced:style' ] );
							                                },
						                                setup : function( element )
						                                {
							                                    for ( var name in styles )
							                                        stylesname ].checkElementRemovableelementtrue ) && this.setValuename );
							                                },
						                                commit: function( element )
						                                {
							                                    var styleName;
							                                    if ( ( styleName this.getValue() ) )
							                                    {
								                                        var style stylesstyleName ];
								                                        var customData element.getCustomData'elementStyle' ) || '';
								                                        style.applyToObjectelement );
								                                        element.setCustomData'elementStyle'customData style._.definition.attributes.style );
								                                    }
							                                }
						                            },
					                            {
						                                id :'class',
						                                type :'text',
						                                label :editor.lang.common.cssClass,
						                                'default' ''
						                            }
					                        ]
					                    }
				                ]
				            },
			            {
				                    id :'advanced',
				                    label :editor.lang.common.advancedTab,
				                    title :editor.lang.common.advancedTab,
				                    elements :
				                    [
				                    {
					                        type :'vbox',
					                        padding :1,
					                        children :
					                        [
					                            {
						                                type :'hbox',
						                                widths : [ '50%''50%' ],
						                                children :
						                                [
						                                    {
							                                        type :'text',
							                                        id :'id',
							                                        label :editor.lang.common.id,
							                                        'default' ''
							                                    },
						                                    {
							                                        type :'text',
							                                        id :'lang',
							                                        label :editor.lang.link.langCode,
							                                        'default' ''
							                                    }
						                                ]
						                            },
					                            {
						                                type :'hbox',
						                                children :
						                                [
						                                        {
							                                            type :'text',
							                                            id :'style',
							                                            style :'width: 100%;
							',
							                                            label :editor.lang.common.cssStyle,
							                                            'default' '',
							                                            commit : function( element )
							                                            {
								                                                // Merge with 'elementStyle', which is of higher priority.
								                                                var merged this.getValue() + ( element.getCustomData'elementStyle' ) || '' );
								                                                element.setAttribute'style'merged );
								                                            }
							                                        }
						                                ]
						                            },
					                            {
						                                type :'hbox',
						                                children :
						                                [
						                                        {
							                                            type :'text',
							                                            id :'title',
							                                            style :'width: 100%;
							',
							                                            label :editor.lang.common.advisoryTitle,
							                                            'default' ''
							                                        }
						                                ]
						                            },
					                            {
						                                type :'select',
						                                id :'dir',
						                                style :'width: 100%;
						',
						                                label :editor.lang.common.langDir,
						                                'default' '',
						                                items :
						                                [
						                                    [ editor.lang.common.notSet '' ],
						                                    [
						                                        editor.lang.common.langDirLtr,
						                                        'ltr'
						                                    ],
						                                    [
						                                        editor.lang.common.langDirRtl,
						                                        'rtl'
						                                    ]
						                                ]
						                            }
					                        ]
					                    }
				                    ]
				                }
			            ],
			            onLoad : function()
			            {
				                setupFields.call(this);
				                // Preparing for the 'elementStyle' field.
				                var dialog this,
				                     stylesField this.getContentElement'info''elementStyle' );
				                 // Reuse the 'stylescombo' plugin's styles definition.
				                editor.getStylesSet( function( stylesDefinitions )
				                {
					                    var styleName;
					                    if ( stylesDefinitions )
					                    {
						                        // Digg only those styles that apply to 'div'.
						                        for ( var ;
						 stylesDefinitions.length ;
						 i++ )
						                        {
							                            var styleDefinition stylesDefinitions];
							                            if ( styleDefinition.element && styleDefinition.element == 'div' )
							                            {
								                                styleName styleDefinition.name;
								                                stylesstyleName ] = new CKEDITOR.stylestyleDefinition );
								                                // Populate the styles field options with style name.
								                                stylesField.items.push( [ styleNamestyleName ] );
								                                stylesField.addstyleNamestyleName );
								                            }
							                        }
						                    }
					                    // We should disable the content element
					                    // it if no options are available at all.
					                    stylesFieldstylesField.items.length 'enable' 'disable' ]();
					                    // Now setup the field value manually.
					                    setTimeout( function() {
						stylesField.setupdialog._element );
						}, );
					                } );
				            },
			            onShow : function()
			            {
				                // Whether always create new container regardless of existed
				                // ones.
				                if ( command == 'editdiv' )
				                {
					                    // Try to discover the containers that already existed in
					                    // ranges
					                    var div getDiveditor );
					                    // update dialog field values
					                    div && this.setupContentthis._element div );
					                }
				            },
			            onOk : function()
			            {
				                if ( command == 'editdiv' )
				                    containers = [ this._element ];
				                else
				                    containers createDiveditortrue );
				                // Update elements attributes
				                var size containers.length;
				                for ( var 0;
				 size;
				 i++ )
				                {
					                    this.commitContentcontainers] );
					                    // Remove empty 'style' attribute.
					                    !containers].getAttribute'style' ) && containers].removeAttribute'style' );
					                }
				                this.hide();
				            },
			            onHide : function()
			            {
				                // Remove style only when editing existing DIV. (#6315)
				                if ( command == 'editdiv' )
				                    this._element.removeCustomData'elementStyle' );
				                delete this._element;
				            }
			        };
		    }
	    CKEDITOR.dialog.add'creatediv', function( editor )
	        {
		            return divDialogeditor'creatediv' );
		        } );
	    CKEDITOR.dialog.add'editdiv', function( editor )
	        {
		            return divDialogeditor'editdiv' );
		        } );
	} )();
/*
 * @name CKEDITOR.config.div_wrapTable
 * Whether to wrap the whole table instead of indivisual cells when created 'div' in table cell.
 * @type Boolean
 * @default false
 * @example config.div_wrapTable = true;
 */





PHP Demo Source Code Index