Roo/bootstrap/Pagination.js
[roojs1] / Roo / bootstrap / Pagination.js
1 /*
2  * - LGPL
3  *
4  * pagination
5  * 
6  */
7
8 /**
9  * @class Roo.bootstrap.Pagination
10  * @extends Roo.bootstrap.Component
11  * Bootstrap Pagination class
12  * @cfg {String} size xs | sm | md | lg
13  * @cfg {Boolean} inverse false | true
14  * @cfg {Number} from pagination starting number
15  * @cfg {Number} to pagination ending number
16  * @cfg {String} align empty or left | right
17  * @cfg {Number} active active page number
18  * 
19  * @constructor
20  * Create a new Pagination
21  * @param {Object} config The config object
22  */
23
24 Roo.bootstrap.Pagination = function(config){
25     Roo.bootstrap.Pagination.superclass.constructor.call(this, config);
26 };
27
28 Roo.extend(Roo.bootstrap.Pagination, Roo.bootstrap.Component,  {
29     
30     cls: false,
31     size: false,
32     inverse: false,
33     from: 1,
34     to: 4,
35     align: false,
36     active: 1,
37     
38     getAutoCreate : function(){
39         var cfg = {
40             tag: 'ul',
41                 cls: 'pagination',
42                 cn: []
43         };
44         if (this.inverse) {
45             cfg.cls += ' inverse';
46         }
47         if (this.html) {
48             cfg.html=this.html;
49         }
50         if (this.cls) {
51             cfg.cls=this.cls;
52         }
53         cfg.cn[0]={
54             tag: 'li',
55             cn: [
56                 {
57                     tag: 'a',
58                     cls: 'previous',
59                     href:'#',
60                     html: '«'
61                 }
62             ]
63         };
64         var from=this.from>0?this.from:1;
65         var to=this.to-from<=10?this.to:from+10;
66         var active=this.active>=from&&this.active<=to?this.active:null;
67         for (var i=from;i<=to;i++) {
68             cfg.cn.push(
69                 {
70                     tag: 'li',
71                     cls: active===i?'active':'',
72                     cn: [
73                         {
74                             tag: 'a',
75                             href: '#',
76                             html: i
77                         }
78                     ]
79                 }
80             );
81         }
82         
83         cfg.cn.push(
84             {
85                 tag: 'li',
86                 cn: [
87                     {
88                        tag: 'a',
89                        cls: 'next',
90                        href: '#',
91                        html: '&raquo;'
92                     }
93                 ]
94             }
95         );
96         
97         return cfg;
98     }
99    
100 });
101
102  
103
104