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

📄 datatable.js

📁 这是YUI的源码及相关示例。里面有很多很炫的Javascript效果。
💻 JS
📖 第 1 页 / 共 5 页
字号:
/****************************************************************************//****************************************************************************//****************************************************************************//** * 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 {    }};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 {    }};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";                }            }        },        /**         * Handles drag events on the Column resizer.         *         * @method onDrag         * @param e {string} The drag event         */        onDrag : function(e) {            var newX = YAHOO.util.Event.getXY(e)[0];            if(newX > YAHOO.util.Dom.getX(this.headCellLiner)) {                var offsetX = newX - this.startX;                var newWidth = this.startWidth + offsetX - this.nLinerPadding;                if(newWidth > 0) {                    this.datatable.setColumnWidth(this.column, newWidth);                }            }        }    });}///////////////////////////////////////////////////////////////////////////////// Deprecated////////////////////////////////////////////////////////////////////////////////** * @property editorOptions * @deprecated Pass configs directly to CellEditor constructor.  */(function () {var lang   = YAHOO.lang,    util   = YAHOO.util,    widget = YAHOO.widget,        Dom    = util.Dom,    Ev     = util.Event,    DT     = widget.DataTable;/****************************************************************************//****************************************************************************//****************************************************************************//** * A RecordSet defines and manages a set of Records. * * @namespace YAHOO.widget * @class RecordSet * @param data {Object || Object[]} An object literal or an array of data. * @constructor */YAHOO.widget.RecordSet = function(data) {    // Internal variables    this._sId = "yui-rs" + widget.RecordSet._nCount;    widget.RecordSet._nCount++;    this._records = [];    //this._length = 0;    if(data) {        if(lang.isArray(data)) {            this.addRecords(data);        }        else if(lang.isObject(data)) {            this.addRecord(data);        }    }};var RS = widget.RecordSet;/** * Internal class variable to name multiple Recordset instances. * * @property RecordSet._nCount * @type Number * @private * @static */RS._nCount = 0;RS.prototype = {    /////////////////////////////////////////////////////////////////////////////    //    // Private member variables    //    /////////////////////////////////////////////////////////////////////////////    /**

⌨️ 快捷键说明

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