import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
/*
|
||||
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
|
||||
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
|
||||
Code licensed under the BSD License:
|
||||
http://developer.yahoo.net/yui/license.txt
|
||||
version: 2.6.0
|
||||
version: 2.7.0
|
||||
*/
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
|
||||
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
|
||||
Code licensed under the BSD License:
|
||||
http://developer.yahoo.net/yui/license.txt
|
||||
version: 2.6.0
|
||||
version: 2.7.0
|
||||
*/
|
||||
.yui-skin-sam .yui-pg-container {
|
||||
display: block;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
|
||||
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
|
||||
Code licensed under the BSD License:
|
||||
http://developer.yahoo.net/yui/license.txt
|
||||
version: 2.6.0
|
||||
version: 2.7.0
|
||||
*/
|
||||
.yui-skin-sam .yui-pg-container{display:block;margin:6px 0;white-space:nowrap;}.yui-skin-sam .yui-pg-first,.yui-skin-sam .yui-pg-previous,.yui-skin-sam .yui-pg-next,.yui-skin-sam .yui-pg-last,.yui-skin-sam .yui-pg-current,.yui-skin-sam .yui-pg-pages,.yui-skin-sam .yui-pg-page{display:inline-block;font-family:arial,helvetica,clean,sans-serif;padding:3px 6px;zoom:1;}.yui-skin-sam .yui-pg-pages{padding:0;}.yui-skin-sam .yui-pg-current{padding:3px 0;}.yui-skin-sam a.yui-pg-first:link,.yui-skin-sam a.yui-pg-first:visited,.yui-skin-sam a.yui-pg-first:active,.yui-skin-sam a.yui-pg-first:hover,.yui-skin-sam a.yui-pg-previous:link,.yui-skin-sam a.yui-pg-previous:visited,.yui-skin-sam a.yui-pg-previous:active,.yui-skin-sam a.yui-pg-previous:hover,.yui-skin-sam a.yui-pg-next:link,.yui-skin-sam a.yui-pg-next:visited,.yui-skin-sam a.yui-pg-next:active,.yui-skin-sam a.yui-pg-next:hover,.yui-skin-sam a.yui-pg-last:link,.yui-skin-sam a.yui-pg-last:visited,.yui-skin-sam a.yui-pg-last:active,.yui-skin-sam a.yui-pg-last:hover,.yui-skin-sam a.yui-pg-page:link,.yui-skin-sam a.yui-pg-page:visited,.yui-skin-sam a.yui-pg-page:active,.yui-skin-sam a.yui-pg-page:hover{color:#06c;text-decoration:underline;outline:0;}.yui-skin-sam span.yui-pg-first,.yui-skin-sam span.yui-pg-previous,.yui-skin-sam span.yui-pg-next,.yui-skin-sam span.yui-pg-last{color:#a6a6a6;}.yui-skin-sam .yui-pg-page{background-color:#fff;border:1px solid #CBCBCB;padding:2px 6px;text-decoration:none;}.yui-skin-sam .yui-pg-current-page{background-color:transparent;border:none;font-weight:bold;padding:3px 6px;}.yui-skin-sam .yui-pg-page{margin-left:1px;margin-right:1px;}.yui-skin-sam .yui-pg-first,.yui-skin-sam .yui-pg-previous{padding-left:0;}.yui-skin-sam .yui-pg-next,.yui-skin-sam .yui-pg-last{padding-right:0;}.yui-skin-sam .yui-pg-current,.yui-skin-sam .yui-pg-rpp-options{margin-left:1em;margin-right:1em;}
|
||||
|
337
webdir/javascript/yui/paginator/paginator-debug.js
vendored
337
webdir/javascript/yui/paginator/paginator-debug.js
vendored
@ -1,9 +1,10 @@
|
||||
/*
|
||||
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
|
||||
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
|
||||
Code licensed under the BSD License:
|
||||
http://developer.yahoo.net/yui/license.txt
|
||||
version: 2.6.0
|
||||
version: 2.7.0
|
||||
*/
|
||||
(function () {
|
||||
/**
|
||||
* The Paginator widget provides a set of controls to navigate through paged
|
||||
* data.
|
||||
@ -28,10 +29,10 @@ version: 2.6.0
|
||||
* @param config {Object} Object literal to set instance and ui component
|
||||
* configuration.
|
||||
*/
|
||||
YAHOO.widget.Paginator = function (config) {
|
||||
var UNLIMITED = YAHOO.widget.Paginator.VALUE_UNLIMITED,
|
||||
function Paginator(config) {
|
||||
var UNLIMITED = Paginator.VALUE_UNLIMITED,
|
||||
lang = YAHOO.lang,
|
||||
attrib, initialPage, records, perPage;
|
||||
attrib, initialPage, records, perPage, startIndex;
|
||||
|
||||
config = lang.isObject(config) ? config : {};
|
||||
|
||||
@ -41,7 +42,7 @@ YAHOO.widget.Paginator = function (config) {
|
||||
|
||||
// Set the basic config keys first
|
||||
this.set('rowsPerPage',config.rowsPerPage,true);
|
||||
if (lang.isNumber(config.totalRecords)) {
|
||||
if (Paginator.isNumeric(config.totalRecords)) {
|
||||
this.set('totalRecords',config.totalRecords,true);
|
||||
}
|
||||
|
||||
@ -59,16 +60,16 @@ YAHOO.widget.Paginator = function (config) {
|
||||
records = this.get('totalRecords');
|
||||
perPage = this.get('rowsPerPage');
|
||||
if (initialPage > 1 && perPage !== UNLIMITED) {
|
||||
var startIndex = (initialPage - 1) * perPage;
|
||||
startIndex = (initialPage - 1) * perPage;
|
||||
if (records === UNLIMITED || startIndex < records) {
|
||||
this.set('recordOffset',startIndex,true);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// Static members
|
||||
YAHOO.lang.augmentObject(YAHOO.widget.Paginator, {
|
||||
YAHOO.lang.augmentObject(Paginator, {
|
||||
/**
|
||||
* Incrementing index used to give instances unique ids.
|
||||
* @static
|
||||
@ -121,13 +122,39 @@ YAHOO.lang.augmentObject(YAHOO.widget.Paginator, {
|
||||
* @static
|
||||
* @property ui
|
||||
*/
|
||||
ui : {}
|
||||
ui : {},
|
||||
|
||||
/**
|
||||
* Similar to YAHOO.lang.isNumber, but allows numeric strings. This is
|
||||
* is used for attribute validation in conjunction with getters that return
|
||||
* numbers.
|
||||
*
|
||||
* @method isNumeric
|
||||
* @param v {Number|String} value to be checked for number or numeric string
|
||||
* @returns {Boolean} true if the input is coercable into a finite number
|
||||
* @static
|
||||
*/
|
||||
isNumeric : function (v) {
|
||||
return isFinite(+v);
|
||||
},
|
||||
|
||||
/**
|
||||
* Return a number or null from input
|
||||
*
|
||||
* @method toNumber
|
||||
* @param n {Number|String} a number or numeric string
|
||||
* @return Number
|
||||
* @static
|
||||
*/
|
||||
toNumber : function (n) {
|
||||
return isFinite(+n) ? +n : null;
|
||||
}
|
||||
|
||||
},true);
|
||||
|
||||
|
||||
// Instance members and methods
|
||||
YAHOO.widget.Paginator.prototype = {
|
||||
Paginator.prototype = {
|
||||
|
||||
// Instance members
|
||||
|
||||
@ -176,7 +203,7 @@ YAHOO.widget.Paginator.prototype = {
|
||||
*/
|
||||
initConfig : function () {
|
||||
|
||||
var UNLIMITED = YAHOO.widget.Paginator.VALUE_UNLIMITED,
|
||||
var UNLIMITED = Paginator.VALUE_UNLIMITED,
|
||||
l = YAHOO.lang;
|
||||
|
||||
/**
|
||||
@ -186,7 +213,8 @@ YAHOO.widget.Paginator.prototype = {
|
||||
*/
|
||||
this.setAttributeConfig('rowsPerPage', {
|
||||
value : 0,
|
||||
validator : l.isNumber
|
||||
validator : Paginator.isNumeric,
|
||||
setter : Paginator.toNumber
|
||||
});
|
||||
|
||||
/**
|
||||
@ -227,7 +255,8 @@ YAHOO.widget.Paginator.prototype = {
|
||||
*/
|
||||
this.setAttributeConfig('totalRecords', {
|
||||
value : 0,
|
||||
validator : l.isNumber
|
||||
validator : Paginator.isNumeric,
|
||||
setter : Paginator.toNumber
|
||||
});
|
||||
|
||||
/**
|
||||
@ -242,13 +271,15 @@ YAHOO.widget.Paginator.prototype = {
|
||||
value : 0,
|
||||
validator : function (val) {
|
||||
var total = this.get('totalRecords');
|
||||
if (l.isNumber(val)) {
|
||||
if (Paginator.isNumeric(val)) {
|
||||
val = +val;
|
||||
return total === UNLIMITED || total > val ||
|
||||
(total === 0 && val === 0);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
},
|
||||
setter : Paginator.toNumber
|
||||
});
|
||||
|
||||
/**
|
||||
@ -259,7 +290,8 @@ YAHOO.widget.Paginator.prototype = {
|
||||
*/
|
||||
this.setAttributeConfig('initialPage', {
|
||||
value : 1,
|
||||
validator : l.isNumber
|
||||
validator : Paginator.isNumeric,
|
||||
setter : Paginator.toNumber
|
||||
});
|
||||
|
||||
/**
|
||||
@ -273,7 +305,7 @@ YAHOO.widget.Paginator.prototype = {
|
||||
* @type string
|
||||
*/
|
||||
this.setAttributeConfig('template', {
|
||||
value : YAHOO.widget.Paginator.TEMPLATE_DEFAULT,
|
||||
value : Paginator.TEMPLATE_DEFAULT,
|
||||
validator : l.isString
|
||||
});
|
||||
|
||||
@ -327,7 +359,7 @@ YAHOO.widget.Paginator.prototype = {
|
||||
* @final
|
||||
*/
|
||||
this.setAttributeConfig('id', {
|
||||
value : YAHOO.widget.Paginator.id++,
|
||||
value : Paginator.id++,
|
||||
readOnly : true
|
||||
});
|
||||
|
||||
@ -350,7 +382,7 @@ YAHOO.widget.Paginator.prototype = {
|
||||
* @private
|
||||
*/
|
||||
initUIComponents : function () {
|
||||
var ui = YAHOO.widget.Paginator.ui,
|
||||
var ui = Paginator.ui,
|
||||
name,UIComp;
|
||||
for (name in ui) {
|
||||
if (YAHOO.lang.hasOwnProperty(ui,name)) {
|
||||
@ -369,11 +401,6 @@ YAHOO.widget.Paginator.prototype = {
|
||||
* @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
|
||||
@ -458,7 +485,7 @@ YAHOO.widget.Paginator.prototype = {
|
||||
_syncRecordOffset : function (e) {
|
||||
var v = e.newValue,rpp,state;
|
||||
if (e.prevValue !== v) {
|
||||
if (v !== YAHOO.widget.Paginator.VALUE_UNLIMITED) {
|
||||
if (v !== Paginator.VALUE_UNLIMITED) {
|
||||
rpp = this.get('rowsPerPage');
|
||||
|
||||
if (rpp && this.get('recordOffset') >= v) {
|
||||
@ -531,26 +558,26 @@ YAHOO.widget.Paginator.prototype = {
|
||||
}
|
||||
|
||||
// Forgo rendering if only one page and alwaysVisible is off
|
||||
var totalRecords = this.get('totalRecords');
|
||||
if (totalRecords !== YAHOO.widget.Paginator.VALUE_UNLIMITED &&
|
||||
var totalRecords = this.get('totalRecords'),
|
||||
Dom = YAHOO.util.Dom,
|
||||
template = this.get('template'),
|
||||
containerClass = this.get('containerClass'),
|
||||
i,len,c,id_base,markers,j,jlen,m,mp,name,UIComp,comp;
|
||||
|
||||
if (totalRecords !== Paginator.VALUE_UNLIMITED &&
|
||||
totalRecords < this.get('rowsPerPage') &&
|
||||
!this.get('alwaysVisible')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var Dom = YAHOO.util.Dom,
|
||||
template = this.get('template'),
|
||||
containerClass = this.get('containerClass');
|
||||
|
||||
// add marker spans to the template html to indicate drop zones
|
||||
// for ui components
|
||||
template = template.replace(/\{([a-z0-9_ \-]+)\}/gi,
|
||||
'<span class="yui-pg-ui $1"></span>');
|
||||
for (var i = 0, len = this._containers.length; i < len; ++i) {
|
||||
var c = this._containers[i],
|
||||
// ex. yui-pg0-1 (first paginator, second container)
|
||||
id_base = YAHOO.widget.Paginator.ID_BASE + this.get('id') +
|
||||
'-' + i;
|
||||
for (i = 0, len = this._containers.length; i < len; ++i) {
|
||||
c = this._containers[i];
|
||||
// ex. yui-pg0-1 (first paginator, second container)
|
||||
id_base = Paginator.ID_BASE + this.get('id') + '-' + i;
|
||||
|
||||
if (!c) {
|
||||
continue;
|
||||
@ -564,16 +591,16 @@ YAHOO.widget.Paginator.prototype = {
|
||||
c.innerHTML = template;
|
||||
|
||||
// Replace each marker with the ui component's render() output
|
||||
var markers = Dom.getElementsByClassName('yui-pg-ui','span',c);
|
||||
markers = Dom.getElementsByClassName('yui-pg-ui','span',c);
|
||||
|
||||
for (var j = 0, jlen = markers.length; j < jlen; ++j) {
|
||||
var m = markers[j],
|
||||
mp = m.parentNode,
|
||||
name = m.className.replace(/\s*yui-pg-ui\s+/g,''),
|
||||
UIComp = YAHOO.widget.Paginator.ui[name];
|
||||
for (j = 0, jlen = markers.length; j < jlen; ++j) {
|
||||
m = markers[j];
|
||||
mp = m.parentNode;
|
||||
name = m.className.replace(/\s*yui-pg-ui\s+/g,'');
|
||||
UIComp = Paginator.ui[name];
|
||||
|
||||
if (YAHOO.lang.isFunction(UIComp)) {
|
||||
var comp = new UIComp(this);
|
||||
comp = new UIComp(this);
|
||||
if (YAHOO.lang.isFunction(comp.render)) {
|
||||
mp.replaceChild(comp.render(id_base),m);
|
||||
}
|
||||
@ -612,13 +639,14 @@ YAHOO.widget.Paginator.prototype = {
|
||||
* @method updateVisibility
|
||||
*/
|
||||
updateVisibility : function (e) {
|
||||
var alwaysVisible = this.get('alwaysVisible');
|
||||
var alwaysVisible = this.get('alwaysVisible'),
|
||||
totalRecords,visible,rpp,rppOptions,i,len;
|
||||
|
||||
if (e.type === 'alwaysVisibleChange' || !alwaysVisible) {
|
||||
var totalRecords = this.get('totalRecords'),
|
||||
visible = true,
|
||||
rpp = this.get('rowsPerPage'),
|
||||
rppOptions = this.get('rowsPerPageOptions'),
|
||||
i,len;
|
||||
totalRecords = this.get('totalRecords');
|
||||
visible = true;
|
||||
rpp = this.get('rowsPerPage');
|
||||
rppOptions = this.get('rowsPerPageOptions');
|
||||
|
||||
if (YAHOO.lang.isArray(rppOptions)) {
|
||||
for (i = 0, len = rppOptions.length; i < len; ++i) {
|
||||
@ -626,7 +654,7 @@ YAHOO.widget.Paginator.prototype = {
|
||||
}
|
||||
}
|
||||
|
||||
if (totalRecords !== YAHOO.widget.Paginator.VALUE_UNLIMITED &&
|
||||
if (totalRecords !== Paginator.VALUE_UNLIMITED &&
|
||||
totalRecords <= rpp) {
|
||||
visible = false;
|
||||
}
|
||||
@ -661,16 +689,16 @@ YAHOO.widget.Paginator.prototype = {
|
||||
* @return {number}
|
||||
*/
|
||||
getTotalPages : function () {
|
||||
var records = this.get('totalRecords');
|
||||
var perPage = this.get('rowsPerPage');
|
||||
var records = this.get('totalRecords'),
|
||||
perPage = this.get('rowsPerPage');
|
||||
|
||||
// rowsPerPage not set. Can't calculate
|
||||
if (!perPage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (records === YAHOO.widget.Paginator.VALUE_UNLIMITED) {
|
||||
return YAHOO.widget.Paginator.VALUE_UNLIMITED;
|
||||
if (records === Paginator.VALUE_UNLIMITED) {
|
||||
return Paginator.VALUE_UNLIMITED;
|
||||
}
|
||||
|
||||
return Math.ceil(records/perPage);
|
||||
@ -689,7 +717,7 @@ YAHOO.widget.Paginator.prototype = {
|
||||
|
||||
var totalPages = this.getTotalPages();
|
||||
|
||||
return (totalPages === YAHOO.widget.Paginator.VALUE_UNLIMITED || totalPages >= page);
|
||||
return (totalPages === Paginator.VALUE_UNLIMITED || totalPages >= page);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -714,7 +742,7 @@ YAHOO.widget.Paginator.prototype = {
|
||||
var currentPage = this.getCurrentPage(),
|
||||
totalPages = this.getTotalPages();
|
||||
|
||||
return currentPage && (totalPages === YAHOO.widget.Paginator.VALUE_UNLIMITED || currentPage < totalPages);
|
||||
return currentPage && (totalPages === Paginator.VALUE_UNLIMITED || currentPage < totalPages);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -766,7 +794,7 @@ YAHOO.widget.Paginator.prototype = {
|
||||
}
|
||||
|
||||
start = (page - 1) * perPage;
|
||||
if (records !== YAHOO.widget.Paginator.VALUE_UNLIMITED) {
|
||||
if (records !== Paginator.VALUE_UNLIMITED) {
|
||||
if (start >= records) {
|
||||
return null;
|
||||
}
|
||||
@ -812,13 +840,13 @@ YAHOO.widget.Paginator.prototype = {
|
||||
* changeRequest event
|
||||
*/
|
||||
setRowsPerPage : function (rpp,silent) {
|
||||
if (YAHOO.lang.isNumber(rpp) && rpp > 0 &&
|
||||
rpp !== this.get('rowsPerPage')) {
|
||||
if (Paginator.isNumeric(rpp) && +rpp > 0 &&
|
||||
+rpp !== this.get('rowsPerPage')) {
|
||||
if (this.get('updateOnChange') || silent) {
|
||||
this.set('rowsPerPage',rpp);
|
||||
} else {
|
||||
this.fireEvent('changeRequest',
|
||||
this.getState({'rowsPerPage':rpp}));
|
||||
this.getState({'rowsPerPage':+rpp}));
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -839,13 +867,13 @@ YAHOO.widget.Paginator.prototype = {
|
||||
* @param silent {boolean} whether to forcibly avoid firing the changeRequest event
|
||||
*/
|
||||
setTotalRecords : function (total,silent) {
|
||||
if (YAHOO.lang.isNumber(total) && total >= 0 &&
|
||||
total !== this.get('totalRecords')) {
|
||||
if (Paginator.isNumeric(total) && +total >= 0 &&
|
||||
+total !== this.get('totalRecords')) {
|
||||
if (this.get('updateOnChange') || silent) {
|
||||
this.set('totalRecords',total);
|
||||
} else {
|
||||
this.fireEvent('changeRequest',
|
||||
this.getState({'totalRecords':total}));
|
||||
this.getState({'totalRecords':+total}));
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -867,13 +895,13 @@ YAHOO.widget.Paginator.prototype = {
|
||||
* @param silent {boolean} whether to forcibly avoid firing the changeRequest event
|
||||
*/
|
||||
setStartIndex : function (offset,silent) {
|
||||
if (YAHOO.lang.isNumber(offset) && offset >= 0 &&
|
||||
offset !== this.get('recordOffset')) {
|
||||
if (Paginator.isNumeric(offset) && +offset >= 0 &&
|
||||
+offset !== this.get('recordOffset')) {
|
||||
if (this.get('updateOnChange') || silent) {
|
||||
this.set('recordOffset',offset);
|
||||
} else {
|
||||
this.fireEvent('changeRequest',
|
||||
this.getState({'recordOffset':offset}));
|
||||
this.getState({'recordOffset':+offset}));
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -903,9 +931,8 @@ YAHOO.widget.Paginator.prototype = {
|
||||
* </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,
|
||||
var UNLIMITED = Paginator.VALUE_UNLIMITED,
|
||||
M = Math, max = M.max, ceil = M.ceil,
|
||||
currentState, state, offset;
|
||||
|
||||
function normalizeOffset(offset,total,rpp) {
|
||||
@ -940,19 +967,19 @@ YAHOO.widget.Paginator.prototype = {
|
||||
before : currentState,
|
||||
|
||||
rowsPerPage : changes.rowsPerPage || currentState.rowsPerPage,
|
||||
totalRecords : (l.isNumber(changes.totalRecords) ?
|
||||
totalRecords : (Paginator.isNumeric(changes.totalRecords) ?
|
||||
max(changes.totalRecords,UNLIMITED) :
|
||||
currentState.totalRecords)
|
||||
+currentState.totalRecords)
|
||||
};
|
||||
|
||||
if (state.totalRecords === 0) {
|
||||
state.recordOffset =
|
||||
state.page = 0;
|
||||
} else {
|
||||
offset = l.isNumber(changes.page) ?
|
||||
offset = Paginator.isNumeric(changes.page) ?
|
||||
(changes.page - 1) * state.rowsPerPage :
|
||||
l.isNumber(changes.recordOffset) ?
|
||||
changes.recordOffset :
|
||||
Paginator.isNumeric(changes.recordOffset) ?
|
||||
+changes.recordOffset :
|
||||
currentState.recordOffset;
|
||||
|
||||
state.recordOffset = normalizeOffset(offset,
|
||||
@ -1024,7 +1051,10 @@ YAHOO.widget.Paginator.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
YAHOO.lang.augmentProto(YAHOO.widget.Paginator, YAHOO.util.AttributeProvider);
|
||||
YAHOO.lang.augmentProto(Paginator, YAHOO.util.AttributeProvider);
|
||||
|
||||
YAHOO.widget.Paginator = Paginator;
|
||||
})();
|
||||
(function () {
|
||||
|
||||
var Paginator = YAHOO.widget.Paginator,
|
||||
@ -1044,9 +1074,6 @@ var Paginator = YAHOO.widget.Paginator,
|
||||
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);
|
||||
@ -1215,11 +1242,6 @@ var Paginator = YAHOO.widget.Paginator,
|
||||
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);
|
||||
@ -1278,7 +1300,7 @@ Paginator.ui.PageLinks.init = function (p) {
|
||||
*/
|
||||
p.setAttributeConfig('pageLinks', {
|
||||
value : 10,
|
||||
validator : l.isNumber
|
||||
validator : Paginator.isNumeric
|
||||
});
|
||||
|
||||
/**
|
||||
@ -1481,9 +1503,6 @@ var Paginator = YAHOO.widget.Paginator,
|
||||
Paginator.ui.FirstPageLink = function (p) {
|
||||
this.paginator = p;
|
||||
|
||||
p.createEvent('firstPageLinkLabelChange');
|
||||
p.createEvent('firstPageLinkClassChange');
|
||||
|
||||
p.subscribe('recordOffsetChange',this.update,this,true);
|
||||
p.subscribe('rowsPerPageChange',this.update,this,true);
|
||||
p.subscribe('totalRecordsChange',this.update,this,true);
|
||||
@ -1576,7 +1595,7 @@ Paginator.ui.FirstPageLink.prototype = {
|
||||
this.span.className = c;
|
||||
this.span.innerHTML = label;
|
||||
|
||||
this.current = p.get('recordOffset') < 1 ? this.span : this.link;
|
||||
this.current = p.getCurrentPage() > 1 ? this.link : this.span;
|
||||
return this.current;
|
||||
},
|
||||
|
||||
@ -1591,16 +1610,16 @@ Paginator.ui.FirstPageLink.prototype = {
|
||||
}
|
||||
|
||||
var par = this.current ? this.current.parentNode : null;
|
||||
if (this.paginator.get('recordOffset') < 1) {
|
||||
if (par && this.current === this.link) {
|
||||
par.replaceChild(this.span,this.current);
|
||||
this.current = this.span;
|
||||
}
|
||||
} else {
|
||||
if (this.paginator.getCurrentPage() > 1) {
|
||||
if (par && this.current === this.span) {
|
||||
par.replaceChild(this.link,this.current);
|
||||
this.current = this.link;
|
||||
}
|
||||
} else {
|
||||
if (par && this.current === this.link) {
|
||||
par.replaceChild(this.span,this.current);
|
||||
this.current = this.span;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -1646,9 +1665,6 @@ var Paginator = YAHOO.widget.Paginator,
|
||||
Paginator.ui.LastPageLink = function (p) {
|
||||
this.paginator = p;
|
||||
|
||||
p.createEvent('lastPageLinkLabelChange');
|
||||
p.createEvent('lastPageLinkClassChange');
|
||||
|
||||
p.subscribe('recordOffsetChange',this.update,this,true);
|
||||
p.subscribe('rowsPerPageChange',this.update,this,true);
|
||||
p.subscribe('totalRecordsChange',this.update,this,true);
|
||||
@ -1835,9 +1851,6 @@ var Paginator = YAHOO.widget.Paginator,
|
||||
Paginator.ui.NextPageLink = function (p) {
|
||||
this.paginator = p;
|
||||
|
||||
p.createEvent('nextPageLinkLabelChange');
|
||||
p.createEvent('nextPageLinkClassChange');
|
||||
|
||||
p.subscribe('recordOffsetChange', this.update,this,true);
|
||||
p.subscribe('rowsPerPageChange', this.update,this,true);
|
||||
p.subscribe('totalRecordsChange', this.update,this,true);
|
||||
@ -2003,9 +2016,6 @@ var Paginator = YAHOO.widget.Paginator,
|
||||
Paginator.ui.PreviousPageLink = function (p) {
|
||||
this.paginator = p;
|
||||
|
||||
p.createEvent('previousPageLinkLabelChange');
|
||||
p.createEvent('previousPageLinkClassChange');
|
||||
|
||||
p.subscribe('recordOffsetChange',this.update,this,true);
|
||||
p.subscribe('rowsPerPageChange',this.update,this,true);
|
||||
p.subscribe('totalRecordsChange',this.update,this,true);
|
||||
@ -2098,7 +2108,7 @@ Paginator.ui.PreviousPageLink.prototype = {
|
||||
this.span.className = c;
|
||||
this.span.innerHTML = label;
|
||||
|
||||
this.current = p.get('recordOffset') < 1 ? this.span : this.link;
|
||||
this.current = p.getCurrentPage() > 1 ? this.link : this.span;
|
||||
return this.current;
|
||||
},
|
||||
|
||||
@ -2113,16 +2123,16 @@ Paginator.ui.PreviousPageLink.prototype = {
|
||||
}
|
||||
|
||||
var par = this.current ? this.current.parentNode : null;
|
||||
if (this.paginator.get('recordOffset') < 1) {
|
||||
if (par && this.current === this.link) {
|
||||
par.replaceChild(this.span,this.current);
|
||||
this.current = this.span;
|
||||
}
|
||||
} else {
|
||||
if (this.paginator.getCurrentPage() > 1) {
|
||||
if (par && this.current === this.span) {
|
||||
par.replaceChild(this.link,this.current);
|
||||
this.current = this.link;
|
||||
}
|
||||
} else {
|
||||
if (par && this.current === this.link) {
|
||||
par.replaceChild(this.span,this.current);
|
||||
this.current = this.span;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -2167,11 +2177,9 @@ var Paginator = YAHOO.widget.Paginator,
|
||||
Paginator.ui.RowsPerPageDropdown = function (p) {
|
||||
this.paginator = p;
|
||||
|
||||
p.createEvent('rowsPerPageOptionsChange');
|
||||
p.createEvent('rowsPerPageDropdownClassChange');
|
||||
|
||||
p.subscribe('rowsPerPageChange',this.update,this,true);
|
||||
p.subscribe('rowsPerPageOptionsChange',this.rebuild,this,true);
|
||||
p.subscribe('totalRecordsChange',this._handleTotalRecordsChange,this,true);
|
||||
p.subscribe('destroy',this.destroy,this,true);
|
||||
|
||||
// TODO: make this work
|
||||
@ -2221,6 +2229,15 @@ Paginator.ui.RowsPerPageDropdown.prototype = {
|
||||
select : null,
|
||||
|
||||
|
||||
/**
|
||||
* option node for the optional All value
|
||||
*
|
||||
* @property all
|
||||
* @type HTMLElement
|
||||
* @protected
|
||||
*/
|
||||
all : null,
|
||||
|
||||
/**
|
||||
* Generate the select and option nodes and returns the select node.
|
||||
* @method render
|
||||
@ -2240,6 +2257,41 @@ Paginator.ui.RowsPerPageDropdown.prototype = {
|
||||
return this.select;
|
||||
},
|
||||
|
||||
/**
|
||||
* (Re)generate the select options.
|
||||
* @method rebuild
|
||||
*/
|
||||
rebuild : function (e) {
|
||||
var p = this.paginator,
|
||||
sel = this.select,
|
||||
options = p.get('rowsPerPageOptions'),
|
||||
opt,cfg,val,i,len;
|
||||
|
||||
this.all = null;
|
||||
|
||||
for (i = 0, len = options.length; i < len; ++i) {
|
||||
cfg = options[i];
|
||||
opt = sel.options[i] ||
|
||||
sel.appendChild(document.createElement('option'));
|
||||
val = l.isValue(cfg.value) ? cfg.value : cfg;
|
||||
opt.innerHTML = l.isValue(cfg.text) ? cfg.text : cfg;
|
||||
|
||||
if (l.isString(val) && val.toLowerCase() === 'all') {
|
||||
this.all = opt;
|
||||
opt.value = p.get('totalRecords');
|
||||
} else{
|
||||
opt.value = val;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
while (sel.options.length > options.length) {
|
||||
sel.removeChild(sel.firstChild);
|
||||
}
|
||||
|
||||
this.update();
|
||||
},
|
||||
|
||||
/**
|
||||
* Select the appropriate option if changed.
|
||||
* @method update
|
||||
@ -2250,42 +2302,45 @@ Paginator.ui.RowsPerPageDropdown.prototype = {
|
||||
return;
|
||||
}
|
||||
|
||||
var rpp = this.paginator.get('rowsPerPage'),
|
||||
var rpp = this.paginator.get('rowsPerPage')+'',
|
||||
options = this.select.options,
|
||||
i,len;
|
||||
|
||||
for (i = 0, len = options.length; i < len; ++i) {
|
||||
if (parseInt(options[i].value,10) === rpp) {
|
||||
if (options[i].value === rpp) {
|
||||
options[i].selected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Listener for the select's onchange event. Sent to setRowsPerPage method.
|
||||
* @method onChange
|
||||
* @param e {DOMEvent} The change event
|
||||
*/
|
||||
onChange : function (e) {
|
||||
this.paginator.setRowsPerPage(
|
||||
parseInt(this.select.options[this.select.selectedIndex].value,10));
|
||||
},
|
||||
|
||||
/**
|
||||
* (Re)generate the select options.
|
||||
* @method rebuild
|
||||
* Updates the all option value (and Paginator's rowsPerPage attribute if
|
||||
* necessary) in response to a change in the Paginator's totalRecords.
|
||||
*
|
||||
* @method _handleTotalRecordsChange
|
||||
* @param e {Event} attribute change event
|
||||
* @protected
|
||||
*/
|
||||
rebuild : function (e) {
|
||||
var p = this.paginator,
|
||||
sel = this.select,
|
||||
options = p.get('rowsPerPageOptions'),
|
||||
opt_tem = document.createElement('option'),
|
||||
i,len;
|
||||
|
||||
while (sel.firstChild) {
|
||||
sel.removeChild(sel.firstChild);
|
||||
_handleTotalRecordsChange : function (e) {
|
||||
if (!this.all || (e && e.prevValue === e.newValue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0, len = options.length; i < len; ++i) {
|
||||
var node = opt_tem.cloneNode(false),
|
||||
opt = options[i];
|
||||
node.value = l.isValue(opt.value) ? opt.value : opt;
|
||||
node.innerHTML = l.isValue(opt.text) ? opt.text : opt;
|
||||
sel.appendChild(node);
|
||||
this.all.value = e.newValue;
|
||||
if (this.all.selected) {
|
||||
this.paginator.set('rowsPerPage',e.newValue);
|
||||
}
|
||||
|
||||
this.update();
|
||||
},
|
||||
|
||||
/**
|
||||
@ -2297,18 +2352,8 @@ Paginator.ui.RowsPerPageDropdown.prototype = {
|
||||
YAHOO.util.Event.purgeElement(this.select);
|
||||
this.select.parentNode.removeChild(this.select);
|
||||
this.select = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Listener for the select's onchange event. Sent to setRowsPerPage method.
|
||||
* @method onChange
|
||||
* @param e {DOMEvent} The change event
|
||||
*/
|
||||
onChange : function (e) {
|
||||
this.paginator.setRowsPerPage(
|
||||
parseInt(this.select.options[this.select.selectedIndex].value,10));
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
YAHOO.register("paginator", YAHOO.widget.Paginator, {version: "2.6.0", build: "1321"});
|
||||
YAHOO.register("paginator", YAHOO.widget.Paginator, {version: "2.7.0", build: "1799"});
|
||||
|
12
webdir/javascript/yui/paginator/paginator-min.js
vendored
12
webdir/javascript/yui/paginator/paginator-min.js
vendored
File diff suppressed because one or more lines are too long
337
webdir/javascript/yui/paginator/paginator.js
vendored
337
webdir/javascript/yui/paginator/paginator.js
vendored
@ -1,9 +1,10 @@
|
||||
/*
|
||||
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
|
||||
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
|
||||
Code licensed under the BSD License:
|
||||
http://developer.yahoo.net/yui/license.txt
|
||||
version: 2.6.0
|
||||
version: 2.7.0
|
||||
*/
|
||||
(function () {
|
||||
/**
|
||||
* The Paginator widget provides a set of controls to navigate through paged
|
||||
* data.
|
||||
@ -28,10 +29,10 @@ version: 2.6.0
|
||||
* @param config {Object} Object literal to set instance and ui component
|
||||
* configuration.
|
||||
*/
|
||||
YAHOO.widget.Paginator = function (config) {
|
||||
var UNLIMITED = YAHOO.widget.Paginator.VALUE_UNLIMITED,
|
||||
function Paginator(config) {
|
||||
var UNLIMITED = Paginator.VALUE_UNLIMITED,
|
||||
lang = YAHOO.lang,
|
||||
attrib, initialPage, records, perPage;
|
||||
attrib, initialPage, records, perPage, startIndex;
|
||||
|
||||
config = lang.isObject(config) ? config : {};
|
||||
|
||||
@ -41,7 +42,7 @@ YAHOO.widget.Paginator = function (config) {
|
||||
|
||||
// Set the basic config keys first
|
||||
this.set('rowsPerPage',config.rowsPerPage,true);
|
||||
if (lang.isNumber(config.totalRecords)) {
|
||||
if (Paginator.isNumeric(config.totalRecords)) {
|
||||
this.set('totalRecords',config.totalRecords,true);
|
||||
}
|
||||
|
||||
@ -59,16 +60,16 @@ YAHOO.widget.Paginator = function (config) {
|
||||
records = this.get('totalRecords');
|
||||
perPage = this.get('rowsPerPage');
|
||||
if (initialPage > 1 && perPage !== UNLIMITED) {
|
||||
var startIndex = (initialPage - 1) * perPage;
|
||||
startIndex = (initialPage - 1) * perPage;
|
||||
if (records === UNLIMITED || startIndex < records) {
|
||||
this.set('recordOffset',startIndex,true);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// Static members
|
||||
YAHOO.lang.augmentObject(YAHOO.widget.Paginator, {
|
||||
YAHOO.lang.augmentObject(Paginator, {
|
||||
/**
|
||||
* Incrementing index used to give instances unique ids.
|
||||
* @static
|
||||
@ -121,13 +122,39 @@ YAHOO.lang.augmentObject(YAHOO.widget.Paginator, {
|
||||
* @static
|
||||
* @property ui
|
||||
*/
|
||||
ui : {}
|
||||
ui : {},
|
||||
|
||||
/**
|
||||
* Similar to YAHOO.lang.isNumber, but allows numeric strings. This is
|
||||
* is used for attribute validation in conjunction with getters that return
|
||||
* numbers.
|
||||
*
|
||||
* @method isNumeric
|
||||
* @param v {Number|String} value to be checked for number or numeric string
|
||||
* @returns {Boolean} true if the input is coercable into a finite number
|
||||
* @static
|
||||
*/
|
||||
isNumeric : function (v) {
|
||||
return isFinite(+v);
|
||||
},
|
||||
|
||||
/**
|
||||
* Return a number or null from input
|
||||
*
|
||||
* @method toNumber
|
||||
* @param n {Number|String} a number or numeric string
|
||||
* @return Number
|
||||
* @static
|
||||
*/
|
||||
toNumber : function (n) {
|
||||
return isFinite(+n) ? +n : null;
|
||||
}
|
||||
|
||||
},true);
|
||||
|
||||
|
||||
// Instance members and methods
|
||||
YAHOO.widget.Paginator.prototype = {
|
||||
Paginator.prototype = {
|
||||
|
||||
// Instance members
|
||||
|
||||
@ -176,7 +203,7 @@ YAHOO.widget.Paginator.prototype = {
|
||||
*/
|
||||
initConfig : function () {
|
||||
|
||||
var UNLIMITED = YAHOO.widget.Paginator.VALUE_UNLIMITED,
|
||||
var UNLIMITED = Paginator.VALUE_UNLIMITED,
|
||||
l = YAHOO.lang;
|
||||
|
||||
/**
|
||||
@ -186,7 +213,8 @@ YAHOO.widget.Paginator.prototype = {
|
||||
*/
|
||||
this.setAttributeConfig('rowsPerPage', {
|
||||
value : 0,
|
||||
validator : l.isNumber
|
||||
validator : Paginator.isNumeric,
|
||||
setter : Paginator.toNumber
|
||||
});
|
||||
|
||||
/**
|
||||
@ -227,7 +255,8 @@ YAHOO.widget.Paginator.prototype = {
|
||||
*/
|
||||
this.setAttributeConfig('totalRecords', {
|
||||
value : 0,
|
||||
validator : l.isNumber
|
||||
validator : Paginator.isNumeric,
|
||||
setter : Paginator.toNumber
|
||||
});
|
||||
|
||||
/**
|
||||
@ -242,13 +271,15 @@ YAHOO.widget.Paginator.prototype = {
|
||||
value : 0,
|
||||
validator : function (val) {
|
||||
var total = this.get('totalRecords');
|
||||
if (l.isNumber(val)) {
|
||||
if (Paginator.isNumeric(val)) {
|
||||
val = +val;
|
||||
return total === UNLIMITED || total > val ||
|
||||
(total === 0 && val === 0);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
},
|
||||
setter : Paginator.toNumber
|
||||
});
|
||||
|
||||
/**
|
||||
@ -259,7 +290,8 @@ YAHOO.widget.Paginator.prototype = {
|
||||
*/
|
||||
this.setAttributeConfig('initialPage', {
|
||||
value : 1,
|
||||
validator : l.isNumber
|
||||
validator : Paginator.isNumeric,
|
||||
setter : Paginator.toNumber
|
||||
});
|
||||
|
||||
/**
|
||||
@ -273,7 +305,7 @@ YAHOO.widget.Paginator.prototype = {
|
||||
* @type string
|
||||
*/
|
||||
this.setAttributeConfig('template', {
|
||||
value : YAHOO.widget.Paginator.TEMPLATE_DEFAULT,
|
||||
value : Paginator.TEMPLATE_DEFAULT,
|
||||
validator : l.isString
|
||||
});
|
||||
|
||||
@ -327,7 +359,7 @@ YAHOO.widget.Paginator.prototype = {
|
||||
* @final
|
||||
*/
|
||||
this.setAttributeConfig('id', {
|
||||
value : YAHOO.widget.Paginator.id++,
|
||||
value : Paginator.id++,
|
||||
readOnly : true
|
||||
});
|
||||
|
||||
@ -350,7 +382,7 @@ YAHOO.widget.Paginator.prototype = {
|
||||
* @private
|
||||
*/
|
||||
initUIComponents : function () {
|
||||
var ui = YAHOO.widget.Paginator.ui,
|
||||
var ui = Paginator.ui,
|
||||
name,UIComp;
|
||||
for (name in ui) {
|
||||
if (YAHOO.lang.hasOwnProperty(ui,name)) {
|
||||
@ -369,11 +401,6 @@ YAHOO.widget.Paginator.prototype = {
|
||||
* @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
|
||||
@ -458,7 +485,7 @@ YAHOO.widget.Paginator.prototype = {
|
||||
_syncRecordOffset : function (e) {
|
||||
var v = e.newValue,rpp,state;
|
||||
if (e.prevValue !== v) {
|
||||
if (v !== YAHOO.widget.Paginator.VALUE_UNLIMITED) {
|
||||
if (v !== Paginator.VALUE_UNLIMITED) {
|
||||
rpp = this.get('rowsPerPage');
|
||||
|
||||
if (rpp && this.get('recordOffset') >= v) {
|
||||
@ -531,26 +558,26 @@ YAHOO.widget.Paginator.prototype = {
|
||||
}
|
||||
|
||||
// Forgo rendering if only one page and alwaysVisible is off
|
||||
var totalRecords = this.get('totalRecords');
|
||||
if (totalRecords !== YAHOO.widget.Paginator.VALUE_UNLIMITED &&
|
||||
var totalRecords = this.get('totalRecords'),
|
||||
Dom = YAHOO.util.Dom,
|
||||
template = this.get('template'),
|
||||
containerClass = this.get('containerClass'),
|
||||
i,len,c,id_base,markers,j,jlen,m,mp,name,UIComp,comp;
|
||||
|
||||
if (totalRecords !== Paginator.VALUE_UNLIMITED &&
|
||||
totalRecords < this.get('rowsPerPage') &&
|
||||
!this.get('alwaysVisible')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var Dom = YAHOO.util.Dom,
|
||||
template = this.get('template'),
|
||||
containerClass = this.get('containerClass');
|
||||
|
||||
// add marker spans to the template html to indicate drop zones
|
||||
// for ui components
|
||||
template = template.replace(/\{([a-z0-9_ \-]+)\}/gi,
|
||||
'<span class="yui-pg-ui $1"></span>');
|
||||
for (var i = 0, len = this._containers.length; i < len; ++i) {
|
||||
var c = this._containers[i],
|
||||
// ex. yui-pg0-1 (first paginator, second container)
|
||||
id_base = YAHOO.widget.Paginator.ID_BASE + this.get('id') +
|
||||
'-' + i;
|
||||
for (i = 0, len = this._containers.length; i < len; ++i) {
|
||||
c = this._containers[i];
|
||||
// ex. yui-pg0-1 (first paginator, second container)
|
||||
id_base = Paginator.ID_BASE + this.get('id') + '-' + i;
|
||||
|
||||
if (!c) {
|
||||
continue;
|
||||
@ -564,16 +591,16 @@ YAHOO.widget.Paginator.prototype = {
|
||||
c.innerHTML = template;
|
||||
|
||||
// Replace each marker with the ui component's render() output
|
||||
var markers = Dom.getElementsByClassName('yui-pg-ui','span',c);
|
||||
markers = Dom.getElementsByClassName('yui-pg-ui','span',c);
|
||||
|
||||
for (var j = 0, jlen = markers.length; j < jlen; ++j) {
|
||||
var m = markers[j],
|
||||
mp = m.parentNode,
|
||||
name = m.className.replace(/\s*yui-pg-ui\s+/g,''),
|
||||
UIComp = YAHOO.widget.Paginator.ui[name];
|
||||
for (j = 0, jlen = markers.length; j < jlen; ++j) {
|
||||
m = markers[j];
|
||||
mp = m.parentNode;
|
||||
name = m.className.replace(/\s*yui-pg-ui\s+/g,'');
|
||||
UIComp = Paginator.ui[name];
|
||||
|
||||
if (YAHOO.lang.isFunction(UIComp)) {
|
||||
var comp = new UIComp(this);
|
||||
comp = new UIComp(this);
|
||||
if (YAHOO.lang.isFunction(comp.render)) {
|
||||
mp.replaceChild(comp.render(id_base),m);
|
||||
}
|
||||
@ -612,13 +639,14 @@ YAHOO.widget.Paginator.prototype = {
|
||||
* @method updateVisibility
|
||||
*/
|
||||
updateVisibility : function (e) {
|
||||
var alwaysVisible = this.get('alwaysVisible');
|
||||
var alwaysVisible = this.get('alwaysVisible'),
|
||||
totalRecords,visible,rpp,rppOptions,i,len;
|
||||
|
||||
if (e.type === 'alwaysVisibleChange' || !alwaysVisible) {
|
||||
var totalRecords = this.get('totalRecords'),
|
||||
visible = true,
|
||||
rpp = this.get('rowsPerPage'),
|
||||
rppOptions = this.get('rowsPerPageOptions'),
|
||||
i,len;
|
||||
totalRecords = this.get('totalRecords');
|
||||
visible = true;
|
||||
rpp = this.get('rowsPerPage');
|
||||
rppOptions = this.get('rowsPerPageOptions');
|
||||
|
||||
if (YAHOO.lang.isArray(rppOptions)) {
|
||||
for (i = 0, len = rppOptions.length; i < len; ++i) {
|
||||
@ -626,7 +654,7 @@ YAHOO.widget.Paginator.prototype = {
|
||||
}
|
||||
}
|
||||
|
||||
if (totalRecords !== YAHOO.widget.Paginator.VALUE_UNLIMITED &&
|
||||
if (totalRecords !== Paginator.VALUE_UNLIMITED &&
|
||||
totalRecords <= rpp) {
|
||||
visible = false;
|
||||
}
|
||||
@ -661,16 +689,16 @@ YAHOO.widget.Paginator.prototype = {
|
||||
* @return {number}
|
||||
*/
|
||||
getTotalPages : function () {
|
||||
var records = this.get('totalRecords');
|
||||
var perPage = this.get('rowsPerPage');
|
||||
var records = this.get('totalRecords'),
|
||||
perPage = this.get('rowsPerPage');
|
||||
|
||||
// rowsPerPage not set. Can't calculate
|
||||
if (!perPage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (records === YAHOO.widget.Paginator.VALUE_UNLIMITED) {
|
||||
return YAHOO.widget.Paginator.VALUE_UNLIMITED;
|
||||
if (records === Paginator.VALUE_UNLIMITED) {
|
||||
return Paginator.VALUE_UNLIMITED;
|
||||
}
|
||||
|
||||
return Math.ceil(records/perPage);
|
||||
@ -689,7 +717,7 @@ YAHOO.widget.Paginator.prototype = {
|
||||
|
||||
var totalPages = this.getTotalPages();
|
||||
|
||||
return (totalPages === YAHOO.widget.Paginator.VALUE_UNLIMITED || totalPages >= page);
|
||||
return (totalPages === Paginator.VALUE_UNLIMITED || totalPages >= page);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -714,7 +742,7 @@ YAHOO.widget.Paginator.prototype = {
|
||||
var currentPage = this.getCurrentPage(),
|
||||
totalPages = this.getTotalPages();
|
||||
|
||||
return currentPage && (totalPages === YAHOO.widget.Paginator.VALUE_UNLIMITED || currentPage < totalPages);
|
||||
return currentPage && (totalPages === Paginator.VALUE_UNLIMITED || currentPage < totalPages);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -766,7 +794,7 @@ YAHOO.widget.Paginator.prototype = {
|
||||
}
|
||||
|
||||
start = (page - 1) * perPage;
|
||||
if (records !== YAHOO.widget.Paginator.VALUE_UNLIMITED) {
|
||||
if (records !== Paginator.VALUE_UNLIMITED) {
|
||||
if (start >= records) {
|
||||
return null;
|
||||
}
|
||||
@ -812,13 +840,13 @@ YAHOO.widget.Paginator.prototype = {
|
||||
* changeRequest event
|
||||
*/
|
||||
setRowsPerPage : function (rpp,silent) {
|
||||
if (YAHOO.lang.isNumber(rpp) && rpp > 0 &&
|
||||
rpp !== this.get('rowsPerPage')) {
|
||||
if (Paginator.isNumeric(rpp) && +rpp > 0 &&
|
||||
+rpp !== this.get('rowsPerPage')) {
|
||||
if (this.get('updateOnChange') || silent) {
|
||||
this.set('rowsPerPage',rpp);
|
||||
} else {
|
||||
this.fireEvent('changeRequest',
|
||||
this.getState({'rowsPerPage':rpp}));
|
||||
this.getState({'rowsPerPage':+rpp}));
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -839,13 +867,13 @@ YAHOO.widget.Paginator.prototype = {
|
||||
* @param silent {boolean} whether to forcibly avoid firing the changeRequest event
|
||||
*/
|
||||
setTotalRecords : function (total,silent) {
|
||||
if (YAHOO.lang.isNumber(total) && total >= 0 &&
|
||||
total !== this.get('totalRecords')) {
|
||||
if (Paginator.isNumeric(total) && +total >= 0 &&
|
||||
+total !== this.get('totalRecords')) {
|
||||
if (this.get('updateOnChange') || silent) {
|
||||
this.set('totalRecords',total);
|
||||
} else {
|
||||
this.fireEvent('changeRequest',
|
||||
this.getState({'totalRecords':total}));
|
||||
this.getState({'totalRecords':+total}));
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -867,13 +895,13 @@ YAHOO.widget.Paginator.prototype = {
|
||||
* @param silent {boolean} whether to forcibly avoid firing the changeRequest event
|
||||
*/
|
||||
setStartIndex : function (offset,silent) {
|
||||
if (YAHOO.lang.isNumber(offset) && offset >= 0 &&
|
||||
offset !== this.get('recordOffset')) {
|
||||
if (Paginator.isNumeric(offset) && +offset >= 0 &&
|
||||
+offset !== this.get('recordOffset')) {
|
||||
if (this.get('updateOnChange') || silent) {
|
||||
this.set('recordOffset',offset);
|
||||
} else {
|
||||
this.fireEvent('changeRequest',
|
||||
this.getState({'recordOffset':offset}));
|
||||
this.getState({'recordOffset':+offset}));
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -903,9 +931,8 @@ YAHOO.widget.Paginator.prototype = {
|
||||
* </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,
|
||||
var UNLIMITED = Paginator.VALUE_UNLIMITED,
|
||||
M = Math, max = M.max, ceil = M.ceil,
|
||||
currentState, state, offset;
|
||||
|
||||
function normalizeOffset(offset,total,rpp) {
|
||||
@ -940,19 +967,19 @@ YAHOO.widget.Paginator.prototype = {
|
||||
before : currentState,
|
||||
|
||||
rowsPerPage : changes.rowsPerPage || currentState.rowsPerPage,
|
||||
totalRecords : (l.isNumber(changes.totalRecords) ?
|
||||
totalRecords : (Paginator.isNumeric(changes.totalRecords) ?
|
||||
max(changes.totalRecords,UNLIMITED) :
|
||||
currentState.totalRecords)
|
||||
+currentState.totalRecords)
|
||||
};
|
||||
|
||||
if (state.totalRecords === 0) {
|
||||
state.recordOffset =
|
||||
state.page = 0;
|
||||
} else {
|
||||
offset = l.isNumber(changes.page) ?
|
||||
offset = Paginator.isNumeric(changes.page) ?
|
||||
(changes.page - 1) * state.rowsPerPage :
|
||||
l.isNumber(changes.recordOffset) ?
|
||||
changes.recordOffset :
|
||||
Paginator.isNumeric(changes.recordOffset) ?
|
||||
+changes.recordOffset :
|
||||
currentState.recordOffset;
|
||||
|
||||
state.recordOffset = normalizeOffset(offset,
|
||||
@ -1024,7 +1051,10 @@ YAHOO.widget.Paginator.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
YAHOO.lang.augmentProto(YAHOO.widget.Paginator, YAHOO.util.AttributeProvider);
|
||||
YAHOO.lang.augmentProto(Paginator, YAHOO.util.AttributeProvider);
|
||||
|
||||
YAHOO.widget.Paginator = Paginator;
|
||||
})();
|
||||
(function () {
|
||||
|
||||
var Paginator = YAHOO.widget.Paginator,
|
||||
@ -1044,9 +1074,6 @@ var Paginator = YAHOO.widget.Paginator,
|
||||
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);
|
||||
@ -1215,11 +1242,6 @@ var Paginator = YAHOO.widget.Paginator,
|
||||
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);
|
||||
@ -1278,7 +1300,7 @@ Paginator.ui.PageLinks.init = function (p) {
|
||||
*/
|
||||
p.setAttributeConfig('pageLinks', {
|
||||
value : 10,
|
||||
validator : l.isNumber
|
||||
validator : Paginator.isNumeric
|
||||
});
|
||||
|
||||
/**
|
||||
@ -1481,9 +1503,6 @@ var Paginator = YAHOO.widget.Paginator,
|
||||
Paginator.ui.FirstPageLink = function (p) {
|
||||
this.paginator = p;
|
||||
|
||||
p.createEvent('firstPageLinkLabelChange');
|
||||
p.createEvent('firstPageLinkClassChange');
|
||||
|
||||
p.subscribe('recordOffsetChange',this.update,this,true);
|
||||
p.subscribe('rowsPerPageChange',this.update,this,true);
|
||||
p.subscribe('totalRecordsChange',this.update,this,true);
|
||||
@ -1576,7 +1595,7 @@ Paginator.ui.FirstPageLink.prototype = {
|
||||
this.span.className = c;
|
||||
this.span.innerHTML = label;
|
||||
|
||||
this.current = p.get('recordOffset') < 1 ? this.span : this.link;
|
||||
this.current = p.getCurrentPage() > 1 ? this.link : this.span;
|
||||
return this.current;
|
||||
},
|
||||
|
||||
@ -1591,16 +1610,16 @@ Paginator.ui.FirstPageLink.prototype = {
|
||||
}
|
||||
|
||||
var par = this.current ? this.current.parentNode : null;
|
||||
if (this.paginator.get('recordOffset') < 1) {
|
||||
if (par && this.current === this.link) {
|
||||
par.replaceChild(this.span,this.current);
|
||||
this.current = this.span;
|
||||
}
|
||||
} else {
|
||||
if (this.paginator.getCurrentPage() > 1) {
|
||||
if (par && this.current === this.span) {
|
||||
par.replaceChild(this.link,this.current);
|
||||
this.current = this.link;
|
||||
}
|
||||
} else {
|
||||
if (par && this.current === this.link) {
|
||||
par.replaceChild(this.span,this.current);
|
||||
this.current = this.span;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -1646,9 +1665,6 @@ var Paginator = YAHOO.widget.Paginator,
|
||||
Paginator.ui.LastPageLink = function (p) {
|
||||
this.paginator = p;
|
||||
|
||||
p.createEvent('lastPageLinkLabelChange');
|
||||
p.createEvent('lastPageLinkClassChange');
|
||||
|
||||
p.subscribe('recordOffsetChange',this.update,this,true);
|
||||
p.subscribe('rowsPerPageChange',this.update,this,true);
|
||||
p.subscribe('totalRecordsChange',this.update,this,true);
|
||||
@ -1835,9 +1851,6 @@ var Paginator = YAHOO.widget.Paginator,
|
||||
Paginator.ui.NextPageLink = function (p) {
|
||||
this.paginator = p;
|
||||
|
||||
p.createEvent('nextPageLinkLabelChange');
|
||||
p.createEvent('nextPageLinkClassChange');
|
||||
|
||||
p.subscribe('recordOffsetChange', this.update,this,true);
|
||||
p.subscribe('rowsPerPageChange', this.update,this,true);
|
||||
p.subscribe('totalRecordsChange', this.update,this,true);
|
||||
@ -2003,9 +2016,6 @@ var Paginator = YAHOO.widget.Paginator,
|
||||
Paginator.ui.PreviousPageLink = function (p) {
|
||||
this.paginator = p;
|
||||
|
||||
p.createEvent('previousPageLinkLabelChange');
|
||||
p.createEvent('previousPageLinkClassChange');
|
||||
|
||||
p.subscribe('recordOffsetChange',this.update,this,true);
|
||||
p.subscribe('rowsPerPageChange',this.update,this,true);
|
||||
p.subscribe('totalRecordsChange',this.update,this,true);
|
||||
@ -2098,7 +2108,7 @@ Paginator.ui.PreviousPageLink.prototype = {
|
||||
this.span.className = c;
|
||||
this.span.innerHTML = label;
|
||||
|
||||
this.current = p.get('recordOffset') < 1 ? this.span : this.link;
|
||||
this.current = p.getCurrentPage() > 1 ? this.link : this.span;
|
||||
return this.current;
|
||||
},
|
||||
|
||||
@ -2113,16 +2123,16 @@ Paginator.ui.PreviousPageLink.prototype = {
|
||||
}
|
||||
|
||||
var par = this.current ? this.current.parentNode : null;
|
||||
if (this.paginator.get('recordOffset') < 1) {
|
||||
if (par && this.current === this.link) {
|
||||
par.replaceChild(this.span,this.current);
|
||||
this.current = this.span;
|
||||
}
|
||||
} else {
|
||||
if (this.paginator.getCurrentPage() > 1) {
|
||||
if (par && this.current === this.span) {
|
||||
par.replaceChild(this.link,this.current);
|
||||
this.current = this.link;
|
||||
}
|
||||
} else {
|
||||
if (par && this.current === this.link) {
|
||||
par.replaceChild(this.span,this.current);
|
||||
this.current = this.span;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -2167,11 +2177,9 @@ var Paginator = YAHOO.widget.Paginator,
|
||||
Paginator.ui.RowsPerPageDropdown = function (p) {
|
||||
this.paginator = p;
|
||||
|
||||
p.createEvent('rowsPerPageOptionsChange');
|
||||
p.createEvent('rowsPerPageDropdownClassChange');
|
||||
|
||||
p.subscribe('rowsPerPageChange',this.update,this,true);
|
||||
p.subscribe('rowsPerPageOptionsChange',this.rebuild,this,true);
|
||||
p.subscribe('totalRecordsChange',this._handleTotalRecordsChange,this,true);
|
||||
p.subscribe('destroy',this.destroy,this,true);
|
||||
|
||||
// TODO: make this work
|
||||
@ -2221,6 +2229,15 @@ Paginator.ui.RowsPerPageDropdown.prototype = {
|
||||
select : null,
|
||||
|
||||
|
||||
/**
|
||||
* option node for the optional All value
|
||||
*
|
||||
* @property all
|
||||
* @type HTMLElement
|
||||
* @protected
|
||||
*/
|
||||
all : null,
|
||||
|
||||
/**
|
||||
* Generate the select and option nodes and returns the select node.
|
||||
* @method render
|
||||
@ -2240,6 +2257,41 @@ Paginator.ui.RowsPerPageDropdown.prototype = {
|
||||
return this.select;
|
||||
},
|
||||
|
||||
/**
|
||||
* (Re)generate the select options.
|
||||
* @method rebuild
|
||||
*/
|
||||
rebuild : function (e) {
|
||||
var p = this.paginator,
|
||||
sel = this.select,
|
||||
options = p.get('rowsPerPageOptions'),
|
||||
opt,cfg,val,i,len;
|
||||
|
||||
this.all = null;
|
||||
|
||||
for (i = 0, len = options.length; i < len; ++i) {
|
||||
cfg = options[i];
|
||||
opt = sel.options[i] ||
|
||||
sel.appendChild(document.createElement('option'));
|
||||
val = l.isValue(cfg.value) ? cfg.value : cfg;
|
||||
opt.innerHTML = l.isValue(cfg.text) ? cfg.text : cfg;
|
||||
|
||||
if (l.isString(val) && val.toLowerCase() === 'all') {
|
||||
this.all = opt;
|
||||
opt.value = p.get('totalRecords');
|
||||
} else{
|
||||
opt.value = val;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
while (sel.options.length > options.length) {
|
||||
sel.removeChild(sel.firstChild);
|
||||
}
|
||||
|
||||
this.update();
|
||||
},
|
||||
|
||||
/**
|
||||
* Select the appropriate option if changed.
|
||||
* @method update
|
||||
@ -2250,42 +2302,45 @@ Paginator.ui.RowsPerPageDropdown.prototype = {
|
||||
return;
|
||||
}
|
||||
|
||||
var rpp = this.paginator.get('rowsPerPage'),
|
||||
var rpp = this.paginator.get('rowsPerPage')+'',
|
||||
options = this.select.options,
|
||||
i,len;
|
||||
|
||||
for (i = 0, len = options.length; i < len; ++i) {
|
||||
if (parseInt(options[i].value,10) === rpp) {
|
||||
if (options[i].value === rpp) {
|
||||
options[i].selected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Listener for the select's onchange event. Sent to setRowsPerPage method.
|
||||
* @method onChange
|
||||
* @param e {DOMEvent} The change event
|
||||
*/
|
||||
onChange : function (e) {
|
||||
this.paginator.setRowsPerPage(
|
||||
parseInt(this.select.options[this.select.selectedIndex].value,10));
|
||||
},
|
||||
|
||||
/**
|
||||
* (Re)generate the select options.
|
||||
* @method rebuild
|
||||
* Updates the all option value (and Paginator's rowsPerPage attribute if
|
||||
* necessary) in response to a change in the Paginator's totalRecords.
|
||||
*
|
||||
* @method _handleTotalRecordsChange
|
||||
* @param e {Event} attribute change event
|
||||
* @protected
|
||||
*/
|
||||
rebuild : function (e) {
|
||||
var p = this.paginator,
|
||||
sel = this.select,
|
||||
options = p.get('rowsPerPageOptions'),
|
||||
opt_tem = document.createElement('option'),
|
||||
i,len;
|
||||
|
||||
while (sel.firstChild) {
|
||||
sel.removeChild(sel.firstChild);
|
||||
_handleTotalRecordsChange : function (e) {
|
||||
if (!this.all || (e && e.prevValue === e.newValue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0, len = options.length; i < len; ++i) {
|
||||
var node = opt_tem.cloneNode(false),
|
||||
opt = options[i];
|
||||
node.value = l.isValue(opt.value) ? opt.value : opt;
|
||||
node.innerHTML = l.isValue(opt.text) ? opt.text : opt;
|
||||
sel.appendChild(node);
|
||||
this.all.value = e.newValue;
|
||||
if (this.all.selected) {
|
||||
this.paginator.set('rowsPerPage',e.newValue);
|
||||
}
|
||||
|
||||
this.update();
|
||||
},
|
||||
|
||||
/**
|
||||
@ -2297,18 +2352,8 @@ Paginator.ui.RowsPerPageDropdown.prototype = {
|
||||
YAHOO.util.Event.purgeElement(this.select);
|
||||
this.select.parentNode.removeChild(this.select);
|
||||
this.select = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Listener for the select's onchange event. Sent to setRowsPerPage method.
|
||||
* @method onChange
|
||||
* @param e {DOMEvent} The change event
|
||||
*/
|
||||
onChange : function (e) {
|
||||
this.paginator.setRowsPerPage(
|
||||
parseInt(this.select.options[this.select.selectedIndex].value,10));
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
YAHOO.register("paginator", YAHOO.widget.Paginator, {version: "2.6.0", build: "1321"});
|
||||
YAHOO.register("paginator", YAHOO.widget.Paginator, {version: "2.7.0", build: "1799"});
|
||||
|
Reference in New Issue
Block a user