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

PHP Demo Application - Source Code

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



/*
Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
(function()
{
	    var pxUnit CKEDITOR.tools.cssLength,
	        needsIEHacks CKEDITOR.env.ie && ( CKEDITOR.env.ie7Compat || CKEDITOR.env.quirks || CKEDITOR.env.version );
	    function getWidthel )
	    {
		        return CKEDITOR.env.ie el.$.clientWidth parseIntel.getComputedStyle'width' ), 10 );
		    }
	    function getBorderWidthelementside )
	    {
		        var computed element.getComputedStyle'border-' side '-width' ),
		            borderMap =
		            {
			                thin'0px',
			                medium'1px',
			                thick'2px'
			            };
		        if ( computed.indexOf'px' ) < )
		        {
			            // look up keywords
			            if ( computed in borderMap && element.getComputedStyle'border-style' ) != 'none' )
			                computed borderMapcomputed ];
			            else
			                computed 0;
			        }
		        return parseIntcomputed10 );
		    }
	    // Gets the table row that contains the most columns.
	    function getMasterPillarRowtable )
	    {
		        var $rows table.$.rows,
		            maxCells 0cellsCount,
		            $elected$tr;
		        for ( var 0len $rows.length ;
		 len;
		 i++ )
		        {
			            $tr $rows];
			            cellsCount $tr.cells.length;
			            if ( cellsCount maxCells )
			            {
				                maxCells cellsCount;
				                $elected $tr;
				            }
			        }
		        return $elected;
		    }
	    function buildTableColumnPillarstable )
	    {
		        var pillars [],
		            pillarIndex = -1,
		            rtl = ( table.getComputedStyle'direction' ) == 'rtl' );
		        // Get the raw row element that cointains the most columns.
		        var $tr getMasterPillarRowtable );
		        // Get the tbody element and position, which will be used to set the
		        // top and bottom boundaries.
		        var tbody = new CKEDITOR.dom.elementtable.$.tBodies] ),
		            tbodyPosition tbody.getDocumentPosition();
		        // Loop thorugh all cells, building pillars after each one of them.
		        for ( var 0len $tr.cells.length ;
		 len ;
		 i++ )
		        {
			            // Both the current cell and the successive one will be used in the
			            // pillar size calculation.
			            var td = new CKEDITOR.dom.element$tr.cells] ),
			                nextTd $tr.cells] && new CKEDITOR.dom.element$tr.cells] );
			            pillarIndex += td.$.colSpan || 1;
			            // Calculate the pillar boundary positions.
			            var pillarLeftpillarRightpillarWidthpillarPadding;
			            var td.getDocumentPosition().x;
			            // Calculate positions based on the current cell.
			            rtl ?
			                pillarRight getBorderWidthtd'left' ) :
			                pillarLeft  td.$.offsetWidth getBorderWidthtd'right' );
			            // Calculate positions based on the next cell, if available.
			            if ( nextTd )
			            {
				                =  nextTd.getDocumentPosition().x;
				                rtl ?
				                    pillarLeft    nextTd.$.offsetWidth getBorderWidthnextTd'right' ) :
				                    pillarRight    getBorderWidthnextTd'left' );
				            }
			            // Otherwise calculate positions based on the table (for last cell).
			            else
			            {
				                =  table.getDocumentPosition().x;
				                rtl ?
				                    pillarLeft    :
				                    pillarRight    table.$.offsetWidth;
				            }
			            pillarWidth Math.maxpillarRight pillarLeft);
			            // Make the pillar touch area at least 14 pixels wide, for easy to use.
			            pillarPadding Math.maxMath.round- ( pillarWidth ) ), );
			            // The pillar should reflects exactly the shape of the hovered
			            // column border line.
			            pillars.push( {
				                table table,
				                index pillarIndex,
				                pillarLeft,
				                tbodyPosition.y,
				                width pillarWidth,
				                heighttbody.$.offsetHeight,
				                padding pillarPadding,
				                rtl rtl
				} );
			        }
		        return pillars;
		    }
	    function getPillarAtPositionpillarspositionX )
	    {
		        for ( var 0len pillars.length ;
		 len ;
		 i++ )
		        {
			            var pillar pillars],
			                pad pillar.padding;
			            if ( positionX >= pillar.pad && positionX <= ( pillar.pillar.width pad ) )
			                return pillar;
			        }
		        return null;
		    }
	    function cancelevt )
	    {
		        ( evt.data || evt ).preventDefault();
		    }
	    function columnResizereditor )
	    {
		        var pillar,
		            document,
		            resizer,
		            isResizing,
		            startOffset,
		            currentShift;
		        var leftSideCellsrightSideCellsleftShiftBoundaryrightShiftBoundary;
		        function detach()
		        {
			            pillar null;
			            currentShift 0;
			            isResizing 0;
			            document.removeListener'mouseup'onMouseUp );
			            resizer.removeListener'mousedown'onMouseDown );
			            resizer.removeListener'mousemove'onMouseMove );
			            document.getBody().setStyle'cursor''auto' );
			            // Hide the resizer (remove it on IE7 - #5890).
			            needsIEHacks resizer.remove() : resizer.hide();
			        }
		        function resizeStart()
		        {
			            // Before starting to resize, figure out which cells to change
			            // and the boundaries of this resizing shift.
			            var columnIndex pillar.index,
			                map CKEDITOR.tools.buildTableMappillar.table ),
			                leftColumnCells [],
			                rightColumnCells [],
			                leftMinSize Number.MAX_VALUE,
			                rightMinSize leftMinSize,
			                rtl pillar.rtl;
			            for ( var 0len map.length ;
			 len ;
			 i++ )
			            {
				                var row            map],
				                    leftCell    rowcolumnIndex + ( rtl ) ],
				                    rightCell    rowcolumnIndex + ( rtl ) ];
				                leftCell    leftCell && new CKEDITOR.dom.elementleftCell );
				                rightCell    rightCell && new CKEDITOR.dom.elementrightCell );
				                if ( !leftCell || !rightCell || !leftCell.equalsrightCell ) )
				                {
					                    leftCell && ( leftMinSize Math.minleftMinSizegetWidthleftCell ) ) );
					                    rightCell && ( rightMinSize Math.minrightMinSizegetWidthrightCell ) ) );
					                    leftColumnCells.pushleftCell );
					                    rightColumnCells.pushrightCell );
					                }
				            }
			            // Cache the list of cells to be resized.
			            leftSideCells leftColumnCells;
			            rightSideCells rightColumnCells;
			            // Cache the resize limit boundaries.
			            leftShiftBoundary =  pillar.leftMinSize;
			            rightShiftBoundary pillar.rightMinSize;
			            resizer.setOpacity0.5 );
			            startOffset parseIntresizer.getStyle'left' ), 10 );
			            currentShift 0;
			            isResizing 1;
			            resizer.on'mousemove'onMouseMove );
			            // Prevent the native drag behavior otherwise 'mousemove' won't fire.
			            document.on'dragstart'cancel );
			        }
		        function resizeEnd()
		        {
			            isResizing 0;
			            resizer.setOpacity);
			            currentShift && resizeColumn();
			            var table pillar.table;
			            setTimeout( function () {
				table.removeCustomData'_cke_table_pillars' );
				}, );
			            document.removeListener'dragstart'cancel );
			        }
		        function resizeColumn()
		        {
			            var rtl pillar.rtl,
			                cellsCount rtl rightSideCells.length leftSideCells.length;
			            // Perform the actual resize to table cells, only for those by side of the pillar.
			            for ( var ;
			 cellsCount ;
			 i++ )
			            {
				                var leftCell leftSideCells],
				                    rightCell rightSideCells],
				                    table pillar.table;
				                // Defer the resizing to avoid any interference among cells.
				                CKEDITOR.tools.setTimeout(
				                    function( leftCellleftOldWidthrightCellrightOldWidthtableWidthsizeShift )
				                    {
					                        leftCell && leftCell.setStyle'width'pxUnitMath.maxleftOldWidth sizeShift) ) );
					                        rightCell && rightCell.setStyle'width'pxUnitMath.maxrightOldWidth sizeShift) ) );
					                        // If we're in the last cell, we need to resize the table as well
					                        if ( tableWidth )
					                            table.setStyle'width'pxUnittableWidth sizeShift * ( rtl ? -) ) );
					                    }
				                    , 0,
				                    this, [
				                        leftCellleftCell && getWidthleftCell ),
				                        rightCellrightCell && getWidthrightCell ),
				                        ( !leftCell || !rightCell ) && ( getWidthtable ) + getBorderWidthtable'left' ) + getBorderWidthtable'right' ) ),
				                        currentShift ] );
				            }
			        }
		        function onMouseDownevt )
		        {
			            cancelevt );
			            resizeStart();
			            document.on'mouseup'onMouseUpthis );
			        }
		        function onMouseUpevt )
		        {
			            evt.removeListener();
			            resizeEnd();
			        }
		        function onMouseMoveevt )
		        {
			            moveevt.data.$.clientX );
			        }
		        document editor.document;
		        resizer CKEDITOR.dom.element.createFromHtml(
		            '<div cke_temp=1 contenteditable=false unselectable=on '+
		            'style="position:absolute;
		cursor:col-resize;
		filter:alpha(opacity=0);
		opacity:0;
		' +
		                'padding:0;
		background-color:#004;
		background-image:none;
		border:0px none;
		z-index:10"></div>'document );
		        // Except on IE6/7 (#5890), place the resizer after body to prevent it
		        // from being editable.
		        if ( !needsIEHacks )
		            document.getDocumentElement().appendresizer );
		        this.attachTo = function( targetPillar )
		        {
			            // Accept only one pillar at a time.
			            if ( isResizing )
			                return;
			            // On IE6/7, we append the resizer everytime we need it. (#5890)
			            if ( needsIEHacks )
			            {
				                document.getBody().appendresizer );
				                currentShift 0;
				            }
			            pillar targetPillar;
			            resizer.setStyles(
			                {
				                    widthpxUnittargetPillar.width ),
				                    height pxUnittargetPillar.height ),
				                    left pxUnittargetPillar.),
				                    top pxUnittargetPillar.)
				                });
			            // In IE6/7, it's not possible to have custom cursors for floating
			            // elements in an editable document. Show the resizer in that case,
			            // to give the user a visual clue.
			            needsIEHacks && resizer.setOpacity0.25 );
			            resizer.on'mousedown'onMouseDownthis );
			            document.getBody().setStyle'cursor''col-resize' );
			            // Display the resizer to receive events but don't show it,
			            // only change the cursor to resizable shape.
			            resizer.show();
			        };
		        var move this.move = function( posX )
		        {
			            if ( !pillar )
			                return 0;
			            var pad pillar.padding;
			            if ( !isResizing && ( posX pillar.pad || posX > ( pillar.pillar.width pad ) ) )
			            {
				                detach();
				                return 0;
				            }
			            var resizerNewPosition posX Math.roundresizer.$.offsetWidth );
			            if ( isResizing )
			            {
				                if ( resizerNewPosition == leftShiftBoundary || resizerNewPosition == rightShiftBoundary )
				                    return 1;
				                resizerNewPosition Math.maxresizerNewPositionleftShiftBoundary );
				                resizerNewPosition Math.minresizerNewPositionrightShiftBoundary );
				                currentShift resizerNewPosition startOffset;
				            }
			            resizer.setStyle'left'pxUnitresizerNewPosition ) );
			            return 1;
			        };
		    }
	    function clearPillarsCacheevt )
	    {
		        var target evt.data.getTarget();
		        if ( evt.name == 'mouseout' )
		        {
			            // Bypass interal mouse move.
			            if ( !target.is 'table' ) )
			                return;
			            var dest = new CKEDITOR.dom.elementevt.data.$.relatedTarget || evt.data.$.toElement );
			            while( dest && dest.$ && !dest.equalstarget ) && !dest.is'body' ) )
			                dest dest.getParent();
			            if ( !dest || dest.equalstarget ) )
			                return;
			        }
		        target.getAscendant'table'true ).removeCustomData'_cke_table_pillars' );
		        evt.removeListener();
		    }
	    CKEDITOR.plugins.add'tableresize',
	    {
		        requires : [ 'tabletools' ],
		        init : function( editor )
		        {
			            editor.on'contentDom', function()
			            {
				                var resizer;
				                editor.document.getBody().on'mousemove', function( evt )
				                    {
					                        evt evt.data;
					                        // If we're already attached to a pillar, simply move the
					                        // resizer.
					                        if ( resizer && resizer.moveevt.$.clientX ) )
					                        {
						                            cancelevt );
						                            return;
						                        }
					                        // Considering table, tr, td, tbody but nothing else.
					                        var target evt.getTarget(),
					                            table,
					                            pillars;
					                        if ( !target.is'table' ) && !target.getAscendant'tbody'true ) )
					                            return;
					                        table target.getAscendant'table'true );
					                        if ( !( pillars table.getCustomData'_cke_table_pillars' ) ) )
					                        {
						                            // Cache table pillars calculation result.
						                            table.setCustomData'_cke_table_pillars', ( pillars buildTableColumnPillarstable ) ) );
						                            table.on'mouseout'clearPillarsCache );
						                            table.on'mousedown'clearPillarsCache );
						                        }
					                        var pillar getPillarAtPositionpillarsevt.$.clientX );
					                        if ( pillar )
					                        {
						                            !resizer && ( resizer = new columnResizereditor ) );
						                            resizer.attachTopillar );
						                        }
					                    });
				            });
			        }
		    });
	})();





PHP Demo Source Code Index