slider-debug.js 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115
  1. /*
  2. Copyright (c) 2009, Yahoo! Inc. All rights reserved.
  3. Code licensed under the BSD License:
  4. http://developer.yahoo.net/yui/license.txt
  5. version: 2.8.0r4
  6. */
  7. /**
  8. * The Slider component is a UI control that enables the user to adjust
  9. * values in a finite range along one or two axes. Typically, the Slider
  10. * control is used in a web application as a rich, visual replacement
  11. * for an input box that takes a number as input. The Slider control can
  12. * also easily accommodate a second dimension, providing x,y output for
  13. * a selection point chosen from a rectangular region.
  14. *
  15. * @module slider
  16. * @title Slider Widget
  17. * @namespace YAHOO.widget
  18. * @requires yahoo,dom,dragdrop,event
  19. * @optional animation
  20. */
  21. (function () {
  22. var getXY = YAHOO.util.Dom.getXY,
  23. Event = YAHOO.util.Event,
  24. _AS = Array.prototype.slice;
  25. /**
  26. * A DragDrop implementation that can be used as a background for a
  27. * slider. It takes a reference to the thumb instance
  28. * so it can delegate some of the events to it. The goal is to make the
  29. * thumb jump to the location on the background when the background is
  30. * clicked.
  31. *
  32. * @class Slider
  33. * @extends YAHOO.util.DragDrop
  34. * @uses YAHOO.util.EventProvider
  35. * @constructor
  36. * @param {String} id The id of the element linked to this instance
  37. * @param {String} sGroup The group of related DragDrop items
  38. * @param {SliderThumb} oThumb The thumb for this slider
  39. * @param {String} sType The type of slider (horiz, vert, region)
  40. */
  41. function Slider(sElementId, sGroup, oThumb, sType) {
  42. Slider.ANIM_AVAIL = (!YAHOO.lang.isUndefined(YAHOO.util.Anim));
  43. if (sElementId) {
  44. this.init(sElementId, sGroup, true);
  45. this.initSlider(sType);
  46. this.initThumb(oThumb);
  47. }
  48. }
  49. YAHOO.lang.augmentObject(Slider,{
  50. /**
  51. * Factory method for creating a horizontal slider
  52. * @method YAHOO.widget.Slider.getHorizSlider
  53. * @static
  54. * @param {String} sBGElId the id of the slider's background element
  55. * @param {String} sHandleElId the id of the thumb element
  56. * @param {int} iLeft the number of pixels the element can move left
  57. * @param {int} iRight the number of pixels the element can move right
  58. * @param {int} iTickSize optional parameter for specifying that the element
  59. * should move a certain number pixels at a time.
  60. * @return {Slider} a horizontal slider control
  61. */
  62. getHorizSlider :
  63. function (sBGElId, sHandleElId, iLeft, iRight, iTickSize) {
  64. return new Slider(sBGElId, sBGElId,
  65. new YAHOO.widget.SliderThumb(sHandleElId, sBGElId,
  66. iLeft, iRight, 0, 0, iTickSize), "horiz");
  67. },
  68. /**
  69. * Factory method for creating a vertical slider
  70. * @method YAHOO.widget.Slider.getVertSlider
  71. * @static
  72. * @param {String} sBGElId the id of the slider's background element
  73. * @param {String} sHandleElId the id of the thumb element
  74. * @param {int} iUp the number of pixels the element can move up
  75. * @param {int} iDown the number of pixels the element can move down
  76. * @param {int} iTickSize optional parameter for specifying that the element
  77. * should move a certain number pixels at a time.
  78. * @return {Slider} a vertical slider control
  79. */
  80. getVertSlider :
  81. function (sBGElId, sHandleElId, iUp, iDown, iTickSize) {
  82. return new Slider(sBGElId, sBGElId,
  83. new YAHOO.widget.SliderThumb(sHandleElId, sBGElId, 0, 0,
  84. iUp, iDown, iTickSize), "vert");
  85. },
  86. /**
  87. * Factory method for creating a slider region like the one in the color
  88. * picker example
  89. * @method YAHOO.widget.Slider.getSliderRegion
  90. * @static
  91. * @param {String} sBGElId the id of the slider's background element
  92. * @param {String} sHandleElId the id of the thumb element
  93. * @param {int} iLeft the number of pixels the element can move left
  94. * @param {int} iRight the number of pixels the element can move right
  95. * @param {int} iUp the number of pixels the element can move up
  96. * @param {int} iDown the number of pixels the element can move down
  97. * @param {int} iTickSize optional parameter for specifying that the element
  98. * should move a certain number pixels at a time.
  99. * @return {Slider} a slider region control
  100. */
  101. getSliderRegion :
  102. function (sBGElId, sHandleElId, iLeft, iRight, iUp, iDown, iTickSize) {
  103. return new Slider(sBGElId, sBGElId,
  104. new YAHOO.widget.SliderThumb(sHandleElId, sBGElId, iLeft, iRight,
  105. iUp, iDown, iTickSize), "region");
  106. },
  107. /**
  108. * Constant for valueChangeSource, indicating that the user clicked or
  109. * dragged the slider to change the value.
  110. * @property Slider.SOURCE_UI_EVENT
  111. * @final
  112. * @static
  113. * @default 1
  114. */
  115. SOURCE_UI_EVENT : 1,
  116. /**
  117. * Constant for valueChangeSource, indicating that the value was altered
  118. * by a programmatic call to setValue/setRegionValue.
  119. * @property Slider.SOURCE_SET_VALUE
  120. * @final
  121. * @static
  122. * @default 2
  123. */
  124. SOURCE_SET_VALUE : 2,
  125. /**
  126. * Constant for valueChangeSource, indicating that the value was altered
  127. * by hitting any of the supported keyboard characters.
  128. * @property Slider.SOURCE_KEY_EVENT
  129. * @final
  130. * @static
  131. * @default 2
  132. */
  133. SOURCE_KEY_EVENT : 3,
  134. /**
  135. * By default, animation is available if the animation utility is detected.
  136. * @property Slider.ANIM_AVAIL
  137. * @static
  138. * @type boolean
  139. */
  140. ANIM_AVAIL : false
  141. },true);
  142. YAHOO.extend(Slider, YAHOO.util.DragDrop, {
  143. /**
  144. * Tracks the state of the mouse button to aid in when events are fired.
  145. *
  146. * @property _mouseDown
  147. * @type boolean
  148. * @default false
  149. * @private
  150. */
  151. _mouseDown : false,
  152. /**
  153. * Override the default setting of dragOnly to true.
  154. * @property dragOnly
  155. * @type boolean
  156. * @default true
  157. */
  158. dragOnly : true,
  159. /**
  160. * Initializes the slider. Executed in the constructor
  161. * @method initSlider
  162. * @param {string} sType the type of slider (horiz, vert, region)
  163. */
  164. initSlider: function(sType) {
  165. /**
  166. * The type of the slider (horiz, vert, region)
  167. * @property type
  168. * @type string
  169. */
  170. this.type = sType;
  171. //this.removeInvalidHandleType("A");
  172. this.logger = new YAHOO.widget.LogWriter(this.toString());
  173. /**
  174. * Event the fires when the value of the control changes. If
  175. * the control is animated the event will fire every point
  176. * along the way.
  177. * @event change
  178. * @param {int} newOffset|x the new offset for normal sliders, or the new
  179. * x offset for region sliders
  180. * @param {int} y the number of pixels the thumb has moved on the y axis
  181. * (region sliders only)
  182. */
  183. this.createEvent("change", this);
  184. /**
  185. * Event that fires at the beginning of a slider thumb move.
  186. * @event slideStart
  187. */
  188. this.createEvent("slideStart", this);
  189. /**
  190. * Event that fires at the end of a slider thumb move
  191. * @event slideEnd
  192. */
  193. this.createEvent("slideEnd", this);
  194. /**
  195. * Overrides the isTarget property in YAHOO.util.DragDrop
  196. * @property isTarget
  197. * @private
  198. */
  199. this.isTarget = false;
  200. /**
  201. * Flag that determines if the thumb will animate when moved
  202. * @property animate
  203. * @type boolean
  204. */
  205. this.animate = Slider.ANIM_AVAIL;
  206. /**
  207. * Set to false to disable a background click thumb move
  208. * @property backgroundEnabled
  209. * @type boolean
  210. */
  211. this.backgroundEnabled = true;
  212. /**
  213. * Adjustment factor for tick animation, the more ticks, the
  214. * faster the animation (by default)
  215. * @property tickPause
  216. * @type int
  217. */
  218. this.tickPause = 40;
  219. /**
  220. * Enables the arrow, home and end keys, defaults to true.
  221. * @property enableKeys
  222. * @type boolean
  223. */
  224. this.enableKeys = true;
  225. /**
  226. * Specifies the number of pixels the arrow keys will move the slider.
  227. * Default is 20.
  228. * @property keyIncrement
  229. * @type int
  230. */
  231. this.keyIncrement = 20;
  232. /**
  233. * moveComplete is set to true when the slider has moved to its final
  234. * destination. For animated slider, this value can be checked in
  235. * the onChange handler to make it possible to execute logic only
  236. * when the move is complete rather than at all points along the way.
  237. * Deprecated because this flag is only useful when the background is
  238. * clicked and the slider is animated. If the user drags the thumb,
  239. * the flag is updated when the drag is over ... the final onDrag event
  240. * fires before the mouseup the ends the drag, so the implementer will
  241. * never see it.
  242. *
  243. * @property moveComplete
  244. * @type Boolean
  245. * @deprecated use the slideEnd event instead
  246. */
  247. this.moveComplete = true;
  248. /**
  249. * If animation is configured, specifies the length of the animation
  250. * in seconds.
  251. * @property animationDuration
  252. * @type int
  253. * @default 0.2
  254. */
  255. this.animationDuration = 0.2;
  256. /**
  257. * Constant for valueChangeSource, indicating that the user clicked or
  258. * dragged the slider to change the value.
  259. * @property SOURCE_UI_EVENT
  260. * @final
  261. * @default 1
  262. * @deprecated use static Slider.SOURCE_UI_EVENT
  263. */
  264. this.SOURCE_UI_EVENT = 1;
  265. /**
  266. * Constant for valueChangeSource, indicating that the value was altered
  267. * by a programmatic call to setValue/setRegionValue.
  268. * @property SOURCE_SET_VALUE
  269. * @final
  270. * @default 2
  271. * @deprecated use static Slider.SOURCE_SET_VALUE
  272. */
  273. this.SOURCE_SET_VALUE = 2;
  274. /**
  275. * When the slider value changes, this property is set to identify where
  276. * the update came from. This will be either 1, meaning the slider was
  277. * clicked or dragged, or 2, meaning that it was set via a setValue() call.
  278. * This can be used within event handlers to apply some of the logic only
  279. * when dealing with one source or another.
  280. * @property valueChangeSource
  281. * @type int
  282. * @since 2.3.0
  283. */
  284. this.valueChangeSource = 0;
  285. /**
  286. * Indicates whether or not events will be supressed for the current
  287. * slide operation
  288. * @property _silent
  289. * @type boolean
  290. * @private
  291. */
  292. this._silent = false;
  293. /**
  294. * Saved offset used to protect against NaN problems when slider is
  295. * set to display:none
  296. * @property lastOffset
  297. * @type [int, int]
  298. */
  299. this.lastOffset = [0,0];
  300. },
  301. /**
  302. * Initializes the slider's thumb. Executed in the constructor.
  303. * @method initThumb
  304. * @param {YAHOO.widget.SliderThumb} t the slider thumb
  305. */
  306. initThumb: function(t) {
  307. var self = this;
  308. /**
  309. * A YAHOO.widget.SliderThumb instance that we will use to
  310. * reposition the thumb when the background is clicked
  311. * @property thumb
  312. * @type YAHOO.widget.SliderThumb
  313. */
  314. this.thumb = t;
  315. t.cacheBetweenDrags = true;
  316. if (t._isHoriz && t.xTicks && t.xTicks.length) {
  317. this.tickPause = Math.round(360 / t.xTicks.length);
  318. } else if (t.yTicks && t.yTicks.length) {
  319. this.tickPause = Math.round(360 / t.yTicks.length);
  320. }
  321. this.logger.log("tickPause: " + this.tickPause);
  322. // delegate thumb methods
  323. t.onAvailable = function() {
  324. return self.setStartSliderState();
  325. };
  326. t.onMouseDown = function () {
  327. self._mouseDown = true;
  328. self.logger.log('thumb mousedown');
  329. return self.focus();
  330. };
  331. t.startDrag = function() {
  332. self.logger.log('thumb startDrag');
  333. self._slideStart();
  334. };
  335. t.onDrag = function() {
  336. self.logger.log('thumb drag');
  337. self.fireEvents(true);
  338. };
  339. t.onMouseUp = function() {
  340. self.thumbMouseUp();
  341. };
  342. },
  343. /**
  344. * Executed when the slider element is available
  345. * @method onAvailable
  346. */
  347. onAvailable: function() {
  348. this._bindKeyEvents();
  349. },
  350. /**
  351. * Sets up the listeners for keydown and key press events.
  352. *
  353. * @method _bindKeyEvents
  354. * @protected
  355. */
  356. _bindKeyEvents : function () {
  357. Event.on(this.id, "keydown", this.handleKeyDown, this, true);
  358. Event.on(this.id, "keypress", this.handleKeyPress, this, true);
  359. },
  360. /**
  361. * Executed when a keypress event happens with the control focused.
  362. * Prevents the default behavior for navigation keys. The actual
  363. * logic for moving the slider thumb in response to a key event
  364. * happens in handleKeyDown.
  365. * @param {Event} e the keypress event
  366. */
  367. handleKeyPress: function(e) {
  368. if (this.enableKeys) {
  369. var kc = Event.getCharCode(e);
  370. switch (kc) {
  371. case 0x25: // left
  372. case 0x26: // up
  373. case 0x27: // right
  374. case 0x28: // down
  375. case 0x24: // home
  376. case 0x23: // end
  377. Event.preventDefault(e);
  378. break;
  379. default:
  380. }
  381. }
  382. },
  383. /**
  384. * Executed when a keydown event happens with the control focused.
  385. * Updates the slider value and display when the keypress is an
  386. * arrow key, home, or end as long as enableKeys is set to true.
  387. * @param {Event} e the keydown event
  388. */
  389. handleKeyDown: function(e) {
  390. if (this.enableKeys) {
  391. var kc = Event.getCharCode(e),
  392. t = this.thumb,
  393. h = this.getXValue(),
  394. v = this.getYValue(),
  395. changeValue = true;
  396. switch (kc) {
  397. // left
  398. case 0x25: h -= this.keyIncrement; break;
  399. // up
  400. case 0x26: v -= this.keyIncrement; break;
  401. // right
  402. case 0x27: h += this.keyIncrement; break;
  403. // down
  404. case 0x28: v += this.keyIncrement; break;
  405. // home
  406. case 0x24: h = t.leftConstraint;
  407. v = t.topConstraint;
  408. break;
  409. // end
  410. case 0x23: h = t.rightConstraint;
  411. v = t.bottomConstraint;
  412. break;
  413. default: changeValue = false;
  414. }
  415. if (changeValue) {
  416. if (t._isRegion) {
  417. this._setRegionValue(Slider.SOURCE_KEY_EVENT, h, v, true);
  418. } else {
  419. this._setValue(Slider.SOURCE_KEY_EVENT,
  420. (t._isHoriz ? h : v), true);
  421. }
  422. Event.stopEvent(e);
  423. }
  424. }
  425. },
  426. /**
  427. * Initialization that sets up the value offsets once the elements are ready
  428. * @method setStartSliderState
  429. */
  430. setStartSliderState: function() {
  431. this.logger.log("Fixing state");
  432. this.setThumbCenterPoint();
  433. /**
  434. * The basline position of the background element, used
  435. * to determine if the background has moved since the last
  436. * operation.
  437. * @property baselinePos
  438. * @type [int, int]
  439. */
  440. this.baselinePos = getXY(this.getEl());
  441. this.thumb.startOffset = this.thumb.getOffsetFromParent(this.baselinePos);
  442. if (this.thumb._isRegion) {
  443. if (this.deferredSetRegionValue) {
  444. this._setRegionValue.apply(this, this.deferredSetRegionValue);
  445. this.deferredSetRegionValue = null;
  446. } else {
  447. this.setRegionValue(0, 0, true, true, true);
  448. }
  449. } else {
  450. if (this.deferredSetValue) {
  451. this._setValue.apply(this, this.deferredSetValue);
  452. this.deferredSetValue = null;
  453. } else {
  454. this.setValue(0, true, true, true);
  455. }
  456. }
  457. },
  458. /**
  459. * When the thumb is available, we cache the centerpoint of the element so
  460. * we can position the element correctly when the background is clicked
  461. * @method setThumbCenterPoint
  462. */
  463. setThumbCenterPoint: function() {
  464. var el = this.thumb.getEl();
  465. if (el) {
  466. /**
  467. * The center of the slider element is stored so we can
  468. * place it in the correct position when the background is clicked.
  469. * @property thumbCenterPoint
  470. * @type {"x": int, "y": int}
  471. */
  472. this.thumbCenterPoint = {
  473. x: parseInt(el.offsetWidth/2, 10),
  474. y: parseInt(el.offsetHeight/2, 10)
  475. };
  476. }
  477. },
  478. /**
  479. * Locks the slider, overrides YAHOO.util.DragDrop
  480. * @method lock
  481. */
  482. lock: function() {
  483. this.logger.log("locking");
  484. this.thumb.lock();
  485. this.locked = true;
  486. },
  487. /**
  488. * Unlocks the slider, overrides YAHOO.util.DragDrop
  489. * @method unlock
  490. */
  491. unlock: function() {
  492. this.logger.log("unlocking");
  493. this.thumb.unlock();
  494. this.locked = false;
  495. },
  496. /**
  497. * Handles mouseup event on the thumb
  498. * @method thumbMouseUp
  499. * @private
  500. */
  501. thumbMouseUp: function() {
  502. this._mouseDown = false;
  503. this.logger.log("thumb mouseup");
  504. if (!this.isLocked()) {
  505. this.endMove();
  506. }
  507. },
  508. onMouseUp: function() {
  509. this._mouseDown = false;
  510. this.logger.log("background mouseup");
  511. if (this.backgroundEnabled && !this.isLocked()) {
  512. this.endMove();
  513. }
  514. },
  515. /**
  516. * Returns a reference to this slider's thumb
  517. * @method getThumb
  518. * @return {SliderThumb} this slider's thumb
  519. */
  520. getThumb: function() {
  521. return this.thumb;
  522. },
  523. /**
  524. * Try to focus the element when clicked so we can add
  525. * accessibility features
  526. * @method focus
  527. * @private
  528. */
  529. focus: function() {
  530. this.logger.log("focus");
  531. this.valueChangeSource = Slider.SOURCE_UI_EVENT;
  532. // Focus the background element if possible
  533. var el = this.getEl();
  534. if (el.focus) {
  535. try {
  536. el.focus();
  537. } catch(e) {
  538. // Prevent permission denied unhandled exception in FF that can
  539. // happen when setting focus while another element is handling
  540. // the blur. @TODO this is still writing to the error log
  541. // (unhandled error) in FF1.5 with strict error checking on.
  542. }
  543. }
  544. this.verifyOffset();
  545. return !this.isLocked();
  546. },
  547. /**
  548. * Event that fires when the value of the slider has changed
  549. * @method onChange
  550. * @param {int} firstOffset the number of pixels the thumb has moved
  551. * from its start position. Normal horizontal and vertical sliders will only
  552. * have the firstOffset. Regions will have both, the first is the horizontal
  553. * offset, the second the vertical.
  554. * @param {int} secondOffset the y offset for region sliders
  555. * @deprecated use instance.subscribe("change") instead
  556. */
  557. onChange: function (firstOffset, secondOffset) {
  558. /* override me */
  559. this.logger.log("onChange: " + firstOffset + ", " + secondOffset);
  560. },
  561. /**
  562. * Event that fires when the at the beginning of the slider thumb move
  563. * @method onSlideStart
  564. * @deprecated use instance.subscribe("slideStart") instead
  565. */
  566. onSlideStart: function () {
  567. /* override me */
  568. this.logger.log("onSlideStart");
  569. },
  570. /**
  571. * Event that fires at the end of a slider thumb move
  572. * @method onSliderEnd
  573. * @deprecated use instance.subscribe("slideEnd") instead
  574. */
  575. onSlideEnd: function () {
  576. /* override me */
  577. this.logger.log("onSlideEnd");
  578. },
  579. /**
  580. * Returns the slider's thumb offset from the start position
  581. * @method getValue
  582. * @return {int} the current value
  583. */
  584. getValue: function () {
  585. return this.thumb.getValue();
  586. },
  587. /**
  588. * Returns the slider's thumb X offset from the start position
  589. * @method getXValue
  590. * @return {int} the current horizontal offset
  591. */
  592. getXValue: function () {
  593. return this.thumb.getXValue();
  594. },
  595. /**
  596. * Returns the slider's thumb Y offset from the start position
  597. * @method getYValue
  598. * @return {int} the current vertical offset
  599. */
  600. getYValue: function () {
  601. return this.thumb.getYValue();
  602. },
  603. /**
  604. * Provides a way to set the value of the slider in code.
  605. *
  606. * @method setValue
  607. * @param {int} newOffset the number of pixels the thumb should be
  608. * positioned away from the initial start point
  609. * @param {boolean} skipAnim set to true to disable the animation
  610. * for this move action (but not others).
  611. * @param {boolean} force ignore the locked setting and set value anyway
  612. * @param {boolean} silent when true, do not fire events
  613. * @return {boolean} true if the move was performed, false if it failed
  614. */
  615. setValue: function() {
  616. var args = _AS.call(arguments);
  617. args.unshift(Slider.SOURCE_SET_VALUE);
  618. return this._setValue.apply(this,args);
  619. },
  620. /**
  621. * Worker function to execute the value set operation. Accepts type of
  622. * set operation in addition to the usual setValue params.
  623. *
  624. * @method _setValue
  625. * @param source {int} what triggered the set (e.g. Slider.SOURCE_SET_VALUE)
  626. * @param {int} newOffset the number of pixels the thumb should be
  627. * positioned away from the initial start point
  628. * @param {boolean} skipAnim set to true to disable the animation
  629. * for this move action (but not others).
  630. * @param {boolean} force ignore the locked setting and set value anyway
  631. * @param {boolean} silent when true, do not fire events
  632. * @return {boolean} true if the move was performed, false if it failed
  633. * @protected
  634. */
  635. _setValue: function(source, newOffset, skipAnim, force, silent) {
  636. var t = this.thumb, newX, newY;
  637. if (!t.available) {
  638. this.logger.log("defer setValue until after onAvailble");
  639. this.deferredSetValue = arguments;
  640. return false;
  641. }
  642. if (this.isLocked() && !force) {
  643. this.logger.log("Can't set the value, the control is locked");
  644. return false;
  645. }
  646. if ( isNaN(newOffset) ) {
  647. this.logger.log("setValue, Illegal argument: " + newOffset);
  648. return false;
  649. }
  650. if (t._isRegion) {
  651. this.logger.log("Call to setValue for region Slider ignored. Use setRegionValue","warn");
  652. return false;
  653. }
  654. this.logger.log("setValue " + newOffset);
  655. this._silent = silent;
  656. this.valueChangeSource = source || Slider.SOURCE_SET_VALUE;
  657. t.lastOffset = [newOffset, newOffset];
  658. this.verifyOffset();
  659. this._slideStart();
  660. if (t._isHoriz) {
  661. newX = t.initPageX + newOffset + this.thumbCenterPoint.x;
  662. this.moveThumb(newX, t.initPageY, skipAnim);
  663. } else {
  664. newY = t.initPageY + newOffset + this.thumbCenterPoint.y;
  665. this.moveThumb(t.initPageX, newY, skipAnim);
  666. }
  667. return true;
  668. },
  669. /**
  670. * Provides a way to set the value of the region slider in code.
  671. * @method setRegionValue
  672. * @param {int} newOffset the number of pixels the thumb should be
  673. * positioned away from the initial start point (x axis for region)
  674. * @param {int} newOffset2 the number of pixels the thumb should be
  675. * positioned away from the initial start point (y axis for region)
  676. * @param {boolean} skipAnim set to true to disable the animation
  677. * for this move action (but not others).
  678. * @param {boolean} force ignore the locked setting and set value anyway
  679. * @param {boolean} silent when true, do not fire events
  680. * @return {boolean} true if the move was performed, false if it failed
  681. */
  682. setRegionValue : function () {
  683. var args = _AS.call(arguments);
  684. args.unshift(Slider.SOURCE_SET_VALUE);
  685. return this._setRegionValue.apply(this,args);
  686. },
  687. /**
  688. * Worker function to execute the value set operation. Accepts type of
  689. * set operation in addition to the usual setValue params.
  690. *
  691. * @method _setRegionValue
  692. * @param source {int} what triggered the set (e.g. Slider.SOURCE_SET_VALUE)
  693. * @param {int} newOffset the number of pixels the thumb should be
  694. * positioned away from the initial start point (x axis for region)
  695. * @param {int} newOffset2 the number of pixels the thumb should be
  696. * positioned away from the initial start point (y axis for region)
  697. * @param {boolean} skipAnim set to true to disable the animation
  698. * for this move action (but not others).
  699. * @param {boolean} force ignore the locked setting and set value anyway
  700. * @param {boolean} silent when true, do not fire events
  701. * @return {boolean} true if the move was performed, false if it failed
  702. * @protected
  703. */
  704. _setRegionValue: function(source, newOffset, newOffset2, skipAnim, force, silent) {
  705. var t = this.thumb, newX, newY;
  706. if (!t.available) {
  707. this.logger.log("defer setRegionValue until after onAvailble");
  708. this.deferredSetRegionValue = arguments;
  709. return false;
  710. }
  711. if (this.isLocked() && !force) {
  712. this.logger.log("Can't set the value, the control is locked");
  713. return false;
  714. }
  715. if ( isNaN(newOffset) ) {
  716. this.logger.log("setRegionValue, Illegal argument: " + newOffset);
  717. return false;
  718. }
  719. if (!t._isRegion) {
  720. this.logger.log("Call to setRegionValue for non-region Slider ignored. Use setValue","warn");
  721. return false;
  722. }
  723. this._silent = silent;
  724. this.valueChangeSource = source || Slider.SOURCE_SET_VALUE;
  725. t.lastOffset = [newOffset, newOffset2];
  726. this.verifyOffset();
  727. this._slideStart();
  728. newX = t.initPageX + newOffset + this.thumbCenterPoint.x;
  729. newY = t.initPageY + newOffset2 + this.thumbCenterPoint.y;
  730. this.moveThumb(newX, newY, skipAnim);
  731. return true;
  732. },
  733. /**
  734. * Checks the background position element position. If it has moved from the
  735. * baseline position, the constraints for the thumb are reset
  736. * @method verifyOffset
  737. * @return {boolean} True if the offset is the same as the baseline.
  738. */
  739. verifyOffset: function() {
  740. var xy = getXY(this.getEl()),
  741. t = this.thumb;
  742. if (!this.thumbCenterPoint || !this.thumbCenterPoint.x) {
  743. this.setThumbCenterPoint();
  744. }
  745. if (xy) {
  746. this.logger.log("newPos: " + xy);
  747. if (xy[0] != this.baselinePos[0] || xy[1] != this.baselinePos[1]) {
  748. this.logger.log("background moved, resetting constraints");
  749. // Reset background
  750. this.setInitPosition();
  751. this.baselinePos = xy;
  752. // Reset thumb
  753. t.initPageX = this.initPageX + t.startOffset[0];
  754. t.initPageY = this.initPageY + t.startOffset[1];
  755. t.deltaSetXY = null;
  756. this.resetThumbConstraints();
  757. return false;
  758. }
  759. }
  760. return true;
  761. },
  762. /**
  763. * Move the associated slider moved to a timeout to try to get around the
  764. * mousedown stealing moz does when I move the slider element between the
  765. * cursor and the background during the mouseup event
  766. * @method moveThumb
  767. * @param {int} x the X coordinate of the click
  768. * @param {int} y the Y coordinate of the click
  769. * @param {boolean} skipAnim don't animate if the move happend onDrag
  770. * @param {boolean} midMove set to true if this is not terminating
  771. * the slider movement
  772. * @private
  773. */
  774. moveThumb: function(x, y, skipAnim, midMove) {
  775. var t = this.thumb,
  776. self = this,
  777. p,_p,anim;
  778. if (!t.available) {
  779. this.logger.log("thumb is not available yet, aborting move");
  780. return;
  781. }
  782. this.logger.log("move thumb, x: " + x + ", y: " + y);
  783. t.setDelta(this.thumbCenterPoint.x, this.thumbCenterPoint.y);
  784. _p = t.getTargetCoord(x, y);
  785. p = [Math.round(_p.x), Math.round(_p.y)];
  786. if (this.animate && t._graduated && !skipAnim) {
  787. this.logger.log("graduated");
  788. this.lock();
  789. // cache the current thumb pos
  790. this.curCoord = getXY(this.thumb.getEl());
  791. this.curCoord = [Math.round(this.curCoord[0]), Math.round(this.curCoord[1])];
  792. setTimeout( function() { self.moveOneTick(p); }, this.tickPause );
  793. } else if (this.animate && Slider.ANIM_AVAIL && !skipAnim) {
  794. this.logger.log("animating to " + p);
  795. this.lock();
  796. anim = new YAHOO.util.Motion(
  797. t.id, { points: { to: p } },
  798. this.animationDuration,
  799. YAHOO.util.Easing.easeOut );
  800. anim.onComplete.subscribe( function() {
  801. self.logger.log("Animation completed _mouseDown:" + self._mouseDown);
  802. self.unlock();
  803. if (!self._mouseDown) {
  804. self.endMove();
  805. }
  806. });
  807. anim.animate();
  808. } else {
  809. t.setDragElPos(x, y);
  810. if (!midMove && !this._mouseDown) {
  811. this.endMove();
  812. }
  813. }
  814. },
  815. _slideStart: function() {
  816. if (!this._sliding) {
  817. if (!this._silent) {
  818. this.onSlideStart();
  819. this.fireEvent("slideStart");
  820. }
  821. this._sliding = true;
  822. this.moveComplete = false; // for backward compatibility. Deprecated
  823. }
  824. },
  825. _slideEnd: function() {
  826. if (this._sliding) {
  827. // Reset state before firing slideEnd
  828. var silent = this._silent;
  829. this._sliding = false;
  830. this.moveComplete = true; // for backward compatibility. Deprecated
  831. this._silent = false;
  832. if (!silent) {
  833. this.onSlideEnd();
  834. this.fireEvent("slideEnd");
  835. }
  836. }
  837. },
  838. /**
  839. * Move the slider one tick mark towards its final coordinate. Used
  840. * for the animation when tick marks are defined
  841. * @method moveOneTick
  842. * @param {int[]} the destination coordinate
  843. * @private
  844. */
  845. moveOneTick: function(finalCoord) {
  846. var t = this.thumb,
  847. self = this,
  848. nextCoord = null,
  849. tmpX, tmpY;
  850. if (t._isRegion) {
  851. nextCoord = this._getNextX(this.curCoord, finalCoord);
  852. tmpX = (nextCoord !== null) ? nextCoord[0] : this.curCoord[0];
  853. nextCoord = this._getNextY(this.curCoord, finalCoord);
  854. tmpY = (nextCoord !== null) ? nextCoord[1] : this.curCoord[1];
  855. nextCoord = tmpX !== this.curCoord[0] || tmpY !== this.curCoord[1] ?
  856. [ tmpX, tmpY ] : null;
  857. } else if (t._isHoriz) {
  858. nextCoord = this._getNextX(this.curCoord, finalCoord);
  859. } else {
  860. nextCoord = this._getNextY(this.curCoord, finalCoord);
  861. }
  862. this.logger.log("moveOneTick: " +
  863. " finalCoord: " + finalCoord +
  864. " this.curCoord: " + this.curCoord +
  865. " nextCoord: " + nextCoord);
  866. if (nextCoord) {
  867. // cache the position
  868. this.curCoord = nextCoord;
  869. // move to the next coord
  870. this.thumb.alignElWithMouse(t.getEl(), nextCoord[0] + this.thumbCenterPoint.x, nextCoord[1] + this.thumbCenterPoint.y);
  871. // check if we are in the final position, if not make a recursive call
  872. if (!(nextCoord[0] == finalCoord[0] && nextCoord[1] == finalCoord[1])) {
  873. setTimeout(function() { self.moveOneTick(finalCoord); },
  874. this.tickPause);
  875. } else {
  876. this.unlock();
  877. if (!this._mouseDown) {
  878. this.endMove();
  879. }
  880. }
  881. } else {
  882. this.unlock();
  883. if (!this._mouseDown) {
  884. this.endMove();
  885. }
  886. }
  887. },
  888. /**
  889. * Returns the next X tick value based on the current coord and the target coord.
  890. * @method _getNextX
  891. * @private
  892. */
  893. _getNextX: function(curCoord, finalCoord) {
  894. this.logger.log("getNextX: " + curCoord + ", " + finalCoord);
  895. var t = this.thumb,
  896. thresh,
  897. tmp = [],
  898. nextCoord = null;
  899. if (curCoord[0] > finalCoord[0]) {
  900. thresh = t.tickSize - this.thumbCenterPoint.x;
  901. tmp = t.getTargetCoord( curCoord[0] - thresh, curCoord[1] );
  902. nextCoord = [tmp.x, tmp.y];
  903. } else if (curCoord[0] < finalCoord[0]) {
  904. thresh = t.tickSize + this.thumbCenterPoint.x;
  905. tmp = t.getTargetCoord( curCoord[0] + thresh, curCoord[1] );
  906. nextCoord = [tmp.x, tmp.y];
  907. } else {
  908. // equal, do nothing
  909. }
  910. return nextCoord;
  911. },
  912. /**
  913. * Returns the next Y tick value based on the current coord and the target coord.
  914. * @method _getNextY
  915. * @private
  916. */
  917. _getNextY: function(curCoord, finalCoord) {
  918. var t = this.thumb,
  919. thresh,
  920. tmp = [],
  921. nextCoord = null;
  922. if (curCoord[1] > finalCoord[1]) {
  923. thresh = t.tickSize - this.thumbCenterPoint.y;
  924. tmp = t.getTargetCoord( curCoord[0], curCoord[1] - thresh );
  925. nextCoord = [tmp.x, tmp.y];
  926. } else if (curCoord[1] < finalCoord[1]) {
  927. thresh = t.tickSize + this.thumbCenterPoint.y;
  928. tmp = t.getTargetCoord( curCoord[0], curCoord[1] + thresh );
  929. nextCoord = [tmp.x, tmp.y];
  930. } else {
  931. // equal, do nothing
  932. }
  933. return nextCoord;
  934. },
  935. /**
  936. * Resets the constraints before moving the thumb.
  937. * @method b4MouseDown
  938. * @private
  939. */
  940. b4MouseDown: function(e) {
  941. if (!this.backgroundEnabled) {
  942. return false;
  943. }
  944. this.thumb.autoOffset();
  945. this.baselinePos = [];
  946. },
  947. /**
  948. * Handles the mousedown event for the slider background
  949. * @method onMouseDown
  950. * @private
  951. */
  952. onMouseDown: function(e) {
  953. if (!this.backgroundEnabled || this.isLocked()) {
  954. return false;
  955. }
  956. this._mouseDown = true;
  957. var x = Event.getPageX(e),
  958. y = Event.getPageY(e);
  959. this.logger.log("bg mousedown: " + x + "," + y);
  960. this.focus();
  961. this._slideStart();
  962. this.moveThumb(x, y);
  963. },
  964. /**
  965. * Handles the onDrag event for the slider background
  966. * @method onDrag
  967. * @private
  968. */
  969. onDrag: function(e) {
  970. this.logger.log("background drag");
  971. if (this.backgroundEnabled && !this.isLocked()) {
  972. var x = Event.getPageX(e),
  973. y = Event.getPageY(e);
  974. this.moveThumb(x, y, true, true);
  975. this.fireEvents();
  976. }
  977. },
  978. /**
  979. * Fired when the slider movement ends
  980. * @method endMove
  981. * @private
  982. */
  983. endMove: function () {
  984. this.logger.log("endMove");
  985. this.unlock();
  986. this.fireEvents();
  987. this._slideEnd();
  988. },
  989. /**
  990. * Resets the X and Y contraints for the thumb. Used in lieu of the thumb
  991. * instance's inherited resetConstraints because some logic was not
  992. * applicable.
  993. * @method resetThumbConstraints
  994. * @protected
  995. */
  996. resetThumbConstraints: function () {
  997. var t = this.thumb;
  998. t.setXConstraint(t.leftConstraint, t.rightConstraint, t.xTickSize);
  999. t.setYConstraint(t.topConstraint, t.bottomConstraint, t.xTickSize);
  1000. },
  1001. /**
  1002. * Fires the change event if the value has been changed. Ignored if we are in
  1003. * the middle of an animation as the event will fire when the animation is
  1004. * complete
  1005. * @method fireEvents
  1006. * @param {boolean} thumbEvent set to true if this event is fired from an event
  1007. * that occurred on the thumb. If it is, the state of the
  1008. * thumb dd object should be correct. Otherwise, the event
  1009. * originated on the background, so the thumb state needs to
  1010. * be refreshed before proceeding.
  1011. * @private
  1012. */
  1013. fireEvents: function (thumbEvent) {
  1014. var t = this.thumb, newX, newY, newVal;
  1015. if (!thumbEvent) {
  1016. t.cachePosition();
  1017. }
  1018. if (! this.isLocked()) {
  1019. if (t._isRegion) {
  1020. newX = t.getXValue();
  1021. newY = t.getYValue();
  1022. if (newX != this.previousX || newY != this.previousY) {
  1023. if (!this._silent) {
  1024. this.onChange(newX, newY);
  1025. this.fireEvent("change", { x: newX, y: newY });
  1026. }
  1027. }
  1028. this.previousX = newX;
  1029. this.previousY = newY;
  1030. } else {
  1031. newVal = t.getValue();
  1032. if (newVal != this.previousVal) {
  1033. this.logger.log("Firing onchange: " + newVal);
  1034. if (!this._silent) {
  1035. this.onChange( newVal );
  1036. this.fireEvent("change", newVal);
  1037. }
  1038. }
  1039. this.previousVal = newVal;
  1040. }
  1041. }
  1042. },
  1043. /**
  1044. * Slider toString
  1045. * @method toString
  1046. * @return {string} string representation of the instance
  1047. */
  1048. toString: function () {
  1049. return ("Slider (" + this.type +") " + this.id);
  1050. }
  1051. });
  1052. YAHOO.lang.augmentProto(Slider, YAHOO.util.EventProvider);
  1053. YAHOO.widget.Slider = Slider;
  1054. })();
  1055. /**
  1056. * A drag and drop implementation to be used as the thumb of a slider.
  1057. * @class SliderThumb
  1058. * @extends YAHOO.util.DD
  1059. * @constructor
  1060. * @param {String} id the id of the slider html element
  1061. * @param {String} sGroup the group of related DragDrop items
  1062. * @param {int} iLeft the number of pixels the element can move left
  1063. * @param {int} iRight the number of pixels the element can move right
  1064. * @param {int} iUp the number of pixels the element can move up
  1065. * @param {int} iDown the number of pixels the element can move down
  1066. * @param {int} iTickSize optional parameter for specifying that the element
  1067. * should move a certain number pixels at a time.
  1068. */
  1069. YAHOO.widget.SliderThumb = function(id, sGroup, iLeft, iRight, iUp, iDown, iTickSize) {
  1070. if (id) {
  1071. YAHOO.widget.SliderThumb.superclass.constructor.call(this, id, sGroup);
  1072. /**
  1073. * The id of the thumbs parent HTML element (the slider background
  1074. * element).
  1075. * @property parentElId
  1076. * @type string
  1077. */
  1078. this.parentElId = sGroup;
  1079. }
  1080. this.logger = new YAHOO.widget.LogWriter(this.toString());
  1081. /**
  1082. * Overrides the isTarget property in YAHOO.util.DragDrop
  1083. * @property isTarget
  1084. * @private
  1085. */
  1086. this.isTarget = false;
  1087. /**
  1088. * The tick size for this slider
  1089. * @property tickSize
  1090. * @type int
  1091. * @private
  1092. */
  1093. this.tickSize = iTickSize;
  1094. /**
  1095. * Informs the drag and drop util that the offsets should remain when
  1096. * resetting the constraints. This preserves the slider value when
  1097. * the constraints are reset
  1098. * @property maintainOffset
  1099. * @type boolean
  1100. * @private
  1101. */
  1102. this.maintainOffset = true;
  1103. this.initSlider(iLeft, iRight, iUp, iDown, iTickSize);
  1104. /**
  1105. * Turns off the autoscroll feature in drag and drop
  1106. * @property scroll
  1107. * @private
  1108. */
  1109. this.scroll = false;
  1110. };
  1111. YAHOO.extend(YAHOO.widget.SliderThumb, YAHOO.util.DD, {
  1112. /**
  1113. * The (X and Y) difference between the thumb location and its parent
  1114. * (the slider background) when the control is instantiated.
  1115. * @property startOffset
  1116. * @type [int, int]
  1117. */
  1118. startOffset: null,
  1119. /**
  1120. * Override the default setting of dragOnly to true.
  1121. * @property dragOnly
  1122. * @type boolean
  1123. * @default true
  1124. */
  1125. dragOnly : true,
  1126. /**
  1127. * Flag used to figure out if this is a horizontal or vertical slider
  1128. * @property _isHoriz
  1129. * @type boolean
  1130. * @private
  1131. */
  1132. _isHoriz: false,
  1133. /**
  1134. * Cache the last value so we can check for change
  1135. * @property _prevVal
  1136. * @type int
  1137. * @private
  1138. */
  1139. _prevVal: 0,
  1140. /**
  1141. * The slider is _graduated if there is a tick interval defined
  1142. * @property _graduated
  1143. * @type boolean
  1144. * @private
  1145. */
  1146. _graduated: false,
  1147. /**
  1148. * Returns the difference between the location of the thumb and its parent.
  1149. * @method getOffsetFromParent
  1150. * @param {[int, int]} parentPos Optionally accepts the position of the parent
  1151. * @type [int, int]
  1152. */
  1153. getOffsetFromParent0: function(parentPos) {
  1154. var myPos = YAHOO.util.Dom.getXY(this.getEl()),
  1155. ppos = parentPos || YAHOO.util.Dom.getXY(this.parentElId);
  1156. return [ (myPos[0] - ppos[0]), (myPos[1] - ppos[1]) ];
  1157. },
  1158. getOffsetFromParent: function(parentPos) {
  1159. var el = this.getEl(), newOffset,
  1160. myPos,ppos,l,t,deltaX,deltaY,newLeft,newTop;
  1161. if (!this.deltaOffset) {
  1162. myPos = YAHOO.util.Dom.getXY(el);
  1163. ppos = parentPos || YAHOO.util.Dom.getXY(this.parentElId);
  1164. newOffset = [ (myPos[0] - ppos[0]), (myPos[1] - ppos[1]) ];
  1165. l = parseInt( YAHOO.util.Dom.getStyle(el, "left"), 10 );
  1166. t = parseInt( YAHOO.util.Dom.getStyle(el, "top" ), 10 );
  1167. deltaX = l - newOffset[0];
  1168. deltaY = t - newOffset[1];
  1169. if (isNaN(deltaX) || isNaN(deltaY)) {
  1170. this.logger.log("element does not have a position style def yet");
  1171. } else {
  1172. this.deltaOffset = [deltaX, deltaY];
  1173. }
  1174. } else {
  1175. newLeft = parseInt( YAHOO.util.Dom.getStyle(el, "left"), 10 );
  1176. newTop = parseInt( YAHOO.util.Dom.getStyle(el, "top" ), 10 );
  1177. newOffset = [newLeft + this.deltaOffset[0], newTop + this.deltaOffset[1]];
  1178. }
  1179. return newOffset;
  1180. },
  1181. /**
  1182. * Set up the slider, must be called in the constructor of all subclasses
  1183. * @method initSlider
  1184. * @param {int} iLeft the number of pixels the element can move left
  1185. * @param {int} iRight the number of pixels the element can move right
  1186. * @param {int} iUp the number of pixels the element can move up
  1187. * @param {int} iDown the number of pixels the element can move down
  1188. * @param {int} iTickSize the width of the tick interval.
  1189. */
  1190. initSlider: function (iLeft, iRight, iUp, iDown, iTickSize) {
  1191. this.initLeft = iLeft;
  1192. this.initRight = iRight;
  1193. this.initUp = iUp;
  1194. this.initDown = iDown;
  1195. this.setXConstraint(iLeft, iRight, iTickSize);
  1196. this.setYConstraint(iUp, iDown, iTickSize);
  1197. if (iTickSize && iTickSize > 1) {
  1198. this._graduated = true;
  1199. }
  1200. this._isHoriz = (iLeft || iRight);
  1201. this._isVert = (iUp || iDown);
  1202. this._isRegion = (this._isHoriz && this._isVert);
  1203. },
  1204. /**
  1205. * Clear's the slider's ticks
  1206. * @method clearTicks
  1207. */
  1208. clearTicks: function () {
  1209. YAHOO.widget.SliderThumb.superclass.clearTicks.call(this);
  1210. this.tickSize = 0;
  1211. this._graduated = false;
  1212. },
  1213. /**
  1214. * Gets the current offset from the element's start position in
  1215. * pixels.
  1216. * @method getValue
  1217. * @return {int} the number of pixels (positive or negative) the
  1218. * slider has moved from the start position.
  1219. */
  1220. getValue: function () {
  1221. return (this._isHoriz) ? this.getXValue() : this.getYValue();
  1222. },
  1223. /**
  1224. * Gets the current X offset from the element's start position in
  1225. * pixels.
  1226. * @method getXValue
  1227. * @return {int} the number of pixels (positive or negative) the
  1228. * slider has moved horizontally from the start position.
  1229. */
  1230. getXValue: function () {
  1231. if (!this.available) {
  1232. return 0;
  1233. }
  1234. var newOffset = this.getOffsetFromParent();
  1235. if (YAHOO.lang.isNumber(newOffset[0])) {
  1236. this.lastOffset = newOffset;
  1237. return (newOffset[0] - this.startOffset[0]);
  1238. } else {
  1239. this.logger.log("can't get offset, using old value: " +
  1240. this.lastOffset[0]);
  1241. return (this.lastOffset[0] - this.startOffset[0]);
  1242. }
  1243. },
  1244. /**
  1245. * Gets the current Y offset from the element's start position in
  1246. * pixels.
  1247. * @method getYValue
  1248. * @return {int} the number of pixels (positive or negative) the
  1249. * slider has moved vertically from the start position.
  1250. */
  1251. getYValue: function () {
  1252. if (!this.available) {
  1253. return 0;
  1254. }
  1255. var newOffset = this.getOffsetFromParent();
  1256. if (YAHOO.lang.isNumber(newOffset[1])) {
  1257. this.lastOffset = newOffset;
  1258. return (newOffset[1] - this.startOffset[1]);
  1259. } else {
  1260. this.logger.log("can't get offset, using old value: " +
  1261. this.lastOffset[1]);
  1262. return (this.lastOffset[1] - this.startOffset[1]);
  1263. }
  1264. },
  1265. /**
  1266. * Thumb toString
  1267. * @method toString
  1268. * @return {string} string representation of the instance
  1269. */
  1270. toString: function () {
  1271. return "SliderThumb " + this.id;
  1272. },
  1273. /**
  1274. * The onchange event for the handle/thumb is delegated to the YAHOO.widget.Slider
  1275. * instance it belongs to.
  1276. * @method onChange
  1277. * @private
  1278. */
  1279. onChange: function (x, y) {
  1280. }
  1281. });
  1282. /**
  1283. * A slider with two thumbs, one that represents the min value and
  1284. * the other the max. Actually a composition of two sliders, both with
  1285. * the same background. The constraints for each slider are adjusted
  1286. * dynamically so that the min value of the max slider is equal or greater
  1287. * to the current value of the min slider, and the max value of the min
  1288. * slider is the current value of the max slider.
  1289. * Constructor assumes both thumbs are positioned absolutely at the 0 mark on
  1290. * the background.
  1291. *
  1292. * @namespace YAHOO.widget
  1293. * @class DualSlider
  1294. * @uses YAHOO.util.EventProvider
  1295. * @constructor
  1296. * @param {Slider} minSlider The Slider instance used for the min value thumb
  1297. * @param {Slider} maxSlider The Slider instance used for the max value thumb
  1298. * @param {int} range The number of pixels the thumbs may move within
  1299. * @param {Array} initVals (optional) [min,max] Initial thumb placement
  1300. */
  1301. (function () {
  1302. var Event = YAHOO.util.Event,
  1303. YW = YAHOO.widget;
  1304. function DualSlider(minSlider, maxSlider, range, initVals) {
  1305. var self = this,
  1306. ready = { min : false, max : false },
  1307. minThumbOnMouseDown, maxThumbOnMouseDown;
  1308. /**
  1309. * A slider instance that keeps track of the lower value of the range.
  1310. * <strong>read only</strong>
  1311. * @property minSlider
  1312. * @type Slider
  1313. */
  1314. this.minSlider = minSlider;
  1315. /**
  1316. * A slider instance that keeps track of the upper value of the range.
  1317. * <strong>read only</strong>
  1318. * @property maxSlider
  1319. * @type Slider
  1320. */
  1321. this.maxSlider = maxSlider;
  1322. /**
  1323. * The currently active slider (min or max). <strong>read only</strong>
  1324. * @property activeSlider
  1325. * @type Slider
  1326. */
  1327. this.activeSlider = minSlider;
  1328. /**
  1329. * Is the DualSlider oriented horizontally or vertically?
  1330. * <strong>read only</strong>
  1331. * @property isHoriz
  1332. * @type boolean
  1333. */
  1334. this.isHoriz = minSlider.thumb._isHoriz;
  1335. //FIXME: this is horrible
  1336. minThumbOnMouseDown = this.minSlider.thumb.onMouseDown;
  1337. maxThumbOnMouseDown = this.maxSlider.thumb.onMouseDown;
  1338. this.minSlider.thumb.onMouseDown = function() {
  1339. self.activeSlider = self.minSlider;
  1340. minThumbOnMouseDown.apply(this,arguments);
  1341. };
  1342. this.maxSlider.thumb.onMouseDown = function () {
  1343. self.activeSlider = self.maxSlider;
  1344. maxThumbOnMouseDown.apply(this,arguments);
  1345. };
  1346. this.minSlider.thumb.onAvailable = function () {
  1347. minSlider.setStartSliderState();
  1348. ready.min = true;
  1349. if (ready.max) {
  1350. self.fireEvent('ready',self);
  1351. }
  1352. };
  1353. this.maxSlider.thumb.onAvailable = function () {
  1354. maxSlider.setStartSliderState();
  1355. ready.max = true;
  1356. if (ready.min) {
  1357. self.fireEvent('ready',self);
  1358. }
  1359. };
  1360. // dispatch mousedowns to the active slider
  1361. minSlider.onMouseDown =
  1362. maxSlider.onMouseDown = function(e) {
  1363. return this.backgroundEnabled && self._handleMouseDown(e);
  1364. };
  1365. // Fix the drag behavior so that only the active slider
  1366. // follows the drag
  1367. minSlider.onDrag =
  1368. maxSlider.onDrag = function(e) {
  1369. self._handleDrag(e);
  1370. };
  1371. // Likely only the minSlider's onMouseUp will be executed, but both are
  1372. // overridden just to be safe
  1373. minSlider.onMouseUp =
  1374. maxSlider.onMouseUp = function (e) {
  1375. self._handleMouseUp(e);
  1376. };
  1377. // Replace the _bindKeyEvents for the minSlider and remove that for the
  1378. // maxSlider since they share the same bg element.
  1379. minSlider._bindKeyEvents = function () {
  1380. self._bindKeyEvents(this);
  1381. };
  1382. maxSlider._bindKeyEvents = function () {};
  1383. // The core events for each slider are handled so we can expose a single
  1384. // event for when the event happens on either slider
  1385. minSlider.subscribe("change", this._handleMinChange, minSlider, this);
  1386. minSlider.subscribe("slideStart", this._handleSlideStart, minSlider, this);
  1387. minSlider.subscribe("slideEnd", this._handleSlideEnd, minSlider, this);
  1388. maxSlider.subscribe("change", this._handleMaxChange, maxSlider, this);
  1389. maxSlider.subscribe("slideStart", this._handleSlideStart, maxSlider, this);
  1390. maxSlider.subscribe("slideEnd", this._handleSlideEnd, maxSlider, this);
  1391. /**
  1392. * Event that fires when the slider is finished setting up
  1393. * @event ready
  1394. * @param {DualSlider} dualslider the DualSlider instance
  1395. */
  1396. this.createEvent("ready", this);
  1397. /**
  1398. * Event that fires when either the min or max value changes
  1399. * @event change
  1400. * @param {DualSlider} dualslider the DualSlider instance
  1401. */
  1402. this.createEvent("change", this);
  1403. /**
  1404. * Event that fires when one of the thumbs begins to move
  1405. * @event slideStart
  1406. * @param {Slider} activeSlider the moving slider
  1407. */
  1408. this.createEvent("slideStart", this);
  1409. /**
  1410. * Event that fires when one of the thumbs finishes moving
  1411. * @event slideEnd
  1412. * @param {Slider} activeSlider the moving slider
  1413. */
  1414. this.createEvent("slideEnd", this);
  1415. // Validate initial values
  1416. initVals = YAHOO.lang.isArray(initVals) ? initVals : [0,range];
  1417. initVals[0] = Math.min(Math.max(parseInt(initVals[0],10)|0,0),range);
  1418. initVals[1] = Math.max(Math.min(parseInt(initVals[1],10)|0,range),0);
  1419. // Swap initVals if min > max
  1420. if (initVals[0] > initVals[1]) {
  1421. initVals.splice(0,2,initVals[1],initVals[0]);
  1422. }
  1423. this.minVal = initVals[0];
  1424. this.maxVal = initVals[1];
  1425. // Set values so initial assignment when the slider thumbs are ready will
  1426. // use these values
  1427. this.minSlider.setValue(this.minVal,true,true,true);
  1428. this.maxSlider.setValue(this.maxVal,true,true,true);
  1429. YAHOO.log("Setting initial values " + this.minVal + ", " + this.maxVal,"info","DualSlider");
  1430. }
  1431. DualSlider.prototype = {
  1432. /**
  1433. * The current value of the min thumb. <strong>read only</strong>.
  1434. * @property minVal
  1435. * @type int
  1436. */
  1437. minVal : -1,
  1438. /**
  1439. * The current value of the max thumb. <strong>read only</strong>.
  1440. * @property maxVal
  1441. * @type int
  1442. */
  1443. maxVal : -1,
  1444. /**
  1445. * Pixel distance to maintain between thumbs.
  1446. * @property minRange
  1447. * @type int
  1448. * @default 0
  1449. */
  1450. minRange : 0,
  1451. /**
  1452. * Executed when one of the sliders fires the slideStart event
  1453. * @method _handleSlideStart
  1454. * @private
  1455. */
  1456. _handleSlideStart: function(data, slider) {
  1457. this.fireEvent("slideStart", slider);
  1458. },
  1459. /**
  1460. * Executed when one of the sliders fires the slideEnd event
  1461. * @method _handleSlideEnd
  1462. * @private
  1463. */
  1464. _handleSlideEnd: function(data, slider) {
  1465. this.fireEvent("slideEnd", slider);
  1466. },
  1467. /**
  1468. * Overrides the onDrag method for both sliders
  1469. * @method _handleDrag
  1470. * @private
  1471. */
  1472. _handleDrag: function(e) {
  1473. YW.Slider.prototype.onDrag.call(this.activeSlider, e);
  1474. },
  1475. /**
  1476. * Executed when the min slider fires the change event
  1477. * @method _handleMinChange
  1478. * @private
  1479. */
  1480. _handleMinChange: function() {
  1481. this.activeSlider = this.minSlider;
  1482. this.updateValue();
  1483. },
  1484. /**
  1485. * Executed when the max slider fires the change event
  1486. * @method _handleMaxChange
  1487. * @private
  1488. */
  1489. _handleMaxChange: function() {
  1490. this.activeSlider = this.maxSlider;
  1491. this.updateValue();
  1492. },
  1493. /**
  1494. * Set up the listeners for the keydown and keypress events.
  1495. *
  1496. * @method _bindKeyEvents
  1497. * @protected
  1498. */
  1499. _bindKeyEvents : function (slider) {
  1500. Event.on(slider.id,'keydown', this._handleKeyDown, this,true);
  1501. Event.on(slider.id,'keypress',this._handleKeyPress,this,true);
  1502. },
  1503. /**
  1504. * Delegate event handling to the active Slider. See Slider.handleKeyDown.
  1505. *
  1506. * @method _handleKeyDown
  1507. * @param e {Event} the mousedown DOM event
  1508. * @protected
  1509. */
  1510. _handleKeyDown : function (e) {
  1511. this.activeSlider.handleKeyDown.apply(this.activeSlider,arguments);
  1512. },
  1513. /**
  1514. * Delegate event handling to the active Slider. See Slider.handleKeyPress.
  1515. *
  1516. * @method _handleKeyPress
  1517. * @param e {Event} the mousedown DOM event
  1518. * @protected
  1519. */
  1520. _handleKeyPress : function (e) {
  1521. this.activeSlider.handleKeyPress.apply(this.activeSlider,arguments);
  1522. },
  1523. /**
  1524. * Sets the min and max thumbs to new values.
  1525. * @method setValues
  1526. * @param min {int} Pixel offset to assign to the min thumb
  1527. * @param max {int} Pixel offset to assign to the max thumb
  1528. * @param skipAnim {boolean} (optional) Set to true to skip thumb animation.
  1529. * Default false
  1530. * @param force {boolean} (optional) ignore the locked setting and set
  1531. * value anyway. Default false
  1532. * @param silent {boolean} (optional) Set to true to skip firing change
  1533. * events. Default false
  1534. */
  1535. setValues : function (min, max, skipAnim, force, silent) {
  1536. var mins = this.minSlider,
  1537. maxs = this.maxSlider,
  1538. mint = mins.thumb,
  1539. maxt = maxs.thumb,
  1540. self = this,
  1541. done = { min : false, max : false };
  1542. // Clear constraints to prevent animated thumbs from prematurely
  1543. // stopping when hitting a constraint that's moving with the other
  1544. // thumb.
  1545. if (mint._isHoriz) {
  1546. mint.setXConstraint(mint.leftConstraint,maxt.rightConstraint,mint.tickSize);
  1547. maxt.setXConstraint(mint.leftConstraint,maxt.rightConstraint,maxt.tickSize);
  1548. } else {
  1549. mint.setYConstraint(mint.topConstraint,maxt.bottomConstraint,mint.tickSize);
  1550. maxt.setYConstraint(mint.topConstraint,maxt.bottomConstraint,maxt.tickSize);
  1551. }
  1552. // Set up one-time slideEnd callbacks to call updateValue when both
  1553. // thumbs have been set
  1554. this._oneTimeCallback(mins,'slideEnd',function () {
  1555. done.min = true;
  1556. if (done.max) {
  1557. self.updateValue(silent);
  1558. // Clean the slider's slideEnd events on a timeout since this
  1559. // will be executed from inside the event's fire
  1560. setTimeout(function () {
  1561. self._cleanEvent(mins,'slideEnd');
  1562. self._cleanEvent(maxs,'slideEnd');
  1563. },0);
  1564. }
  1565. });
  1566. this._oneTimeCallback(maxs,'slideEnd',function () {
  1567. done.max = true;
  1568. if (done.min) {
  1569. self.updateValue(silent);
  1570. // Clean both sliders' slideEnd events on a timeout since this
  1571. // will be executed from inside one of the event's fire
  1572. setTimeout(function () {
  1573. self._cleanEvent(mins,'slideEnd');
  1574. self._cleanEvent(maxs,'slideEnd');
  1575. },0);
  1576. }
  1577. });
  1578. // Must emit Slider slideEnd event to propagate to updateValue
  1579. mins.setValue(min,skipAnim,force,false);
  1580. maxs.setValue(max,skipAnim,force,false);
  1581. },
  1582. /**
  1583. * Set the min thumb position to a new value.
  1584. * @method setMinValue
  1585. * @param min {int} Pixel offset for min thumb
  1586. * @param skipAnim {boolean} (optional) Set to true to skip thumb animation.
  1587. * Default false
  1588. * @param force {boolean} (optional) ignore the locked setting and set
  1589. * value anyway. Default false
  1590. * @param silent {boolean} (optional) Set to true to skip firing change
  1591. * events. Default false
  1592. */
  1593. setMinValue : function (min, skipAnim, force, silent) {
  1594. var mins = this.minSlider,
  1595. self = this;
  1596. this.activeSlider = mins;
  1597. // Use a one-time event callback to delay the updateValue call
  1598. // until after the slide operation is done
  1599. self = this;
  1600. this._oneTimeCallback(mins,'slideEnd',function () {
  1601. self.updateValue(silent);
  1602. // Clean the slideEnd event on a timeout since this
  1603. // will be executed from inside the event's fire
  1604. setTimeout(function () { self._cleanEvent(mins,'slideEnd'); }, 0);
  1605. });
  1606. mins.setValue(min, skipAnim, force);
  1607. },
  1608. /**
  1609. * Set the max thumb position to a new value.
  1610. * @method setMaxValue
  1611. * @param max {int} Pixel offset for max thumb
  1612. * @param skipAnim {boolean} (optional) Set to true to skip thumb animation.
  1613. * Default false
  1614. * @param force {boolean} (optional) ignore the locked setting and set
  1615. * value anyway. Default false
  1616. * @param silent {boolean} (optional) Set to true to skip firing change
  1617. * events. Default false
  1618. */
  1619. setMaxValue : function (max, skipAnim, force, silent) {
  1620. var maxs = this.maxSlider,
  1621. self = this;
  1622. this.activeSlider = maxs;
  1623. // Use a one-time event callback to delay the updateValue call
  1624. // until after the slide operation is done
  1625. this._oneTimeCallback(maxs,'slideEnd',function () {
  1626. self.updateValue(silent);
  1627. // Clean the slideEnd event on a timeout since this
  1628. // will be executed from inside the event's fire
  1629. setTimeout(function () { self._cleanEvent(maxs,'slideEnd'); }, 0);
  1630. });
  1631. maxs.setValue(max, skipAnim, force);
  1632. },
  1633. /**
  1634. * Executed when one of the sliders is moved
  1635. * @method updateValue
  1636. * @param silent {boolean} (optional) Set to true to skip firing change
  1637. * events. Default false
  1638. * @private
  1639. */
  1640. updateValue: function(silent) {
  1641. var min = this.minSlider.getValue(),
  1642. max = this.maxSlider.getValue(),
  1643. changed = false,
  1644. mint,maxt,dim,minConstraint,maxConstraint,thumbInnerWidth;
  1645. if (min != this.minVal || max != this.maxVal) {
  1646. changed = true;
  1647. mint = this.minSlider.thumb;
  1648. maxt = this.maxSlider.thumb;
  1649. dim = this.isHoriz ? 'x' : 'y';
  1650. thumbInnerWidth = this.minSlider.thumbCenterPoint[dim] +
  1651. this.maxSlider.thumbCenterPoint[dim];
  1652. // Establish barriers within the respective other thumb's edge, less
  1653. // the minRange. Limit to the Slider's range in the case of
  1654. // negative minRanges.
  1655. minConstraint = Math.max(max-thumbInnerWidth-this.minRange,0);
  1656. maxConstraint = Math.min(-min-thumbInnerWidth-this.minRange,0);
  1657. if (this.isHoriz) {
  1658. minConstraint = Math.min(minConstraint,maxt.rightConstraint);
  1659. mint.setXConstraint(mint.leftConstraint,minConstraint, mint.tickSize);
  1660. maxt.setXConstraint(maxConstraint,maxt.rightConstraint, maxt.tickSize);
  1661. } else {
  1662. minConstraint = Math.min(minConstraint,maxt.bottomConstraint);
  1663. mint.setYConstraint(mint.leftConstraint,minConstraint, mint.tickSize);
  1664. maxt.setYConstraint(maxConstraint,maxt.bottomConstraint, maxt.tickSize);
  1665. }
  1666. }
  1667. this.minVal = min;
  1668. this.maxVal = max;
  1669. if (changed && !silent) {
  1670. this.fireEvent("change", this);
  1671. }
  1672. },
  1673. /**
  1674. * A background click will move the slider thumb nearest to the click.
  1675. * Override if you need different behavior.
  1676. * @method selectActiveSlider
  1677. * @param e {Event} the mousedown event
  1678. * @private
  1679. */
  1680. selectActiveSlider: function(e) {
  1681. var min = this.minSlider,
  1682. max = this.maxSlider,
  1683. minLocked = min.isLocked() || !min.backgroundEnabled,
  1684. maxLocked = max.isLocked() || !min.backgroundEnabled,
  1685. Ev = YAHOO.util.Event,
  1686. d;
  1687. if (minLocked || maxLocked) {
  1688. this.activeSlider = minLocked ? max : min;
  1689. } else {
  1690. if (this.isHoriz) {
  1691. d = Ev.getPageX(e)-min.thumb.initPageX-min.thumbCenterPoint.x;
  1692. } else {
  1693. d = Ev.getPageY(e)-min.thumb.initPageY-min.thumbCenterPoint.y;
  1694. }
  1695. this.activeSlider = d*2 > max.getValue()+min.getValue() ? max : min;
  1696. }
  1697. },
  1698. /**
  1699. * Delegates the onMouseDown to the appropriate Slider
  1700. *
  1701. * @method _handleMouseDown
  1702. * @param e {Event} mouseup event
  1703. * @protected
  1704. */
  1705. _handleMouseDown: function(e) {
  1706. if (!e._handled && !this.minSlider._sliding && !this.maxSlider._sliding) {
  1707. e._handled = true;
  1708. this.selectActiveSlider(e);
  1709. return YW.Slider.prototype.onMouseDown.call(this.activeSlider, e);
  1710. } else {
  1711. return false;
  1712. }
  1713. },
  1714. /**
  1715. * Delegates the onMouseUp to the active Slider
  1716. *
  1717. * @method _handleMouseUp
  1718. * @param e {Event} mouseup event
  1719. * @protected
  1720. */
  1721. _handleMouseUp : function (e) {
  1722. YW.Slider.prototype.onMouseUp.apply(
  1723. this.activeSlider, arguments);
  1724. },
  1725. /**
  1726. * Schedule an event callback that will execute once, then unsubscribe
  1727. * itself.
  1728. * @method _oneTimeCallback
  1729. * @param o {EventProvider} Object to attach the event to
  1730. * @param evt {string} Name of the event
  1731. * @param fn {Function} function to execute once
  1732. * @private
  1733. */
  1734. _oneTimeCallback : function (o,evt,fn) {
  1735. var sub = function () {
  1736. // Unsubscribe myself
  1737. o.unsubscribe(evt, sub);
  1738. // Pass the event handler arguments to the one time callback
  1739. fn.apply({},arguments);
  1740. };
  1741. o.subscribe(evt,sub);
  1742. },
  1743. /**
  1744. * Clean up the slideEnd event subscribers array, since each one-time
  1745. * callback will be replaced in the event's subscribers property with
  1746. * null. This will cause memory bloat and loss of performance.
  1747. * @method _cleanEvent
  1748. * @param o {EventProvider} object housing the CustomEvent
  1749. * @param evt {string} name of the CustomEvent
  1750. * @private
  1751. */
  1752. _cleanEvent : function (o,evt) {
  1753. var ce,i,len,j,subs,newSubs;
  1754. if (o.__yui_events && o.events[evt]) {
  1755. for (i = o.__yui_events.length; i >= 0; --i) {
  1756. if (o.__yui_events[i].type === evt) {
  1757. ce = o.__yui_events[i];
  1758. break;
  1759. }
  1760. }
  1761. if (ce) {
  1762. subs = ce.subscribers;
  1763. newSubs = [];
  1764. j = 0;
  1765. for (i = 0, len = subs.length; i < len; ++i) {
  1766. if (subs[i]) {
  1767. newSubs[j++] = subs[i];
  1768. }
  1769. }
  1770. ce.subscribers = newSubs;
  1771. }
  1772. }
  1773. }
  1774. };
  1775. YAHOO.lang.augmentProto(DualSlider, YAHOO.util.EventProvider);
  1776. /**
  1777. * Factory method for creating a horizontal dual-thumb slider
  1778. * @for YAHOO.widget.Slider
  1779. * @method YAHOO.widget.Slider.getHorizDualSlider
  1780. * @static
  1781. * @param {String} bg the id of the slider's background element
  1782. * @param {String} minthumb the id of the min thumb
  1783. * @param {String} maxthumb the id of the thumb thumb
  1784. * @param {int} range the number of pixels the thumbs can move within
  1785. * @param {int} iTickSize (optional) the element should move this many pixels
  1786. * at a time
  1787. * @param {Array} initVals (optional) [min,max] Initial thumb placement
  1788. * @return {DualSlider} a horizontal dual-thumb slider control
  1789. */
  1790. YW.Slider.getHorizDualSlider =
  1791. function (bg, minthumb, maxthumb, range, iTickSize, initVals) {
  1792. var mint = new YW.SliderThumb(minthumb, bg, 0, range, 0, 0, iTickSize),
  1793. maxt = new YW.SliderThumb(maxthumb, bg, 0, range, 0, 0, iTickSize);
  1794. return new DualSlider(
  1795. new YW.Slider(bg, bg, mint, "horiz"),
  1796. new YW.Slider(bg, bg, maxt, "horiz"),
  1797. range, initVals);
  1798. };
  1799. /**
  1800. * Factory method for creating a vertical dual-thumb slider.
  1801. * @for YAHOO.widget.Slider
  1802. * @method YAHOO.widget.Slider.getVertDualSlider
  1803. * @static
  1804. * @param {String} bg the id of the slider's background element
  1805. * @param {String} minthumb the id of the min thumb
  1806. * @param {String} maxthumb the id of the thumb thumb
  1807. * @param {int} range the number of pixels the thumbs can move within
  1808. * @param {int} iTickSize (optional) the element should move this many pixels
  1809. * at a time
  1810. * @param {Array} initVals (optional) [min,max] Initial thumb placement
  1811. * @return {DualSlider} a vertical dual-thumb slider control
  1812. */
  1813. YW.Slider.getVertDualSlider =
  1814. function (bg, minthumb, maxthumb, range, iTickSize, initVals) {
  1815. var mint = new YW.SliderThumb(minthumb, bg, 0, 0, 0, range, iTickSize),
  1816. maxt = new YW.SliderThumb(maxthumb, bg, 0, 0, 0, range, iTickSize);
  1817. return new YW.DualSlider(
  1818. new YW.Slider(bg, bg, mint, "vert"),
  1819. new YW.Slider(bg, bg, maxt, "vert"),
  1820. range, initVals);
  1821. };
  1822. YAHOO.widget.DualSlider = DualSlider;
  1823. })();
  1824. YAHOO.register("slider", YAHOO.widget.Slider, {version: "2.8.0r4", build: "2449"});