MDL-44361 Import YUI 3.15.0
[moodle.git] / lib / yuilib / 3.15.0 / paginator / paginator-debug.js
blob5ea729ec6ff2c9d6803775b34d6cc7b914014a66
1 /*
2 YUI 3.15.0 (build 834026e)
3 Copyright 2014 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
8 YUI.add('paginator', function (Y, NAME) {
10 /**
11  The Paginator utility allows you to display an item or a group of items
12  depending on the number of items you wish to display at one time.
14  Paginator's primary functionality is contained in `paginator-core` and is mixed
15  into `paginator` to allow `paginator` to have extra functionality added to it
16  while leaving the core functionality untouched. This allows `paginator-core` to
17  remain available for use later on or used in isolation if it is the only piece
18  you need.
20  Due to the vast number of interfaces a paginator could possibly consist of,
21  `Paginator` does not contain any ready to use UIs. However, `Paginator` is
22  ready to be used in any Based-based, module such as a Widget, by extending your
23  desired class and mixing in `Paginator`. This is displayed in the following
24  example:
26  <pre><code>
27  YUI().use('paginator-url', 'widget', function (Y){
28      var MyPaginator = Y.Base.create('my-paginator', Y.Widget, [Y.Paginator], {
30         renderUI: function () {
31             var numbers = '',
32                 i, numberOfPages = this.get('totalPages');
34             for (i = 1; i <= numberOfPages; i++) {
35                 // use paginator-url's formatUrl method
36                 numbers += '&lt;a href="' + this.formatUrl(i) + '">' + i + '&lt;/a>';
37             }
39             this.get('boundingBox').append(numbers);
40         },
42         bindUI: function () {
43             this.get('boundingBox').delegate('click', function (e) {
44                 // let's not go to the page, just update internally
45                 e.preventDefault();
46                 this.set('page', parseInt(e.currentTarget.getContent(), 10));
47             }, 'a', this);
49             this.after('pageChange', function (e) {
50                 // mark the link selected when it's the page being displayed
51                 var bb = this.get('boundingBox'),
52                     activeClass = 'selected';
54                 bb.all('a').removeClass(activeClass).item(e.newVal).addClass(activeClass);
55             });
56         }
58      });
60      var myPg = new MyPaginator({
61                     totalItems: 100,
62                     pageUrl: '?pg={page}'
63                 });
65      myPg.render();
66  });
67  </code></pre>
69  @module paginator
70  @main paginator
71  @class Paginator
72  @constructor
73  @since 3.11.0
74  */
76 Y.Paginator = Y.mix(
77     Y.Base.create('paginator', Y.Base, [Y.Paginator.Core]),
78     Y.Paginator
82 }, '3.15.0', {"requires": ["paginator-core"]});