SlidingPager.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. This file is part of Ext JS 4
  3. Copyright (c) 2011 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. 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.
  7. If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
  8. */
  9. /**
  10. * @class Ext.ux.SlidingPager
  11. * @extends Object
  12. * Plugin for PagingToolbar which replaces the textfield input with a slider
  13. * @constructor
  14. * Create a new ItemSelector
  15. * @param {Object} config Configuration options
  16. */
  17. Ext.define('Ext.ux.SlidingPager', {
  18. extend: 'Object',
  19. requires: [
  20. 'Ext.slider.Single',
  21. 'Ext.slider.Tip'
  22. ],
  23. constructor : function(config) {
  24. if (config) {
  25. Ext.apply(this, config);
  26. }
  27. },
  28. init : function(pbar){
  29. var idx = pbar.items.indexOf(pbar.child("#inputItem")),
  30. slider;
  31. Ext.each(pbar.items.getRange(idx - 2, idx + 2), function(c){
  32. c.hide();
  33. });
  34. slider = Ext.create('Ext.slider.Single', {
  35. width: 114,
  36. minValue: 1,
  37. maxValue: 1,
  38. hideLabel: true,
  39. tipText: function(thumb) {
  40. return Ext.String.format('Page <b>{0}</b> of <b>{1}</b>', thumb.value, thumb.slider.maxValue);
  41. },
  42. listeners: {
  43. changecomplete: function(s, v){
  44. pbar.store.loadPage(v);
  45. }
  46. }
  47. });
  48. pbar.insert(idx + 1, slider);
  49. pbar.on({
  50. change: function(pb, data){
  51. slider.setMaxValue(data.pageCount);
  52. slider.setValue(data.currentPage);
  53. }
  54. });
  55. }
  56. });