PanelResizer.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*!
  2. * Ext JS Library 3.0.0
  3. * Copyright(c) 2006-2009 Ext JS, LLC
  4. * licensing@extjs.com
  5. * http://www.extjs.com/license
  6. */
  7. Ext.ux.PanelResizer = Ext.extend(Ext.util.Observable, {
  8. minHeight: 0,
  9. maxHeight:10000000,
  10. constructor: function(config){
  11. Ext.apply(this, config);
  12. this.events = {};
  13. Ext.ux.PanelResizer.superclass.constructor.call(this, config);
  14. },
  15. init : function(p){
  16. this.panel = p;
  17. if(this.panel.elements.indexOf('footer')==-1){
  18. p.elements += ',footer';
  19. }
  20. p.on('render', this.onRender, this);
  21. },
  22. onRender : function(p){
  23. this.handle = p.footer.createChild({cls:'x-panel-resize'});
  24. this.tracker = new Ext.dd.DragTracker({
  25. onStart: this.onDragStart.createDelegate(this),
  26. onDrag: this.onDrag.createDelegate(this),
  27. onEnd: this.onDragEnd.createDelegate(this),
  28. tolerance: 3,
  29. autoStart: 300
  30. });
  31. this.tracker.initEl(this.handle);
  32. p.on('beforedestroy', this.tracker.destroy, this.tracker);
  33. },
  34. // private
  35. onDragStart: function(e){
  36. this.dragging = true;
  37. this.startHeight = this.panel.el.getHeight();
  38. this.fireEvent('dragstart', this, e);
  39. },
  40. // private
  41. onDrag: function(e){
  42. this.panel.setHeight((this.startHeight-this.tracker.getOffset()[1]).constrain(this.minHeight, this.maxHeight));
  43. this.fireEvent('drag', this, e);
  44. },
  45. // private
  46. onDragEnd: function(e){
  47. this.dragging = false;
  48. this.fireEvent('dragend', this, e);
  49. }
  50. });
  51. Ext.preg('panelresizer', Ext.ux.PanelResizer);