⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datatable-debug.js

📁 这是YUI的源码及相关示例。里面有很多很炫的Javascript效果。
💻 JS
📖 第 1 页 / 共 5 页
字号:
     * Public accessor returns Column's calculated COLSPAN value.     *     * @method getColspan     * @return {Number} Column's COLSPAN value.     */    getColspan : function() {        return this._nColspan;    },    // Backward compatibility    getColSpan : function() {        YAHOO.log("The method getColSpan() has been" +        " deprecated in favor of getColspan()", "warn", this.toString());        return this.getColspan();    },    /**     * Public accessor returns Column's calculated ROWSPAN value.     *     * @method getRowspan     * @return {Number} Column's ROWSPAN value.     */    getRowspan : function() {        return this._nRowspan;    },    /**     * Returns DOM reference to the key TH element.     *     * @method getThEl     * @return {HTMLElement} TH element.     */    getThEl : function() {        return this._elTh;    },    /**     * Returns DOM reference to the TH's liner DIV element. Introduced since     * resizeable Columns may have an extra resizer liner, making the DIV liner     * not reliably the TH element's first child.                    *     * @method getThLInerEl     * @return {HTMLElement} TH element.     */    getThLinerEl : function() {        return this._elThLiner;    },        /**     * Returns DOM reference to the resizer element, or null.     *     * @method getResizerEl     * @return {HTMLElement} DIV element.     */    getResizerEl : function() {        return this._elResizer;    },    // Backward compatibility    /**     * @method getColEl     * @deprecated Use getThEl     */    getColEl : function() {        YAHOO.log("The method getColEl() has been" +        " deprecated in favor of getThEl()", "warn",        this.toString());        return this.getThEl();    },    getIndex : function() {        YAHOO.log("The method getIndex() has been" +        " deprecated in favor of getKeyIndex()", "warn",        this.toString());        return this.getKeyIndex();    },    format : function() {        YAHOO.log("The method format() has been deprecated in favor of the " +        "DataTable method formatCell()", "error", this.toString());    }};/****************************************************************************//****************************************************************************//****************************************************************************//** * Sort static utility to support Column sorting. * * @namespace YAHOO.util * @class Sort * @static */YAHOO.util.Sort = {    /////////////////////////////////////////////////////////////////////////////    //    // Public methods    //    /////////////////////////////////////////////////////////////////////////////    /**     * Comparator function for simple case-insensitive string sorting.     *     * @method compare     * @param a {Object} First sort argument.     * @param b {Object} Second sort argument.     * @param desc {Boolean} True if sort direction is descending, false if     * sort direction is ascending.     */    compare: function(a, b, desc) {        if((a === null) || (typeof a == "undefined")) {            if((b === null) || (typeof b == "undefined")) {                return 0;            }            else {                return 1;            }        }        else if((b === null) || (typeof b == "undefined")) {            return -1;        }        if(a.constructor == String) {            a = a.toLowerCase();        }        if(b.constructor == String) {            b = b.toLowerCase();        }        if(a < b) {            return (desc) ? 1 : -1;        }        else if (a > b) {            return (desc) ? -1 : 1;        }        else {            return 0;        }    }};/****************************************************************************//****************************************************************************//****************************************************************************//** * ColumnDD subclasses DragDrop to support rearrangeable Columns. * * @namespace YAHOO.util * @class ColumnDD * @extends YAHOO.util.DDProxy * @constructor * @param oDataTable {YAHOO.widget.DataTable} DataTable instance. * @param oColumn {YAHOO.widget.Column} Column instance. * @param elTh {HTMLElement} TH element reference. * @param elTarget {HTMLElement} Drag target element. */YAHOO.widget.ColumnDD = function(oDataTable, oColumn, elTh, elTarget) {    if(oDataTable && oColumn && elTh && elTarget) {        this.datatable = oDataTable;        this.table = oDataTable.getTableEl();        this.column = oColumn;        this.headCell = elTh;        this.pointer = elTarget;        this.newIndex = null;        this.init(elTh);        this.initFrame(); // Needed for DDProxy        this.invalidHandleTypes = {};        // Set top/bottom padding to account for children of nested columns        this.setPadding(10, 0, (this.datatable.getTheadEl().offsetHeight + 10) , 0);        YAHOO.util.Event.on(window, 'resize', function() {            this.initConstraints();        }, this, true);    }    else {        YAHOO.log("Column dragdrop could not be created","warn",oDataTable.toString());    }};if(YAHOO.util.DDProxy) {    YAHOO.extend(YAHOO.widget.ColumnDD, YAHOO.util.DDProxy, {        initConstraints: function() {            //Get the top, right, bottom and left positions            var region = YAHOO.util.Dom.getRegion(this.table),                //Get the element we are working on                el = this.getEl(),                //Get the xy position of it                xy = YAHOO.util.Dom.getXY(el),                //Get the width and height                width = parseInt(YAHOO.util.Dom.getStyle(el, 'width'), 10),                height = parseInt(YAHOO.util.Dom.getStyle(el, 'height'), 10),                //Set left to x minus left                left = ((xy[0] - region.left) + 15), //Buffer of 15px                //Set right to right minus x minus width                right = ((region.right - xy[0] - width) + 15);                //Set the constraints based on the above calculations            this.setXConstraint(left, right);            this.setYConstraint(10, 10);                    },        _resizeProxy: function() {            this.constructor.superclass._resizeProxy.apply(this, arguments);            var dragEl = this.getDragEl(),                el = this.getEl();            YAHOO.util.Dom.setStyle(this.pointer, 'height', (this.table.parentNode.offsetHeight + 10) + 'px');            YAHOO.util.Dom.setStyle(this.pointer, 'display', 'block');            var xy = YAHOO.util.Dom.getXY(el);            YAHOO.util.Dom.setXY(this.pointer, [xy[0], (xy[1] - 5)]);                        YAHOO.util.Dom.setStyle(dragEl, 'height', this.datatable.getContainerEl().offsetHeight + "px");            YAHOO.util.Dom.setStyle(dragEl, 'width', (parseInt(YAHOO.util.Dom.getStyle(dragEl, 'width'),10) + 4) + 'px');            YAHOO.util.Dom.setXY(this.dragEl, xy);        },        onMouseDown: function() {                this.initConstraints();                this.resetConstraints();        },        clickValidator: function(e) {            if(!this.column.hidden) {                var target = YAHOO.util.Event.getTarget(e);                return ( this.isValidHandleChild(target) &&                            (this.id == this.handleElId ||                                this.DDM.handleWasClicked(target, this.id)) );            }        },        onDragOver: function(ev, id) {            // Validate target as a Column            var target = this.datatable.getColumn(id);            if(target) {                                // Validate target as a top-level parent                var targetIndex = target.getTreeIndex();                while((targetIndex === null) && target.getParent()) {                    target = target.getParent();                    targetIndex = target.getTreeIndex();                }                if(targetIndex !== null) {                    // Are we placing to left or right of target?                    var elTarget = target.getThEl();                    var newIndex = targetIndex;                    var mouseX = YAHOO.util.Event.getPageX(ev),                        targetX = YAHOO.util.Dom.getX(elTarget),                        midX = targetX + ((YAHOO.util.Dom.get(elTarget).offsetWidth)/2),                        currentIndex =  this.column.getTreeIndex();                                        if (mouseX < midX) {                       YAHOO.util.Dom.setX(this.pointer, targetX);                    } else {                        var targetWidth = parseInt(elTarget.offsetWidth, 10);                        YAHOO.util.Dom.setX(this.pointer, (targetX + targetWidth));                        newIndex++;                    }                    if (targetIndex > currentIndex) {                        newIndex--;                    }                    if(newIndex < 0) {                        newIndex = 0;                    }                    else if(newIndex > this.datatable.getColumnSet().tree[0].length) {                        newIndex = this.datatable.getColumnSet().tree[0].length;                    }                    this.newIndex = newIndex;                }            }        },        onDragDrop: function() {            this.datatable.reorderColumn(this.column, this.newIndex);        },        endDrag: function() {            this.newIndex = null;            YAHOO.util.Dom.setStyle(this.pointer, 'display', 'none');        }    });}/****************************************************************************//****************************************************************************//****************************************************************************//** * ColumnResizer subclasses DragDrop to support resizeable Columns. * * @namespace YAHOO.util * @class ColumnResizer * @extends YAHOO.util.DDProxy * @constructor * @param oDataTable {YAHOO.widget.DataTable} DataTable instance. * @param oColumn {YAHOO.widget.Column} Column instance. * @param elTh {HTMLElement} TH element reference. * @param sHandleElId {String} DOM ID of the handle element that causes the resize. * @param elProxy {HTMLElement} Resizer proxy element. */YAHOO.util.ColumnResizer = function(oDataTable, oColumn, elTh, sHandleId, elProxy) {    if(oDataTable && oColumn && elTh && sHandleId) {        this.datatable = oDataTable;        this.column = oColumn;        this.headCell = elTh;        this.headCellLiner = oColumn.getThLinerEl();        this.resizerLiner = elTh.firstChild;        this.init(sHandleId, sHandleId, {dragOnly:true, dragElId: elProxy.id});        this.initFrame(); // Needed for proxy        this.resetResizerEl(); // Needed when rowspan > 0        // Set right padding for bug 1858462        this.setPadding(0, 1, 0, 0);    }    else {        YAHOO.log("Column resizer could not be created","warn",oDataTable.toString());    }};if(YAHOO.util.DD) {    YAHOO.extend(YAHOO.util.ColumnResizer, YAHOO.util.DDProxy, {        /////////////////////////////////////////////////////////////////////////////        //        // Public methods        //        /////////////////////////////////////////////////////////////////////////////        /**         * Resets resizer element.         *         * @method resetResizerEl         */        resetResizerEl : function() {            var resizerStyle = YAHOO.util.Dom.get(this.handleElId).style;            resizerStyle.left = "auto";            resizerStyle.right = 0;            resizerStyle.top = "auto";            resizerStyle.bottom = 0;            resizerStyle.height = this.headCell.offsetHeight+"px";        },            /////////////////////////////////////////////////////////////////////////////        //        // Public DOM event handlers        //        /////////////////////////////////////////////////////////////////////////////            /**         * Handles mouseup events on the Column resizer.         *         * @method onMouseUp         * @param e {string} The mouseup event         */        onMouseUp : function(e) {            // Reset height of all resizer els in case TH's have changed height            var allKeys = this.datatable.getColumnSet().keys,                col;            for(var i=0, len=allKeys.length; i<len; i++) {                col = allKeys[i];                if(col._ddResizer) {                    col._ddResizer.resetResizerEl();                }            }            this.resetResizerEl();                        var el = this.headCellLiner;            var newWidth = el.offsetWidth -                (parseInt(YAHOO.util.Dom.getStyle(el,"paddingLeft"),10)|0) -                (parseInt(YAHOO.util.Dom.getStyle(el,"paddingRight"),10)|0);            this.datatable.fireEvent("columnResizeEvent", {column:this.column,target:this.headCell,width:newWidth});        },            /**         * Handles mousedown events on the Column resizer.         *         * @method onMouseDown         * @param e {string} The mousedown event         */        onMouseDown : function(e) {            this.startWidth = this.headCellLiner.offsetWidth;            this.startX = YAHOO.util.Event.getXY(e)[0];            this.nLinerPadding = (parseInt(YAHOO.util.Dom.getStyle(this.headCellLiner,"paddingLeft"),10)|0) +                    (parseInt(YAHOO.util.Dom.getStyle(this.headCellLiner,"paddingRight"),10)|0);        },            /**         * Custom clickValidator to ensure Column is not in hidden state.         *         * @method clickValidator         * @param {Event} e         * @private         */        clickValidator : function(e) {            if(!this.column.hidden) {                var target = YAHOO.util.Event.getTarget(e);                return ( this.isValidHandleChild(target) &&                            (this.id == this.handleElId ||                                this.DDM.handleWasClicked(target, this.id)) );            }        },            /**         * Handles start drag on the Column resizer.         *         * @method startDrag         * @param e {string} The drag event         */        startDrag : function() {            // Shrinks height of all resizer els to not hold open TH els            var allKeys = this.datatable.getColumnSet().keys,                thisKey = this.column.getKeyIndex(),                col;            for(var i=0, len=allKeys.length; i<len; i++) {                col = allKeys[i];                if(col._ddResizer) {                    YAHOO.util.Dom.get(col._ddResizer.handleElId).style.height = "1em";                }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -