ProgressBar.js.uncompressed.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. require({cache:{
  2. 'url:dijit/templates/ProgressBar.html':"<div class=\"dijitProgressBar dijitProgressBarEmpty\" role=\"progressbar\"\n\t><div data-dojo-attach-point=\"internalProgress\" class=\"dijitProgressBarFull\"\n\t\t><div class=\"dijitProgressBarTile\" role=\"presentation\"></div\n\t\t><span style=\"visibility:hidden\">&#160;</span\n\t></div\n\t><div data-dojo-attach-point=\"labelNode\" class=\"dijitProgressBarLabel\" id=\"${id}_label\"></div\n\t><img data-dojo-attach-point=\"indeterminateHighContrastImage\" class=\"dijitProgressBarIndeterminateHighContrastImage\" alt=\"\"\n/></div>\n"}});
  3. define("dijit/ProgressBar", [
  4. "require", // require.toUrl
  5. "dojo/_base/declare", // declare
  6. "dojo/dom-class", // domClass.toggle
  7. "dojo/_base/lang", // lang.mixin
  8. "dojo/number", // number.format
  9. "./_Widget",
  10. "./_TemplatedMixin",
  11. "dojo/text!./templates/ProgressBar.html"
  12. ], function(require, declare, domClass, lang, number, _Widget, _TemplatedMixin, template){
  13. // module:
  14. // dijit/ProgressBar
  15. return declare("dijit.ProgressBar", [_Widget, _TemplatedMixin], {
  16. // summary:
  17. // A progress indication widget, showing the amount completed
  18. // (often the percentage completed) of a task.
  19. //
  20. // example:
  21. // | <div data-dojo-type="ProgressBar"
  22. // | places="0"
  23. // | value="..." maximum="...">
  24. // | </div>
  25. // progress: [const] String (Percentage or Number)
  26. // Number or percentage indicating amount of task completed.
  27. // Deprecated. Use "value" instead.
  28. progress: "0",
  29. // value: String (Percentage or Number)
  30. // Number or percentage indicating amount of task completed.
  31. // With "%": percentage value, 0% <= progress <= 100%, or
  32. // without "%": absolute value, 0 <= progress <= maximum.
  33. // Infinity means that the progress bar is indeterminate.
  34. value: "",
  35. // maximum: [const] Float
  36. // Max sample number
  37. maximum: 100,
  38. // places: [const] Number
  39. // Number of places to show in values; 0 by default
  40. places: 0,
  41. // indeterminate: [const] Boolean
  42. // If false: show progress value (number or percentage).
  43. // If true: show that a process is underway but that the amount completed is unknown.
  44. // Deprecated. Use "value" instead.
  45. indeterminate: false,
  46. // label: String?
  47. // Label on progress bar. Defaults to percentage for determinate progress bar and
  48. // blank for indeterminate progress bar.
  49. label:"",
  50. // name: String
  51. // this is the field name (for a form) if set. This needs to be set if you want to use
  52. // this widget in a dijit/form/Form widget (such as dijit/Dialog)
  53. name: '',
  54. templateString: template,
  55. // _indeterminateHighContrastImagePath: [private] URL
  56. // URL to image to use for indeterminate progress bar when display is in high contrast mode
  57. _indeterminateHighContrastImagePath:
  58. require.toUrl("./themes/a11y/indeterminate_progress.gif"),
  59. postMixInProperties: function(){
  60. this.inherited(arguments);
  61. // Back-compat for when constructor specifies indeterminate or progress, rather than value. Remove for 2.0.
  62. if(!(this.params && "value" in this.params)){
  63. this.value = this.indeterminate ? Infinity : this.progress;
  64. }
  65. },
  66. buildRendering: function(){
  67. this.inherited(arguments);
  68. this.indeterminateHighContrastImage.setAttribute("src",
  69. this._indeterminateHighContrastImagePath.toString());
  70. this.update();
  71. },
  72. update: function(/*Object?*/attributes){
  73. // summary:
  74. // Internal method to change attributes of ProgressBar, similar to set(hash). Users should call
  75. // set("value", ...) rather than calling this method directly.
  76. // attributes:
  77. // May provide progress and/or maximum properties on this parameter;
  78. // see attribute specs for details.
  79. // example:
  80. // | myProgressBar.update({'indeterminate': true});
  81. // | myProgressBar.update({'progress': 80});
  82. // | myProgressBar.update({'indeterminate': true, label:"Loading ..." })
  83. // tags:
  84. // private
  85. // TODO: deprecate this method and use set() instead
  86. lang.mixin(this, attributes || {});
  87. var tip = this.internalProgress, ap = this.domNode;
  88. var percent = 1;
  89. if(this.indeterminate){
  90. ap.removeAttribute("aria-valuenow");
  91. }else{
  92. if(String(this.progress).indexOf("%") != -1){
  93. percent = Math.min(parseFloat(this.progress)/100, 1);
  94. this.progress = percent * this.maximum;
  95. }else{
  96. this.progress = Math.min(this.progress, this.maximum);
  97. percent = this.maximum ? this.progress / this.maximum : 0;
  98. }
  99. ap.setAttribute("aria-valuenow", this.progress);
  100. }
  101. // Even indeterminate ProgressBars should have these attributes
  102. ap.setAttribute("aria-describedby", this.labelNode.id);
  103. ap.setAttribute("aria-valuemin", 0);
  104. ap.setAttribute("aria-valuemax", this.maximum);
  105. this.labelNode.innerHTML = this.report(percent);
  106. domClass.toggle(this.domNode, "dijitProgressBarIndeterminate", this.indeterminate);
  107. tip.style.width = (percent * 100) + "%";
  108. this.onChange();
  109. },
  110. _setValueAttr: function(v){
  111. this._set("value", v);
  112. if(v == Infinity){
  113. this.update({indeterminate:true});
  114. }else{
  115. this.update({indeterminate:false, progress:v});
  116. }
  117. },
  118. _setLabelAttr: function(label){
  119. this._set("label", label);
  120. this.update();
  121. },
  122. _setIndeterminateAttr: function(indeterminate){
  123. // Deprecated, use set("value", ...) instead
  124. this.indeterminate = indeterminate;
  125. this.update();
  126. },
  127. report: function(/*float*/percent){
  128. // summary:
  129. // Generates message to show inside progress bar (normally indicating amount of task completed).
  130. // May be overridden.
  131. // tags:
  132. // extension
  133. return this.label ? this.label :
  134. (this.indeterminate ? "&#160;" : number.format(percent, { type: "percent", places: this.places, locale: this.lang }));
  135. },
  136. onChange: function(){
  137. // summary:
  138. // Callback fired when progress updates.
  139. // tags:
  140. // extension
  141. }
  142. });
  143. });