Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / examples / ux / SlidingPager.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16 * @class Ext.ux.SlidingPager
17 * @extends Object
18 * Plugin for PagingToolbar which replaces the textfield input with a slider
19 * @constructor
20 * Create a new ItemSelector
21 * @param {Object} config Configuration options
22 */
23 Ext.define('Ext.ux.SlidingPager', {
24     extend: 'Object',
25     requires: [
26         'Ext.slider.Single',
27         'Ext.slider.Tip'
28     ],
29
30     constructor : function(config) {
31         if (config) {
32             Ext.apply(this, config);
33         }
34     },
35
36     init : function(pbar){
37         var idx = pbar.items.indexOf(pbar.child("#inputItem")),
38             slider;
39
40         Ext.each(pbar.items.getRange(idx - 2, idx + 2), function(c){
41             c.hide();
42         });
43
44         slider = Ext.create('Ext.slider.Single', {
45             width: 114,
46             minValue: 1,
47             maxValue: 1,
48             hideLabel: true,
49             tipText: function(thumb) {
50                 return Ext.String.format('Page <b>{0}</b> of <b>{1}</b>', thumb.value, thumb.slider.maxValue);
51             },
52             listeners: {
53                 changecomplete: function(s, v){
54                     pbar.store.loadPage(v);
55                 }
56             }
57         });
58
59         pbar.insert(idx + 1, slider);
60
61         pbar.on({
62             change: function(pb, data){
63                 slider.setMaxValue(data.pageCount);
64                 slider.setValue(data.currentPage);
65             }
66         });
67     }
68 });
69