[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/yuilib/3.17.2/paginator-core/ -> paginator-core.js (source)

   1  /*
   2  YUI 3.17.2 (build 9c3c78e)
   3  Copyright 2014 Yahoo! Inc. All rights reserved.
   4  Licensed under the BSD License.
   5  http://yuilibrary.com/license/
   6  */
   7  
   8  YUI.add('paginator-core', function (Y, NAME) {
   9  
  10  /**
  11   Paginator's core functionality consists of keeping track of the current page
  12   being displayed and providing information for previous and next pages.
  13  
  14   @module paginator
  15   @submodule paginator-core
  16   @since 3.11.0
  17   */
  18  
  19  /**
  20   _API docs for this extension are included in the Paginator class._
  21  
  22   Class extension providing the core API and structure for the Paginator module.
  23  
  24   Use this class extension with Widget or another Base-based superclass to
  25   create the basic Paginator model API and composing class structure.
  26  
  27   @class Paginator.Core
  28   @for Paginator
  29   @since 3.11.0
  30   */
  31  
  32  var PaginatorCore = Y.namespace('Paginator').Core = function () {};
  33  
  34  PaginatorCore.ATTRS = {
  35      /**
  36       Current page count. First page is 1.
  37  
  38       @attribute page
  39       @type Number
  40       @default 1
  41       **/
  42      page: {
  43          value: 1
  44      },
  45  
  46      /**
  47       Total number of pages to display
  48  
  49       @readOnly
  50       @attribute totalPages
  51       @type Number
  52       **/
  53      totalPages: {
  54          readOnly: true,
  55          getter: '_getTotalPagesFn'
  56      },
  57  
  58      /**
  59       Maximum number of items per page. A value of negative one (-1) indicates
  60           all items on one page.
  61  
  62       @attribute itemsPerPage
  63       @type Number
  64       @default 10
  65       **/
  66      itemsPerPage: {
  67          value: 10
  68      },
  69  
  70      /**
  71       Total number of items in all pages.
  72  
  73       @attribute totalItems
  74       @type Number
  75       @default 0
  76       **/
  77      totalItems: {
  78          value: 0
  79      }
  80  };
  81  
  82  Y.mix(PaginatorCore.prototype, {
  83      /**
  84       Sets the page to the previous page in the set, if there is a previous page.
  85       @method prevPage
  86       @chainable
  87       */
  88      prevPage: function () {
  89          if (this.hasPrevPage()) {
  90              this.set('page', this.get('page') - 1);
  91          }
  92  
  93          return this;
  94      },
  95  
  96      /**
  97       Sets the page to the next page in the set, if there is a next page.
  98  
  99       @method nextPage
 100       @chainable
 101       */
 102      nextPage: function () {
 103          if (this.hasNextPage()) {
 104              this.set('page', this.get('page') + 1);
 105          }
 106  
 107          return this;
 108      },
 109  
 110      /**
 111       Returns True if there is a previous page in the set.
 112  
 113       @method hasPrevPage
 114       @return {Boolean} `true` if there is a previous page, `false` otherwise.
 115       */
 116      hasPrevPage: function () {
 117          return this.get('page') > 1;
 118      },
 119  
 120      /**
 121       Returns True if there is a next page in the set.
 122  
 123       If totalItems isn't set, assume there is always next page.
 124  
 125       @method hasNextPage
 126       @return {Boolean} `true` if there is a next page, `false` otherwise.
 127       */
 128      hasNextPage: function () {
 129          return (!this.get('totalItems') || this.get('page') < this.get('totalPages'));
 130      },
 131  
 132  
 133      //--- P R O T E C T E D
 134  
 135      /**
 136       Returns the total number of pages based on the total number of
 137         items provided and the number of items per page
 138  
 139       @protected
 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
 143       */
 144      _getTotalPagesFn: function () {
 145          var itemsPerPage = this.get('itemsPerPage');
 146  
 147          return (itemsPerPage < 1) ? 1 : Math.ceil(this.get('totalItems') / itemsPerPage);
 148      }
 149  });
 150  
 151  
 152  
 153  }, '3.17.2', {"requires": ["base"]});


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1