Upgrade to ExtJS 3.2.1 - Released 04/27/2010
[extjs.git] / examples / ux / SlidingPager.js
1 /*!
2  * Ext JS Library 3.2.1
3  * Copyright(c) 2006-2010 Ext JS, Inc.
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 /**
8  * Plugin for PagingToolbar which replaces the textfield input with a slider 
9  */
10 Ext.ux.SlidingPager = Ext.extend(Object, {
11     init : function(pbar){
12         var idx = pbar.items.indexOf(pbar.inputItem);
13         Ext.each(pbar.items.getRange(idx - 2, idx + 2), function(c){
14             c.hide();
15         });
16         var slider = new Ext.Slider({
17             width: 114,
18             minValue: 1,
19             maxValue: 1,
20             plugins: new Ext.slider.Tip({
21                 getText : function(thumb) {
22                     return String.format('Page <b>{0}</b> of <b>{1}</b>', thumb.value, thumb.slider.maxValue);
23                 }
24             }),
25             listeners: {
26                 changecomplete: function(s, v){
27                     pbar.changePage(v);
28                 }
29             }
30         });
31         pbar.insert(idx + 1, slider);
32         pbar.on({
33             change: function(pb, data){
34                 slider.setMaxValue(data.pages);
35                 slider.setValue(data.activePage);
36             }
37         });
38     }
39 });