2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
8 YUI.add('paginator-core', function (Y, NAME) {
11 Paginator's core functionality consists of keeping track of the current page
12 being displayed and providing information for previous and next pages.
15 @submodule paginator-core
20 _API docs for this extension are included in the Paginator class._
22 Class extension providing the core API and structure for the Paginator module.
24 Use this class extension with Widget or another Base-based superclass to
25 create the basic Paginator model API and composing class structure.
32 var PaginatorCore = Y.namespace('Paginator').Core = function () {};
34 PaginatorCore.ATTRS = {
36 Current page count. First page is 1.
47 Total number of pages to display
55 getter: '_getTotalPagesFn'
59 Maximum number of items per page. A value of negative one (-1) indicates
60 all items on one page.
62 @attribute itemsPerPage
71 Total number of items in all pages.
82 Y.mix(PaginatorCore.prototype, {
84 Sets the page to the previous page in the set, if there is a previous page.
88 prevPage: function () {
89 if (this.hasPrevPage()) {
90 this.set('page', this.get('page') - 1);
97 Sets the page to the next page in the set, if there is a next page.
102 nextPage: function () {
103 if (this.hasNextPage()) {
104 this.set('page', this.get('page') + 1);
111 Returns True if there is a previous page in the set.
114 @return {Boolean} `true` if there is a previous page, `false` otherwise.
116 hasPrevPage: function () {
117 return this.get('page') > 1;
121 Returns True if there is a next page in the set.
123 If totalItems isn't set, assume there is always next page.
126 @return {Boolean} `true` if there is a next page, `false` otherwise.
128 hasNextPage: function () {
129 return (!this.get('totalItems') || this.get('page') < this.get('totalPages'));
133 //--- P R O T E C T E D
136 Returns the total number of pages based on the total number of
137 items provided and the number of items per page
140 @method _getTotalPagesFn
141 @return {Number} Total number of pages based on total number of items and
142 items per page or one if itemsPerPage is less than one
144 _getTotalPagesFn: function () {
145 var itemsPerPage = this.get('itemsPerPage');
147 return (itemsPerPage < 1) ? 1 : Math.ceil(this.get('totalItems') / itemsPerPage);
153 }, '3.13.0', {"requires": ["base"]});