Thumb.html 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-slider-Thumb'>/**
  19. </span> * @class Ext.slider.Thumb
  20. * @private
  21. * Represents a single thumb element on a Slider. This would not usually be created manually and would instead
  22. * be created internally by an {@link Ext.slider.Multi Multi slider}.
  23. */
  24. Ext.define('Ext.slider.Thumb', {
  25. requires: ['Ext.dd.DragTracker', 'Ext.util.Format'],
  26. <span id='Ext-slider-Thumb-property-topThumbZIndex'> /**
  27. </span> * @private
  28. * @property {Number} topThumbZIndex
  29. * The number used internally to set the z index of the top thumb (see promoteThumb for details)
  30. */
  31. topZIndex: 10000,
  32. <span id='Ext-slider-Thumb-cfg-slider'> /**
  33. </span> * @cfg {Ext.slider.MultiSlider} slider (required)
  34. * The Slider to render to.
  35. */
  36. <span id='Ext-slider-Thumb-method-constructor'> /**
  37. </span> * Creates new slider thumb.
  38. * @param {Object} [config] Config object.
  39. */
  40. constructor: function(config) {
  41. var me = this;
  42. <span id='Ext-slider-Thumb-property-slider'> /**
  43. </span> * @property {Ext.slider.MultiSlider} slider
  44. * The slider this thumb is contained within
  45. */
  46. Ext.apply(me, config || {}, {
  47. cls: Ext.baseCSSPrefix + 'slider-thumb',
  48. <span id='Ext-slider-Thumb-cfg-constrain'> /**
  49. </span> * @cfg {Boolean} constrain True to constrain the thumb so that it cannot overlap its siblings
  50. */
  51. constrain: false
  52. });
  53. me.callParent([config]);
  54. },
  55. <span id='Ext-slider-Thumb-method-render'> /**
  56. </span> * Renders the thumb into a slider
  57. */
  58. render: function() {
  59. var me = this;
  60. me.el = me.slider.innerEl.insertFirst(me.getElConfig());
  61. me.onRender();
  62. },
  63. onRender: function() {
  64. if (this.disabled) {
  65. this.disable();
  66. }
  67. this.initEvents();
  68. },
  69. getElConfig: function() {
  70. var me = this,
  71. slider = me.slider,
  72. style = {};
  73. style[slider.vertical ? 'bottom' : 'left'] = slider.calculateThumbPosition(slider.normalizeValue(me.value)) + '%';
  74. return {
  75. style: style,
  76. id : this.id,
  77. cls : this.cls
  78. };
  79. },
  80. <span id='Ext-slider-Thumb-method-move'> /**
  81. </span> * @private
  82. * move the thumb
  83. */
  84. move: function(v, animate) {
  85. var el = this.el,
  86. styleProp = this.slider.vertical ? 'bottom' : 'left',
  87. to,
  88. from;
  89. v += '%';
  90. if (!animate) {
  91. el.dom.style[styleProp] = v;
  92. } else {
  93. to = {};
  94. to[styleProp] = v;
  95. if (!Ext.supports.GetPositionPercentage) {
  96. from = {};
  97. from[styleProp] = el.dom.style[styleProp];
  98. }
  99. new Ext.fx.Anim({
  100. target: el,
  101. duration: 350,
  102. from: from,
  103. to: to
  104. });
  105. }
  106. },
  107. <span id='Ext-slider-Thumb-method-bringToFront'> /**
  108. </span> * @private
  109. * Bring thumb dom element to front.
  110. */
  111. bringToFront: function() {
  112. this.el.setStyle('zIndex', this.topZIndex);
  113. },
  114. <span id='Ext-slider-Thumb-method-sendToBack'> /**
  115. </span> * @private
  116. * Send thumb dom element to back.
  117. */
  118. sendToBack: function() {
  119. this.el.setStyle('zIndex', '');
  120. },
  121. <span id='Ext-slider-Thumb-method-enable'> /**
  122. </span> * Enables the thumb if it is currently disabled
  123. */
  124. enable: function() {
  125. var me = this;
  126. me.disabled = false;
  127. if (me.el) {
  128. me.el.removeCls(me.slider.disabledCls);
  129. }
  130. },
  131. <span id='Ext-slider-Thumb-method-disable'> /**
  132. </span> * Disables the thumb if it is currently enabled
  133. */
  134. disable: function() {
  135. var me = this;
  136. me.disabled = true;
  137. if (me.el) {
  138. me.el.addCls(me.slider.disabledCls);
  139. }
  140. },
  141. <span id='Ext-slider-Thumb-method-initEvents'> /**
  142. </span> * Sets up an Ext.dd.DragTracker for this thumb
  143. */
  144. initEvents: function() {
  145. var me = this,
  146. el = me.el;
  147. me.tracker = new Ext.dd.DragTracker({
  148. onBeforeStart: Ext.Function.bind(me.onBeforeDragStart, me),
  149. onStart : Ext.Function.bind(me.onDragStart, me),
  150. onDrag : Ext.Function.bind(me.onDrag, me),
  151. onEnd : Ext.Function.bind(me.onDragEnd, me),
  152. tolerance : 3,
  153. autoStart : 300,
  154. overCls : Ext.baseCSSPrefix + 'slider-thumb-over'
  155. });
  156. me.tracker.initEl(el);
  157. },
  158. <span id='Ext-slider-Thumb-method-onBeforeDragStart'> /**
  159. </span> * @private
  160. * This is tied into the internal Ext.dd.DragTracker. If the slider is currently disabled,
  161. * this returns false to disable the DragTracker too.
  162. * @return {Boolean} False if the slider is currently disabled
  163. */
  164. onBeforeDragStart : function(e) {
  165. if (this.disabled) {
  166. return false;
  167. } else {
  168. this.slider.promoteThumb(this);
  169. return true;
  170. }
  171. },
  172. <span id='Ext-slider-Thumb-method-onDragStart'> /**
  173. </span> * @private
  174. * This is tied into the internal Ext.dd.DragTracker's onStart template method. Adds the drag CSS class
  175. * to the thumb and fires the 'dragstart' event
  176. */
  177. onDragStart: function(e){
  178. var me = this;
  179. me.el.addCls(Ext.baseCSSPrefix + 'slider-thumb-drag');
  180. me.dragging = me.slider.dragging = true;
  181. me.dragStartValue = me.value;
  182. me.slider.fireEvent('dragstart', me.slider, e, me);
  183. },
  184. <span id='Ext-slider-Thumb-method-onDrag'> /**
  185. </span> * @private
  186. * This is tied into the internal Ext.dd.DragTracker's onDrag template method. This is called every time
  187. * the DragTracker detects a drag movement. It updates the Slider's value using the position of the drag
  188. */
  189. onDrag: function(e) {
  190. var me = this,
  191. slider = me.slider,
  192. index = me.index,
  193. newValue = me.getValueFromTracker(),
  194. above,
  195. below;
  196. // If dragged out of range, value will be undefined
  197. if (newValue !== undefined) {
  198. if (me.constrain) {
  199. above = slider.thumbs[index + 1];
  200. below = slider.thumbs[index - 1];
  201. if (below !== undefined &amp;&amp; newValue &lt;= below.value) {
  202. newValue = below.value;
  203. }
  204. if (above !== undefined &amp;&amp; newValue &gt;= above.value) {
  205. newValue = above.value;
  206. }
  207. }
  208. slider.setValue(index, newValue, false);
  209. slider.fireEvent('drag', slider, e, me);
  210. }
  211. },
  212. getValueFromTracker: function() {
  213. var slider = this.slider,
  214. trackPoint = slider.getTrackpoint(this.tracker.getXY());
  215. // If dragged out of range, value will be undefined
  216. if (trackPoint !== undefined) {
  217. return slider.reversePixelValue(trackPoint);
  218. }
  219. },
  220. <span id='Ext-slider-Thumb-method-onDragEnd'> /**
  221. </span> * @private
  222. * This is tied to the internal Ext.dd.DragTracker's onEnd template method. Removes the drag CSS class and
  223. * fires the 'changecomplete' event with the new value
  224. */
  225. onDragEnd: function(e) {
  226. var me = this,
  227. slider = me.slider,
  228. value = me.value;
  229. me.el.removeCls(Ext.baseCSSPrefix + 'slider-thumb-drag');
  230. me.dragging = slider.dragging = false;
  231. slider.fireEvent('dragend', slider, e);
  232. if (me.dragStartValue != value) {
  233. slider.fireEvent('changecomplete', slider, value, me);
  234. }
  235. },
  236. destroy: function() {
  237. Ext.destroy(this.tracker);
  238. }
  239. });
  240. </pre>
  241. </body>
  242. </html>