not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.6 KiB

  1. /**
  2. A control that shows the current progress of a process in a horizontal bar.
  3. {kind: "onyx.ProgressBar", progress: 10}
  4. To animate progress changes, call the *animateProgressTo* method:
  5. this.$.progressBar.animateProgressTo(50);
  6. You may customize the color of the bar by applying a style via the
  7. *barClasses* property, e.g.:
  8. {kind: "onyx.ProgressBar", barClasses: "onyx-dark"}
  9. When the *showStripes* property is true (the default), stripes are shown in
  10. the progress bar; when *animateStripes* is true (also the default), these
  11. stripes are animated. The animated stripes use CSS3 gradients and animation
  12. to produce the effects. In browsers that don't support these features, the
  13. effects will not be visible.
  14. */
  15. enyo.kind({
  16. name: "onyx.ProgressBar",
  17. classes: "onyx-progress-bar",
  18. published: {
  19. progress: 0,
  20. min: 0,
  21. max: 100,
  22. barClasses: "",
  23. showStripes: true,
  24. animateStripes: true
  25. },
  26. events: {
  27. onAnimateProgressFinish: ""
  28. },
  29. components: [
  30. {name: "progressAnimator", kind: "Animator", onStep: "progressAnimatorStep", onEnd: "progressAnimatorComplete"},
  31. {name: "bar", classes: "onyx-progress-bar-bar"}
  32. ],
  33. //* @protected
  34. create: function() {
  35. this.inherited(arguments);
  36. this.progressChanged();
  37. this.barClassesChanged();
  38. this.showStripesChanged();
  39. this.animateStripesChanged();
  40. },
  41. barClassesChanged: function(inOld) {
  42. this.$.bar.removeClass(inOld);
  43. this.$.bar.addClass(this.barClasses);
  44. },
  45. showStripesChanged: function() {
  46. this.$.bar.addRemoveClass("striped", this.showStripes);
  47. },
  48. animateStripesChanged: function() {
  49. this.$.bar.addRemoveClass("animated", this.animateStripes);
  50. },
  51. progressChanged: function() {
  52. this.progress = this.clampValue(this.min, this.max, this.progress);
  53. var p = this.calcPercent(this.progress);
  54. this.updateBarPosition(p);
  55. },
  56. clampValue: function(inMin, inMax, inValue) {
  57. return Math.max(inMin, Math.min(inValue, inMax));
  58. },
  59. calcRatio: function(inValue) {
  60. return (inValue - this.min) / (this.max - this.min);
  61. },
  62. calcPercent: function(inValue) {
  63. return this.calcRatio(inValue) * 100;
  64. },
  65. updateBarPosition: function(inPercent) {
  66. this.$.bar.applyStyle("width", inPercent + "%");
  67. },
  68. //* @public
  69. //* Animates progress to the given value.
  70. animateProgressTo: function(inValue) {
  71. this.$.progressAnimator.play({
  72. startValue: this.progress,
  73. endValue: inValue,
  74. node: this.hasNode()
  75. });
  76. },
  77. //* @protected
  78. progressAnimatorStep: function(inSender) {
  79. this.setProgress(inSender.value);
  80. return true;
  81. },
  82. progressAnimatorComplete: function(inSender) {
  83. this.doAnimateProgressFinish(inSender);
  84. return true;
  85. }
  86. });