progressbar.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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. *
  9. * @module progressbar
  10. * @requires yahoo, dom, event, element
  11. * @optional animation
  12. * @title ProgressBar Widget
  13. */
  14. (function () {
  15. var Dom = YAHOO.util.Dom,
  16. Lang = YAHOO.lang,
  17. // ClassNames
  18. CLASS_PROGBAR = 'yui-pb',
  19. CLASS_MASK = CLASS_PROGBAR + '-mask',
  20. CLASS_BAR = CLASS_PROGBAR + '-bar',
  21. CLASS_ANIM = CLASS_PROGBAR + '-anim',
  22. CLASS_TL = CLASS_PROGBAR + '-tl',
  23. CLASS_TR = CLASS_PROGBAR + '-tr',
  24. CLASS_BL = CLASS_PROGBAR + '-bl',
  25. CLASS_BR = CLASS_PROGBAR + '-br',
  26. // Configuration attributes
  27. WIDTH = 'width',
  28. HEIGHT = 'height',
  29. MIN_VALUE = 'minValue',
  30. MAX_VALUE = 'maxValue',
  31. VALUE = 'value',
  32. ANIM = 'anim',
  33. DIRECTION = 'direction',
  34. DIRECTION_LTR = 'ltr',
  35. DIRECTION_RTL = 'rtl',
  36. DIRECTION_TTB = 'ttb',
  37. DIRECTION_BTT = 'btt',
  38. BAR_EL = 'barEl',
  39. MASK_EL = 'maskEl',
  40. ARIA_TEXT_TEMPLATE = 'ariaTextTemplate',
  41. // Events
  42. START = 'start',
  43. PROGRESS = 'progress',
  44. COMPLETE = 'complete';
  45. /**
  46. * The ProgressBar widget provides an easy way to draw a bar depicting progress of an operation,
  47. * a level meter, rating or any such simple linear measure.
  48. * It allows for highly customized styles including animation, vertical or horizontal and forward or reverse.
  49. * @namespace YAHOO.widget
  50. * @class ProgressBar
  51. * @extends YAHOO.util.Element
  52. * @param oConfigs {object} An object containing any configuration attributes to be set
  53. * @constructor
  54. */
  55. var Prog = function(oConfigs) {
  56. Prog.superclass.constructor.call(this, document.createElement('div') , oConfigs);
  57. this._init(oConfigs);
  58. };
  59. YAHOO.widget.ProgressBar = Prog;
  60. /**
  61. * String containing the HTML string which is the basis for the Progress Bar.
  62. *
  63. * @property ProgressBar.MARKUP
  64. * @type String
  65. * @static
  66. * @final
  67. * @default (too long)
  68. */
  69. Prog.MARKUP = [
  70. '<div class="',
  71. CLASS_BAR,
  72. '"></div><div class="',
  73. CLASS_MASK,
  74. '"><div class="',
  75. CLASS_TL,
  76. '"></div><div class="',
  77. CLASS_TR,
  78. '"></div><div class="',
  79. CLASS_BL,
  80. '"></div><div class="',
  81. CLASS_BR,
  82. '"></div></div>'
  83. ].join('');
  84. Lang.extend(Prog, YAHOO.util.Element, {
  85. /**
  86. * Initialization code for the widget, separate from the constructor to allow for overriding/patching.
  87. * It is called after <a href="#method_initAttributes">initAttributes</a>
  88. *
  89. * @method _init
  90. * @param oConfigs {Object} (Optional) Object literal definition of configuration values.
  91. * @protected
  92. */
  93. _init: function (oConfigs) {
  94. /**
  95. * Fires when the value is about to change. It reports the starting value
  96. * @event start
  97. * @type CustomEvent
  98. * @param value {Number} the current (initial) value
  99. */
  100. // No actual creation required, event will be created when subscribed to
  101. //this.createEvent(START);
  102. /**
  103. * If animation is active, it will trigger several times during the animation providing intermediate values
  104. * If animation is not active, it will fire only once providing the end value
  105. * @event progress
  106. * @type CustomEvent
  107. * @param value{Number} the current, changing value
  108. */
  109. // No actual creation required, event will be created when subscribed to
  110. //this.createEvent(PROGRESS);
  111. /**
  112. * Fires at the end of the animation or immediately upon changing values if animation is not loaded
  113. * @event complete
  114. * @type CustomEvent
  115. * @param value {Number} the current (final) value
  116. */
  117. // No actual creation required, event will be created when listened to
  118. //this.createEvent(COMPLETE);
  119. },
  120. /**
  121. * Implementation of Element's abstract method. Sets up config values.
  122. *
  123. * @method initAttributes
  124. * @param oConfigs {Object} (Optional) Object literal definition of configuration values.
  125. * @private
  126. */
  127. initAttributes: function (oConfigs) {
  128. Prog.superclass.initAttributes.call(this, oConfigs);
  129. this.set('innerHTML',Prog.MARKUP);
  130. this.addClass(CLASS_PROGBAR);
  131. // I need to apply at least the following styles, if present in oConfigs,
  132. // to the ProgressBar so when it later reads the width and height,
  133. // they are already set to the correct values.
  134. // id is important because it can be used as a CSS selector.
  135. var key, presets = ['id',WIDTH,HEIGHT,'class','style'];
  136. while((key = presets.pop())) {
  137. if (key in oConfigs) {
  138. this.set(key,oConfigs[key]);
  139. }
  140. }
  141. /**
  142. * @attribute barEl
  143. * @description Reference to the HTML object that makes the moving bar (read-only)
  144. * @type HTMLElement (div)
  145. * @readonly
  146. */
  147. this.setAttributeConfig(BAR_EL, {
  148. readOnly: true,
  149. value: this.getElementsByClassName(CLASS_BAR)[0]
  150. });
  151. /**
  152. * @attribute maskEl
  153. * @description Reference to the HTML object that overlays the bar providing the mask. (read-only)
  154. * @type HTMLElement (table)
  155. * @readonly
  156. */
  157. this.setAttributeConfig(MASK_EL, {
  158. readOnly: true,
  159. value: this.getElementsByClassName(CLASS_MASK)[0]
  160. });
  161. /**
  162. * @attribute direction
  163. * @description Direction of movement of the bar.
  164. * It can be any of 'ltr' (left to right), 'rtl' (the reverse) , 'ttb' (top to bottom) or 'btt'.
  165. * Can only be set once and only before rendering.
  166. * @default 'ltr'
  167. * @type String (any of "ltr", "rtl", "ttb" or "btt")
  168. */
  169. this.setAttributeConfig(DIRECTION, {
  170. value:DIRECTION_LTR,
  171. validator:function(value) {
  172. if (this._rendered) { return false; }
  173. switch (value) {
  174. case DIRECTION_LTR:
  175. case DIRECTION_RTL:
  176. case DIRECTION_TTB:
  177. case DIRECTION_BTT:
  178. return true;
  179. default:
  180. return false;
  181. }
  182. },
  183. method: function(value) {
  184. this._barSizeFunction = this._barSizeFunctions[this.get(ANIM)?1:0][value];
  185. }
  186. });
  187. /**
  188. * @attribute maxValue
  189. * @description Represents the top value for the bar.
  190. * The bar will be fully extended when reaching this value.
  191. * Values higher than this will be ignored.
  192. * @default 100
  193. * @type Number
  194. */
  195. this.setAttributeConfig(MAX_VALUE, {
  196. value: 100,
  197. validator: Lang.isNumber,
  198. method: function (value) {
  199. this.get('element').setAttribute('aria-valuemax',value);
  200. if (this.get(VALUE) > value) { this.set(VALUE,value); }
  201. }
  202. });
  203. /**
  204. * @attribute minValue
  205. * @description Represents the lowest value for the bar.
  206. * The bar will be totally collapsed when reaching this value.
  207. * Values lower than this will be ignored.
  208. * @default 0
  209. * @type Number
  210. */
  211. this.setAttributeConfig(MIN_VALUE, {
  212. value: 0,
  213. validator: Lang.isNumber,
  214. method: function (value) {
  215. this.get('element').setAttribute('aria-valuemin',value);
  216. if (this.get(VALUE) < value) { this.set(VALUE,value); }
  217. }
  218. });
  219. /**
  220. * @attribute width
  221. * @description Width of the ProgressBar.
  222. * If a number, it will be assumed to be in pixels.
  223. * If a string it should be a valid setting for the CSS width attribute.
  224. * It will always be returned as a string including units.
  225. * @default "200px"
  226. * @type Number or String
  227. */
  228. this.setAttributeConfig(WIDTH, {
  229. getter: function() {
  230. return this.getStyle(WIDTH);
  231. },
  232. method: this._widthChange
  233. });
  234. /**
  235. * @attribute height
  236. * @description Height of the ProgressBar.
  237. * If a number, it will be assumed to be in pixels.
  238. * If a string it should be a valid setting for the CSS height attribute.
  239. * It will always be returned as a string including units.
  240. * @default "20px"
  241. * @type Number or String
  242. */
  243. this.setAttributeConfig(HEIGHT, {
  244. getter:function() {
  245. return this.getStyle(HEIGHT);
  246. },
  247. method: this._heightChange
  248. });
  249. /**
  250. * @attribute ariaTextTemplate
  251. * @description Text to be voiced by screen readers.
  252. * The text is processed by <a href="YAHOO.lang.html#method_substitute">YAHOO.lang.substitute</a>.
  253. * It can use the placeholders {value}, {minValue} and {maxValue}
  254. * @default "{value}"
  255. * @type String
  256. */
  257. this.setAttributeConfig(ARIA_TEXT_TEMPLATE, {
  258. value:'{value}'
  259. });
  260. /**
  261. * @attribute value
  262. * @description The value for the bar.
  263. * Valid values are in between the minValue and maxValue attributes.
  264. * @default 0
  265. * @type Number
  266. */
  267. this.setAttributeConfig(VALUE, {
  268. value: 0,
  269. validator: function(value) {
  270. return Lang.isNumber(value) && value >= this.get(MIN_VALUE) && value <= this.get(MAX_VALUE);
  271. },
  272. method: this._valueChange
  273. });
  274. /**
  275. * @attribute anim
  276. * @description it accepts either a boolean (recommended) or an instance of <a href="YAHOO.util.Anim.html">YAHOO.util.Anim</a>.
  277. * If a boolean, it will enable/disable animation creating its own instance of the animation utility.
  278. * If given an instance of <a href="YAHOO.util.Anim.html">YAHOO.util.Anim</a> it will use that instance.
  279. * The <a href="YAHOO.util.Anim.html">animation</a> utility needs to be loaded.
  280. * When read, it returns the instance of the animation utility in use or null if none.
  281. * It can be used to set the animation parameters such as easing methods or duration.
  282. * @default null
  283. * @type {boolean} or {instance of YAHOO.util.Anim}
  284. */
  285. this.setAttributeConfig(ANIM, {
  286. validator: function(value) {
  287. return !!YAHOO.util.Anim;
  288. },
  289. setter: this._animSetter
  290. });
  291. },
  292. /**
  293. * Renders the ProgressBar into the given container.
  294. * If the container has other content, the ProgressBar will be appended to it.
  295. * If the second argument is provided, the ProgressBar will be inserted before the given child.
  296. * The method is chainable since it returns a reference to this instance.
  297. * @method render
  298. * @param el {HTML Element} HTML element that will contain the ProgressBar
  299. * @param before {HTML Element} (optional) If present, the ProgressBar will be inserted before this element.
  300. * @return {YAHOO.widget.ProgressBar}
  301. * @chainable
  302. */
  303. render: function(parent,before) {
  304. if (this._rendered) { return; }
  305. this._rendered = true;
  306. var direction = this.get(DIRECTION);
  307. // If the developer set a className attribute on initialization,
  308. // Element would have wiped out my own classNames
  309. // So I need to insist on them, plus add the one for direction.
  310. this.addClass(CLASS_PROGBAR);
  311. this.addClass(CLASS_PROGBAR + '-' + direction);
  312. var container = this.get('element');
  313. container.tabIndex = 0;
  314. container.setAttribute('role','progressbar');
  315. container.setAttribute('aria-valuemin',this.get(MIN_VALUE));
  316. container.setAttribute('aria-valuemax',this.get(MAX_VALUE));
  317. this.appendTo(parent,before);
  318. // I need to use the non-animated bar resizing function for initial redraw
  319. this._barSizeFunction = this._barSizeFunctions[0][direction];
  320. this.redraw();
  321. this._previousValue = this.get(VALUE);
  322. this._fixEdges();
  323. // I can now set the correct bar resizer
  324. if (this.get(ANIM)) {
  325. this._barSizeFunction = this._barSizeFunctions[1][direction];
  326. }
  327. this.on('minValueChange',this.redraw);
  328. this.on('maxValueChange',this.redraw);
  329. return this;
  330. },
  331. /**
  332. * Recalculates the bar size and position and redraws it
  333. * @method redraw
  334. * @return void
  335. */
  336. redraw: function () {
  337. this._recalculateConstants();
  338. this._valueChange(this.get(VALUE));
  339. },
  340. /**
  341. * Destroys the ProgressBar, related objects and unsubscribes from all events
  342. * @method destroy
  343. * @return void
  344. */
  345. destroy: function() {
  346. this.set(ANIM,false);
  347. this.unsubscribeAll();
  348. var el = this.get('element');
  349. if (el.parentNode) { el.parentNode.removeChild(el); }
  350. },
  351. /**
  352. * The previous value setting for the bar. Used mostly as information to event listeners
  353. * @property _previousValue
  354. * @type Number
  355. * @private
  356. * @default 0
  357. */
  358. _previousValue:0,
  359. /**
  360. * The actual space (in pixels) available for the bar within the mask (excludes margins)
  361. * @property _barSpace
  362. * @type Number
  363. * @private
  364. * @default 100
  365. */
  366. _barSpace:100,
  367. /**
  368. * The factor to convert the actual value of the bar into pixels
  369. * @property _barSpace
  370. * @type Number
  371. * @private
  372. * @default 1
  373. */
  374. _barFactor:1,
  375. /**
  376. * A flag to signal that rendering has already happened
  377. * @property _rendered
  378. * @type boolean
  379. * @private
  380. * @default false
  381. */
  382. _rendered:false,
  383. /**
  384. * Function to be used to calculate bar size.
  385. * It is picked from <a href="#property_barSizeFunctions">_barSizeFunctions</a>
  386. * depending on direction and whether animation is active.
  387. * @property _barSizeFunction
  388. * @type {function}
  389. * @default null
  390. * @private
  391. */
  392. _barSizeFunction: null,
  393. /**
  394. * Method called when the height attribute is changed
  395. * @method _heightChange
  396. * @param {int or string} value New height, in pixels if int or string including units
  397. * @return void
  398. * @private
  399. */
  400. _heightChange: function(value) {
  401. if (Lang.isNumber(value)) {
  402. value += 'px';
  403. }
  404. this.setStyle(HEIGHT,value);
  405. this._fixEdges();
  406. this.redraw();
  407. },
  408. /**
  409. * Method called when the height attribute is changed
  410. * @method _widthChange
  411. * @param {int or string} value New width, in pixels if int or string including units
  412. * @return void
  413. * @private
  414. */
  415. _widthChange: function(value) {
  416. if (Lang.isNumber(value)) {
  417. value += 'px';
  418. }
  419. this.setStyle(WIDTH,value);
  420. this._fixEdges();
  421. this.redraw();
  422. },
  423. /**
  424. * Due to rounding differences, some browsers fail to cover the whole area
  425. * with the mask quadrants when the width or height is odd. This method
  426. * stretches the lower and/or right quadrants to make the difference.
  427. * @method _fixEdges
  428. * @return void
  429. * @private
  430. */
  431. _fixEdges:function() {
  432. if (!this._rendered || YAHOO.env.ua.ie || YAHOO.env.ua.gecko ) { return; }
  433. var maskEl = this.get(MASK_EL),
  434. tlEl = Dom.getElementsByClassName(CLASS_TL,undefined,maskEl)[0],
  435. trEl = Dom.getElementsByClassName(CLASS_TR,undefined,maskEl)[0],
  436. blEl = Dom.getElementsByClassName(CLASS_BL,undefined,maskEl)[0],
  437. brEl = Dom.getElementsByClassName(CLASS_BR,undefined,maskEl)[0],
  438. newSize = (parseInt(Dom.getStyle(maskEl,HEIGHT),10) -
  439. parseInt(Dom.getStyle(tlEl,HEIGHT),10)) + 'px';
  440. Dom.setStyle(blEl,HEIGHT,newSize);
  441. Dom.setStyle(brEl,HEIGHT,newSize);
  442. newSize = (parseInt(Dom.getStyle(maskEl,WIDTH),10) -
  443. parseInt(Dom.getStyle(tlEl,WIDTH),10)) + 'px';
  444. Dom.setStyle(trEl,WIDTH,newSize);
  445. Dom.setStyle(brEl,WIDTH,newSize);
  446. },
  447. /**
  448. * Calculates some auxiliary values to make the rendering faster
  449. * @method _recalculateConstants
  450. * @return void
  451. * @private
  452. */
  453. _recalculateConstants: function() {
  454. var barEl = this.get(BAR_EL);
  455. switch (this.get(DIRECTION)) {
  456. case DIRECTION_LTR:
  457. case DIRECTION_RTL:
  458. this._barSpace = parseInt(this.get(WIDTH),10) -
  459. (parseInt(Dom.getStyle(barEl,'marginLeft'),10) || 0) -
  460. (parseInt(Dom.getStyle(barEl,'marginRight'),10) || 0);
  461. break;
  462. case DIRECTION_TTB:
  463. case DIRECTION_BTT:
  464. this._barSpace = parseInt(this.get(HEIGHT),10) -
  465. (parseInt(Dom.getStyle(barEl,'marginTop'),10) || 0)-
  466. (parseInt(Dom.getStyle(barEl,'marginBottom'),10) || 0);
  467. break;
  468. }
  469. this._barFactor = this._barSpace / (this.get(MAX_VALUE) - (this.get(MIN_VALUE) || 0)) || 1;
  470. },
  471. /**
  472. * Called in response to a change in the <a href="#config_anim">anim</a> attribute.
  473. * It creates and sets up or destroys the instance of the animation utility that will move the bar
  474. * @method _animSetter
  475. * @return void
  476. * @private
  477. */
  478. _animSetter: function (value) {
  479. var anim, barEl = this.get(BAR_EL);
  480. if (value) {
  481. if (value instanceof YAHOO.util.Anim) {
  482. anim = value;
  483. } else {
  484. anim = new YAHOO.util.Anim(barEl);
  485. }
  486. anim.onTween.subscribe(this._animOnTween,this,true);
  487. anim.onComplete.subscribe(this._animComplete,this,true);
  488. // Temporary solution until http://yuilibrary.com/projects/yui2/ticket/2528222 gets solved:
  489. var oldSetAttribute = anim.setAttribute,
  490. pb = this;
  491. switch(this.get(DIRECTION)) {
  492. case DIRECTION_BTT:
  493. anim.setAttribute = function(attr , val , unit) {
  494. val = Math.round(val);
  495. oldSetAttribute.call(this,attr,val,unit);
  496. Dom.setStyle(barEl,'top',(pb._barSpace - val) + 'px');
  497. };
  498. break;
  499. case DIRECTION_RTL:
  500. anim.setAttribute = function(attr , val , unit) {
  501. val = Math.round(val);
  502. oldSetAttribute.call(this,attr,val,unit);
  503. Dom.setStyle(barEl,'left',(pb._barSpace - val) + 'px');
  504. };
  505. break;
  506. }
  507. // up to here
  508. } else {
  509. anim = this.get(ANIM);
  510. if (anim) {
  511. anim.onTween.unsubscribeAll();
  512. anim.onComplete.unsubscribeAll();
  513. }
  514. anim = null;
  515. }
  516. this._barSizeFunction = this._barSizeFunctions[anim?1:0][this.get(DIRECTION)];
  517. return anim;
  518. },
  519. _animComplete: function() {
  520. var value = this.get(VALUE);
  521. this._previousValue = value;
  522. this.fireEvent(PROGRESS,value);
  523. this.fireEvent(COMPLETE, value);
  524. Dom.removeClass(this.get(BAR_EL),CLASS_ANIM);
  525. },
  526. _animOnTween:function (name,oArgs) {
  527. var value = Math.floor(this._tweenFactor * oArgs[0].currentFrame + this._previousValue);
  528. this.fireEvent(PROGRESS,value);
  529. },
  530. /**
  531. * Called in response to a change in the <a href="#config_value">value</a> attribute.
  532. * Moves the bar to reflect the new value
  533. * @method _valueChange
  534. * @return void
  535. * @private
  536. */
  537. _valueChange: function (value) {
  538. var anim = this.get(ANIM),
  539. pixelValue = Math.floor((value - this.get(MIN_VALUE)) * this._barFactor),
  540. barEl = this.get(BAR_EL);
  541. this._setAriaText(value);
  542. if (this._rendered) {
  543. if (anim) {
  544. anim.stop();
  545. if (anim.isAnimated()) { anim._onComplete.fire(); } // see: http://yuilibrary.com/projects/yui2/ticket/2528217
  546. }
  547. this.fireEvent(START,this._previousValue);
  548. this._barSizeFunction(value, pixelValue, barEl, anim);
  549. }
  550. },
  551. /**
  552. * Utility method to set the ARIA value attributes
  553. * @method _setAriaText
  554. * @return void
  555. * @private
  556. */
  557. _setAriaText: function(value) {
  558. var container = this.get('element'),
  559. text = Lang.substitute(this.get(ARIA_TEXT_TEMPLATE),{
  560. value:value,
  561. minValue:this.get(MIN_VALUE),
  562. maxValue:this.get(MAX_VALUE)
  563. });
  564. container.setAttribute('aria-valuenow',value);
  565. container.setAttribute('aria-valuetext',text);
  566. }
  567. });
  568. /**
  569. * Collection of functions used by to calculate the size of the bar.
  570. * One of this will be used depending on direction and whether animation is active.
  571. * @property _barSizeFunctions
  572. * @type {collection of functions}
  573. * @private
  574. */
  575. var b = [{},{}];
  576. Prog.prototype._barSizeFunctions = b;
  577. b[0][DIRECTION_LTR] = function(value, pixelValue, barEl, anim) {
  578. Dom.setStyle(barEl,WIDTH, pixelValue + 'px');
  579. this.fireEvent(PROGRESS,value);
  580. this.fireEvent(COMPLETE,value);
  581. };
  582. b[0][DIRECTION_RTL] = function(value, pixelValue, barEl, anim) {
  583. Dom.setStyle(barEl,WIDTH, pixelValue + 'px');
  584. Dom.setStyle(barEl,'left',(this._barSpace - pixelValue) + 'px');
  585. this.fireEvent(PROGRESS,value);
  586. this.fireEvent(COMPLETE,value);
  587. };
  588. b[0][DIRECTION_TTB] = function(value, pixelValue, barEl, anim) {
  589. Dom.setStyle(barEl,HEIGHT, pixelValue + 'px');
  590. this.fireEvent(PROGRESS,value);
  591. this.fireEvent(COMPLETE,value);
  592. };
  593. b[0][DIRECTION_BTT] = function(value, pixelValue, barEl, anim) {
  594. Dom.setStyle(barEl,HEIGHT, pixelValue + 'px');
  595. Dom.setStyle(barEl,'top', (this._barSpace - pixelValue) + 'px');
  596. this.fireEvent(PROGRESS,value);
  597. this.fireEvent(COMPLETE,value);
  598. };
  599. b[1][DIRECTION_LTR] = function(value, pixelValue, barEl, anim) {
  600. Dom.addClass(barEl,CLASS_ANIM);
  601. this._tweenFactor = (value - this._previousValue) / anim.totalFrames / anim.duration;
  602. anim.attributes = {width:{ to: pixelValue }};
  603. anim.animate();
  604. };
  605. b[1][DIRECTION_RTL] = b[1][DIRECTION_LTR];
  606. b[1][DIRECTION_TTB] = function(value, pixelValue, barEl, anim) {
  607. Dom.addClass(barEl,CLASS_ANIM);
  608. this._tweenFactor = (value - this._previousValue) / anim.totalFrames / anim.duration;
  609. anim.attributes = {height:{to: pixelValue}};
  610. anim.animate();
  611. };
  612. b[1][DIRECTION_BTT] = b[1][DIRECTION_TTB];
  613. })();
  614. YAHOO.register("progressbar", YAHOO.widget.ProgressBar, {version: "2.8.0r4", build: "2449"});