SliderField.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. // vim: fdc=4:nu:ts=4:sw=4:nospell
  7. /**
  8. * @class Ext.form.SliderField
  9. * @extends Ext.form.Field Slider form field.
  10. * @constructor Creates a new SliderField
  11. * @param {Object}
  12. * config Configuration options
  13. */
  14. Ext.form.SliderField = Ext.extend(Ext.form.Field, {
  15. defaultAutoCreate : {
  16. tag : 'input',
  17. type : 'hidden'
  18. },
  19. // private
  20. initComponent : function() {
  21. Ext.form.SliderField.superclass.initComponent.call(this);
  22. this.minValue = this.minValue || 0;
  23. this.maxValue = this.maxValue || 1;
  24. },
  25. // private
  26. onRender : function(ct, position) {
  27. Ext.form.SliderField.superclass.onRender.call(this, ct, position);
  28. this.setValue(this.getValue() || this.minValue);
  29. this.sbar = Ext.DomHelper.insertFirst(ct, {
  30. tag : 'div',
  31. cls : 'x-slider-hbar'
  32. }, true);
  33. this.sthumb = Ext.DomHelper.append(ct, {
  34. tag : 'img',
  35. src : Ext.BLANK_IMAGE_URL,
  36. cls : 'x-slider-thumb'
  37. }, true);
  38. this.sthumb.addClassOnOver('x-slider-thumb-over');
  39. },
  40. // private
  41. afterRender : function() {
  42. Ext.form.SliderField.superclass.afterRender.call(this);
  43. this.sbar.setWidth(parseInt(this.el.dom.style.width, 10));
  44. this.dd = new Ext.dd.DD(this.sthumb.id, 'slider-' + this.sthumb.id, {});
  45. this.dd.slider = this;
  46. this.dd.onDrag = this.onDrag;
  47. this.dd.startDrag = this.startDrag;
  48. },
  49. startDrag : function(x, y) {
  50. var slider = this.slider;
  51. var bb = slider.sbar.getBox();
  52. var tb = slider.sthumb.getBox();
  53. this.resetConstraints();
  54. this.setYConstraint(0, 0);
  55. this.setXConstraint(tb.x - bb.x + 1, bb.x + bb.width - tb.x - tb.width
  56. - 1);
  57. slider.pixelMax = bb.width - tb.width;
  58. // debugger;
  59. },
  60. onDrag : function(e) {
  61. var min = this.slider.minValue;
  62. var max = this.slider.maxValue;
  63. var pixelPos = parseInt(this.getEl().style.left, 10);
  64. this.slider.setValue(min + (max - min) * pixelPos
  65. / this.slider.pixelMax);
  66. }
  67. });
  68. Ext.reg('sliderfield', Ext.form.SliderField);
  69. // end of file