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

📄 paginator-debug.js

📁 这是YUI的源码及相关示例。里面有很多很炫的Javascript效果。
💻 JS
📖 第 1 页 / 共 5 页
字号:
/*Copyright (c) 2008, Yahoo! Inc. All rights reserved.Code licensed under the BSD License:http://developer.yahoo.net/yui/license.txtversion: 2.6.0*//** * The Paginator widget provides a set of controls to navigate through paged * data. * * @module paginator * @uses YAHOO.util.EventProvider * @uses YAHOO.util.AttributeProvider *//** * Instantiate a Paginator, passing a configuration object to the contructor. * The configuration object should contain the following properties: * <ul> *   <li>rowsPerPage : <em>n</em> (int)</li> *   <li>totalRecords : <em>n</em> (int or Paginator.VALUE_UNLIMITED)</li> *   <li>containers : <em>id | el | arr</em> (HTMLElement reference, its id, or an array of either)</li> * </ul> * * @namespace YAHOO.widget * @class Paginator * @constructor * @param config {Object} Object literal to set instance and ui component * configuration. */YAHOO.widget.Paginator = function (config) {    var UNLIMITED = YAHOO.widget.Paginator.VALUE_UNLIMITED,        lang      = YAHOO.lang,        attrib, initialPage, records, perPage;    config = lang.isObject(config) ? config : {};    this.initConfig();    this.initEvents();    // Set the basic config keys first    this.set('rowsPerPage',config.rowsPerPage,true);    if (lang.isNumber(config.totalRecords)) {        this.set('totalRecords',config.totalRecords,true);    }        this.initUIComponents();    // Update the other config values    for (attrib in config) {        if (lang.hasOwnProperty(config,attrib)) {            this.set(attrib,config[attrib],true);        }    }    // Calculate the initial record offset    initialPage = this.get('initialPage');    records     = this.get('totalRecords');    perPage     = this.get('rowsPerPage');    if (initialPage > 1 && perPage !== UNLIMITED) {        var startIndex = (initialPage - 1) * perPage;        if (records === UNLIMITED || startIndex < records) {            this.set('recordOffset',startIndex,true);        }    }};// Static membersYAHOO.lang.augmentObject(YAHOO.widget.Paginator, {    /**     * Incrementing index used to give instances unique ids.     * @static     * @property id     * @type number     * @private     */    id : 0,    /**     * Base of id strings used for ui components.     * @static     * @property ID_BASE     * @type string     * @private     */    ID_BASE : 'yui-pg',    /**     * Used to identify unset, optional configurations, or used explicitly in     * the case of totalRecords to indicate unlimited pagination.     * @static     * @property VALUE_UNLIMITED     * @type number     * @final     */    VALUE_UNLIMITED : -1,    /**     * Default template used by Paginator instances.  Update this if you want     * all new Paginators to use a different default template.     * @static     * @property TEMPLATE_DEFAULT     * @type string     */    TEMPLATE_DEFAULT : "{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}",    /**     * Common alternate pagination format, including page links, links for     * previous, next, first and last pages as well as a rows-per-page     * dropdown.  Offered as a convenience.     * @static     * @property TEMPLATE_ROWS_PER_PAGE     * @type string     */    TEMPLATE_ROWS_PER_PAGE : "{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}",    /**     * Storage object for UI Components     * @static     * @property ui     */    ui : {}},true);// Instance members and methodsYAHOO.widget.Paginator.prototype = {    // Instance members    /**     * Array of nodes in which to render pagination controls.  This is set via     * the &quot;containers&quot; attribute.     * @property _containers     * @type Array(HTMLElement)     * @private     */    _containers : [],    /**     * Flag used to indicate multiple attributes are being updated via setState     * @property _batch     * @type boolean     * @protected     */    _batch : false,    /**     * Used by setState to indicate when a page change has occurred     * @property _pageChanged     * @type boolean     * @protected     */    _pageChanged : false,    /**     * Temporary state cache used by setState to keep track of the previous     * state for eventual pageChange event firing     * @property _state     * @type Object     * @protected     */    _state : null,    // Instance methods    /**     * Initialize the Paginator's attributes (see YAHOO.util.Element class     * AttributeProvider).     * @method initConfig     * @private     */    initConfig : function () {        var UNLIMITED = YAHOO.widget.Paginator.VALUE_UNLIMITED,            l         = YAHOO.lang;        /**         * REQUIRED. Number of records constituting a &quot;page&quot;         * @attribute rowsPerPage         * @type integer         */        this.setAttributeConfig('rowsPerPage', {            value     : 0,            validator : l.isNumber        });        /**         * REQUIRED. Node references or ids of nodes in which to render the         * pagination controls.         * @attribute containers         * @type {string|HTMLElement|Array(string|HTMLElement)}         */        this.setAttributeConfig('containers', {            value     : null,            validator : function (val) {                if (!l.isArray(val)) {                    val = [val];                }                for (var i = 0, len = val.length; i < len; ++i) {                    if (l.isString(val[i]) ||                         (l.isObject(val[i]) && val[i].nodeType === 1)) {                        continue;                    }                    return false;                }                return true;            },            method : function (val) {                val = YAHOO.util.Dom.get(val);                if (!l.isArray(val)) {                    val = [val];                }                this._containers = val;            }        });        /**         * Total number of records to paginate through         * @attribute totalRecords         * @type integer         * @default 0         */        this.setAttributeConfig('totalRecords', {            value     : 0,            validator : l.isNumber        });        /**         * Zero based index of the record considered first on the current page.         * For page based interactions, don't modify this attribute directly;         * use setPage(n).         * @attribute recordOffset         * @type integer         * @default 0         */        this.setAttributeConfig('recordOffset', {            value     : 0,            validator : function (val) {                var total = this.get('totalRecords');                if (l.isNumber(val)) {                    return total === UNLIMITED || total > val ||                           (total === 0 && val === 0);                }                return false;            }        });        /**         * Page to display on initial paint         * @attribute initialPage         * @type integer         * @default 1         */        this.setAttributeConfig('initialPage', {            value     : 1,            validator : l.isNumber        });        /**         * Template used to render controls.  The string will be used as         * innerHTML on all specified container nodes.  Bracketed keys         * (e.g. {pageLinks}) in the string will be replaced with an instance         * of the so named ui component.         * @see Paginator.TEMPLATE_DEFAULT         * @see Paginator.TEMPLATE_ROWS_PER_PAGE         * @attribute template         * @type string         */        this.setAttributeConfig('template', {            value : YAHOO.widget.Paginator.TEMPLATE_DEFAULT,            validator : l.isString        });        /**         * Class assigned to the element(s) containing pagination controls.         * @attribute containerClass         * @type string         * @default 'yui-pg-container'         */        this.setAttributeConfig('containerClass', {            value : 'yui-pg-container',            validator : l.isString        });        /**         * Display pagination controls even when there is only one page.  Set         * to false to forgo rendering and/or hide the containers when there         * is only one page of data.  Note if you are using the rowsPerPage         * dropdown ui component, visibility will be maintained as long as the         * number of records exceeds the smallest page size.         * @attribute alwaysVisible         * @type boolean         * @default true         */        this.setAttributeConfig('alwaysVisible', {            value : true,            validator : l.isBoolean        });        /**         * Update the UI immediately upon interaction.  If false, changeRequest         * subscribers or other external code will need to explicitly set the         * new values in the paginator to trigger repaint.         * @attribute updateOnChange         * @type boolean         * @default false         */        this.setAttributeConfig('updateOnChange', {            value     : false,            validator : l.isBoolean        });        // Read only attributes        /**         * Unique id assigned to this instance         * @attribute id         * @type integer         * @final         */        this.setAttributeConfig('id', {            value    : YAHOO.widget.Paginator.id++,            readOnly : true        });        /**         * Indicator of whether the DOM nodes have been initially created         * @attribute rendered         * @type boolean         * @final         */        this.setAttributeConfig('rendered', {            value    : false,            readOnly : true        });    },    /**     * Initialize registered ui components onto this instance.     * @method initUIComponents     * @private     */    initUIComponents : function () {        var ui = YAHOO.widget.Paginator.ui,            name,UIComp;        for (name in ui) {            if (YAHOO.lang.hasOwnProperty(ui,name)) {                UIComp = ui[name];                if (YAHOO.lang.isObject(UIComp) &&                    YAHOO.lang.isFunction(UIComp.init)) {                    UIComp.init(this);                }            }        }    },    /**     * Initialize this instance's CustomEvents.     * @method initEvents     * @private     */    initEvents : function () {        this.createEvent('recordOffsetChange');        this.createEvent('totalRecordsChange');        this.createEvent('rowsPerPageChange');        this.createEvent('alwaysVisibleChange');        /**         * Event fired when the Paginator is initially rendered         * @event render         */        this.createEvent('render');        /**         * Event fired when the Paginator is initially rendered         * @event rendered         * @deprecated use render event         */        this.createEvent('rendered'); // backward compatibility        /**         * Event fired when a change in pagination values is requested,         * either by interacting with the various ui components or via the         * setStartIndex(n) etc APIs.         * Subscribers will receive the proposed state as the first parameter.         * The proposed state object will contain the following keys:         * <ul>         *   <li>paginator - the Paginator instance</li>         *   <li>page</li>         *   <li>totalRecords</li>         *   <li>recordOffset - index of the first record on the new page</li>         *   <li>rowsPerPage</li>         *   <li>records - array containing [start index, end index] for the records on the new page</li>         *   <li>before - object literal with all these keys for the current state</li>         * </ul>         * @event changeRequest         */        this.createEvent('changeRequest');        /**         * Event fired when attribute changes have resulted in the calculated         * current page changing.         * @event pageChange         */        this.createEvent('pageChange');        /**         * Event that fires before the destroy event.         * @event beforeDestroy         */        this.createEvent('beforeDestroy');        /**         * Event used to trigger cleanup of ui components         * @event destroy         */        this.createEvent('destroy');        this._selfSubscribe();    },    /**     * Subscribes to instance attribute change events to automate certain     * behaviors.     * @method _selfSubscribe     * @protected     */    _selfSubscribe : function () {

⌨️ 快捷键说明

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