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