📄 paginator-debug.js
字号:
this.fireEvent('changeRequest', this.getState({'recordOffset':offset})); } } }, /** * Get an object literal describing the current state of the paginator. If * an object literal of proposed values is passed, the proposed state will * be returned as an object literal with the following keys: * <ul> * <li>paginator - instance of the Paginator</li> * <li>page - number</li> * <li>totalRecords - number</li> * <li>recordOffset - number</li> * <li>rowsPerPage - number</li> * <li>records - [ start_index, end_index ]</li> * <li>before - (OPTIONAL) { state object literal for current state }</li> * </ul> * @method getState * @return {object} * @param changes {object} OPTIONAL object literal with proposed values * Supported change keys include: * <ul> * <li>rowsPerPage</li> * <li>totalRecords</li> * <li>recordOffset OR</li> * <li>page</li> * </ul> */ getState : function (changes) { var UNLIMITED = YAHOO.widget.Paginator.VALUE_UNLIMITED, l = YAHOO.lang, M = Math, min = M.min, max = M.max, floor = M.floor, ceil = M.ceil, currentState, state, offset; function normalizeOffset(offset,total,rpp) { if (offset <= 0 || total === 0) { return 0; } if (total === UNLIMITED || total > offset) { return offset - (offset % rpp); } return total - (total % rpp || rpp); } currentState = { paginator : this, totalRecords : this.get('totalRecords'), rowsPerPage : this.get('rowsPerPage'), records : this.getPageRecords() }; currentState.recordOffset = normalizeOffset( this.get('recordOffset'), currentState.totalRecords, currentState.rowsPerPage); currentState.page = ceil(currentState.recordOffset / currentState.rowsPerPage) + 1; if (!changes) { return currentState; } state = { paginator : this, before : currentState, rowsPerPage : changes.rowsPerPage || currentState.rowsPerPage, totalRecords : (l.isNumber(changes.totalRecords) ? max(changes.totalRecords,UNLIMITED) : currentState.totalRecords) }; if (state.totalRecords === 0) { state.recordOffset = state.page = 0; } else { offset = l.isNumber(changes.page) ? (changes.page - 1) * state.rowsPerPage : l.isNumber(changes.recordOffset) ? changes.recordOffset : currentState.recordOffset; state.recordOffset = normalizeOffset(offset, state.totalRecords, state.rowsPerPage); state.page = ceil(state.recordOffset / state.rowsPerPage) + 1; } state.records = [ state.recordOffset, state.recordOffset + state.rowsPerPage - 1 ]; // limit upper index to totalRecords - 1 if (state.totalRecords !== UNLIMITED && state.recordOffset < state.totalRecords && state.records && state.records[1] > state.totalRecords - 1) { state.records[1] = state.totalRecords - 1; } return state; }, /** * Convenience method to facilitate setting state attributes rowsPerPage, * totalRecords, recordOffset in batch. Also supports calculating * recordOffset from state.page if state.recordOffset is not provided. * Fires only a single pageChange event, if appropriate. * This will not fire a changeRequest event. * @method setState * @param state {Object} Object literal of attribute:value pairs to set */ setState : function (state) { if (YAHOO.lang.isObject(state)) { // get flux state based on current state with before state as well this._state = this.getState({}); // use just the state props from the input obj state = { page : state.page, rowsPerPage : state.rowsPerPage, totalRecords : state.totalRecords, recordOffset : state.recordOffset }; // calculate recordOffset from page if recordOffset not specified. // not using lang.isNumber for support of numeric strings if (state.page && state.recordOffset === undefined) { state.recordOffset = (state.page - 1) * (state.rowsPerPage || this.get('rowsPerPage')); } this._batch = true; this._pageChanged = false; for (var k in state) { if (state.hasOwnProperty(k)) { this.set(k,state[k]); } } this._batch = false; if (this._pageChanged) { this._pageChanged = false; this._firePageChange(this.getState(this._state)); } } }};YAHOO.lang.augmentProto(YAHOO.widget.Paginator, YAHOO.util.AttributeProvider);(function () {var Paginator = YAHOO.widget.Paginator, l = YAHOO.lang;/** * ui Component to generate the textual report of current pagination status. * E.g. "Now viewing page 1 of 13". * * @namespace YAHOO.widget.Paginator.ui * @class CurrentPageReport * @for YAHOO.widget.Paginator * * @constructor * @param p {Pagintor} Paginator instance to attach to */Paginator.ui.CurrentPageReport = function (p) { this.paginator = p; p.createEvent('pageReportClassChange'); p.createEvent('pageReportTemplateChange'); p.subscribe('recordOffsetChange', this.update,this,true); p.subscribe('rowsPerPageChange', this.update,this,true); p.subscribe('totalRecordsChange',this.update,this,true); p.subscribe('pageReportTemplateChange', this.update,this,true); p.subscribe('destroy',this.destroy,this,true); //TODO: make this work p.subscribe('pageReportClassChange', this.update,this,true);};/** * Decorates Paginator instances with new attributes. Called during * Paginator instantiation. * @method init * @param p {Paginator} Paginator instance to decorate * @static */Paginator.ui.CurrentPageReport.init = function (p) { /** * CSS class assigned to the span containing the info. * @attribute pageReportClass * @default 'yui-pg-current' */ p.setAttributeConfig('pageReportClass', { value : 'yui-pg-current', validator : l.isString }); /** * Used as innerHTML for the span. Place holders in the form of {name} * will be replaced with the so named value from the key:value map * generated by the function held in the pageReportValueGenerator attribute. * @attribute pageReportTemplate * @default '({currentPage} of {totalPages})' * @see pageReportValueGenerator attribute */ p.setAttributeConfig('pageReportTemplate', { value : '({currentPage} of {totalPages})', validator : l.isString }); /** * Function to generate the value map used to populate the * pageReportTemplate. The function is passed the Paginator instance as a * parameter. The default function returns a map with the following keys: * <ul> * <li>currentPage</li> * <li>totalPages</li> * <li>startIndex</li> * <li>endIndex</li> * <li>startRecord</li> * <li>endRecord</li> * <li>totalRecords</li> * </ul> * @attribute pageReportValueGenarator */ p.setAttributeConfig('pageReportValueGenerator', { value : function (paginator) { var curPage = paginator.getCurrentPage(), records = paginator.getPageRecords(); return { 'currentPage' : records ? curPage : 0, 'totalPages' : paginator.getTotalPages(), 'startIndex' : records ? records[0] : 0, 'endIndex' : records ? records[1] : 0, 'startRecord' : records ? records[0] + 1 : 0, 'endRecord' : records ? records[1] + 1 : 0, 'totalRecords': paginator.get('totalRecords') }; }, validator : l.isFunction });};/** * Replace place holders in a string with the named values found in an * object literal. * @static * @method sprintf * @param template {string} The content string containing place holders * @param values {object} The key:value pairs used to replace the place holders * @return {string} */Paginator.ui.CurrentPageReport.sprintf = function (template, values) { return template.replace(/\{([\w\s\-]+)\}/g, function (x,key) { return (key in values) ? values[key] : ''; });};Paginator.ui.CurrentPageReport.prototype = { /** * Span node containing the formatted info * @property span * @type HTMLElement * @private */ span : null, /** * Generate the span containing info formatted per the pageReportTemplate * attribute. * @method render * @param id_base {string} used to create unique ids for generated nodes * @return {HTMLElement} */ render : function (id_base) { this.span = document.createElement('span'); this.span.id = id_base + '-page-report'; this.span.className = this.paginator.get('pageReportClass'); this.update(); return this.span; }, /** * Regenerate the content of the span if appropriate. Calls * CurrentPageReport.sprintf with the value of the pageReportTemplate * attribute and the value map returned from pageReportValueGenerator * function. * @method update * @param e {CustomEvent} The calling change event */ update : function (e) { if (e && e.prevValue === e.newValue) { return; } this.span.innerHTML = Paginator.ui.CurrentPageReport.sprintf( this.paginator.get('pageReportTemplate'), this.paginator.get('pageReportValueGenerator')(this.paginator)); }, /** * Removes the link/span node and clears event listeners * removal. * @method destroy * @private */ destroy : function () { this.span.parentNode.removeChild(this.span); this.span = null; }};})();(function () {var Paginator = YAHOO.widget.Paginator, l = YAHOO.lang;/** * ui Component to generate the page links * * @namespace YAHOO.widget.Paginator.ui * @class PageLinks * @for YAHOO.widget.Paginator * * @constructor * @param p {Pagintor} Paginator instance to attach to */Paginator.ui.PageLinks = function (p) { this.paginator = p; p.createEvent('pageLinkClassChange'); p.createEvent('currentPageClassChange'); p.createEvent('pageLinksContainerClassChange'); p.createEvent('pageLinksChange'); p.subscribe('recordOffsetChange',this.update,this,true); p.subscribe('rowsPerPageChange',this.update,this,true); p.subscribe('totalRecordsChange',this.update,this,true); p.subscribe('pageLinksChange', this.rebuild,this,true); p.subscribe('pageLinkClassChange', this.rebuild,this,true); p.subscribe('currentPageClassChange', this.rebuild,this,true); p.subscribe('destroy',this.destroy,this,true); //TODO: Make this work p.subscribe('pageLinksContainerClassChange', this.rebuild,this,true);};/** * Decorates Paginator instances with new attributes. Called during * Paginator instantiation. * @method init * @param p {Paginator} Paginator instance to decorate * @static */Paginator.ui.PageLinks.init = function (p) { /** * CSS class assigned to each page link/span. * @attribute pageLinkClass * @default 'yui-pg-page' */ p.setAttributeConfig('pageLinkClass', { value : 'yui-pg-page', validator : l.isString }); /** * CSS class assigned to the current page span. * @attribute currentPageClass * @default 'yui-pg-current-page' */ p.setAttributeConfig('currentPageClass', { value : 'yui-pg-current-page', validator : l.isString }); /** * CSS class assigned to the span containing the page links. * @attribute pageLinksContainerClass * @default 'yui-pg-pages' */ p.setAttributeConfig('pageLinksContainerClass', { value : 'yui-pg-pages', validator : l.isString }); /** * Maximum number of page links to display at one time. * @attribute pageLinks * @default 10 */ p.setAttributeConfig('pageLinks', { value : 10, validator : l.isNumber }); /** * Function used generate the innerHTML for each page link/span. The * function receives as parameters the page number and a reference to the * paginator object. * @attribute pageLabelBuilder * @default function (page, paginator) { return page; } */ p.setAttributeConfig('pageLabelBuilder', { value : function (page, paginator) { return page; }, validator : l.isFunction });};/** * Calculates start and end page numbers given a current page, attempting * to keep the current page in the middle * @static * @method calculateRange * @param {int} currentPage The current page * @param {int} totalPages (optional) Maximum number of pages * @param {int} numPages (optional) Preferred number of pages in range * @return {Array} [start_page_number, end_page_number] */Paginator.ui.PageLinks.calculateRange = function (currentPage,totalPages,numPages) { var UNLIMITED = Paginator.VALUE_UNLIMITED, start, end, delta; // Either has no pages, or unlimited pages. Show none.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -