7bb3d03701323459234562d372bcf9d30ab98a15.svn-base 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. if (!dojo._hasResource["dijit.form.Slider"]) { // _hasResource checks added by
  2. // build. Do not use
  3. // _hasResource directly in your
  4. // code.
  5. dojo._hasResource["dijit.form.Slider"] = true;
  6. dojo.provide("dijit.form.Slider");
  7. dojo.require("dijit.form._FormWidget");
  8. dojo.require("dijit._Container");
  9. dojo.require("dojo.dnd.move");
  10. dojo.require("dijit.form.Button");
  11. dojo.require("dojo.number");
  12. dojo.declare("dijit.form.HorizontalSlider", [dijit.form._FormWidget,
  13. dijit._Container], {
  14. // summary
  15. // A form widget that allows one to select a value with a
  16. // horizontally draggable image
  17. templateString : "<table class=\"dijit dijitReset dijitSlider\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" rules=\"none\"\n\t><tr class=\"dijitReset\"\n\t\t><td class=\"dijitReset\" colspan=\"2\"></td\n\t\t><td dojoAttachPoint=\"containerNode,topDecoration\" class=\"dijitReset\" style=\"text-align:center;width:100%;\"></td\n\t\t><td class=\"dijitReset\" colspan=\"2\"></td\n\t></tr\n\t><tr class=\"dijitReset\"\n\t\t><td class=\"dijitReset dijitSliderButtonContainer dijitHorizontalSliderButtonContainer\"\n\t\t\t><div class=\"dijitHorizontalSliderDecrementIcon\" tabIndex=\"-1\" style=\"display:none\" dojoAttachPoint=\"decrementButton\" dojoAttachEvent=\"onclick: decrement\"><span class=\"dijitSliderButtonInner\">-</span></div\n\t\t></td\n\t\t><td class=\"dijitReset\"\n\t\t\t><div class=\"dijitSliderBar dijitSliderBumper dijitHorizontalSliderBumper dijitSliderLeftBumper dijitHorizontalSliderLeftBumper\"></div\n\t\t></td\n\t\t><td class=\"dijitReset\"\n\t\t\t><input dojoAttachPoint=\"valueNode\" type=\"hidden\" name=\"${name}\"\n\t\t\t/><div style=\"position:relative;\" dojoAttachPoint=\"sliderBarContainer\"\n\t\t\t\t><div dojoAttachPoint=\"progressBar\" class=\"dijitSliderBar dijitHorizontalSliderBar dijitSliderProgressBar dijitHorizontalSliderProgressBar\" dojoAttachEvent=\"onclick:_onBarClick\"\n\t\t\t\t\t><div dojoAttachPoint=\"sliderHandle,focusNode\" class=\"dijitSliderMoveable dijitHorizontalSliderMoveable\" dojoAttachEvent=\"onkeypress:_onKeyPress,onclick:_onHandleClick\" waiRole=\"slider\" valuemin=\"${minimum}\" valuemax=\"${maximum}\"\n\t\t\t\t\t\t><div class=\"dijitSliderImageHandle dijitHorizontalSliderImageHandle\"></div\n\t\t\t\t\t></div\n\t\t\t\t></div\n\t\t\t\t><div dojoAttachPoint=\"remainingBar\" class=\"dijitSliderBar dijitHorizontalSliderBar dijitSliderRemainingBar dijitHorizontalSliderRemainingBar\" dojoAttachEvent=\"onclick:_onBarClick\"></div\n\t\t\t></div\n\t\t></td\n\t\t><td class=\"dijitReset\"\n\t\t\t><div class=\"dijitSliderBar dijitSliderBumper dijitHorizontalSliderBumper dijitSliderRightBumper dijitHorizontalSliderRightBumper\"></div\n\t\t></td\n\t\t><td class=\"dijitReset dijitSliderButtonContainer dijitHorizontalSliderButtonContainer\" style=\"right:0px;\"\n\t\t\t><div class=\"dijitHorizontalSliderIncrementIcon\" tabIndex=\"-1\" style=\"display:none\" dojoAttachPoint=\"incrementButton\" dojoAttachEvent=\"onclick: increment\"><span class=\"dijitSliderButtonInner\">+</span></div\n\t\t></td\n\t></tr\n\t><tr class=\"dijitReset\"\n\t\t><td class=\"dijitReset\" colspan=\"2\"></td\n\t\t><td dojoAttachPoint=\"containerNode,bottomDecoration\" class=\"dijitReset\" style=\"text-align:center;\"></td\n\t\t><td class=\"dijitReset\" colspan=\"2\"></td\n\t></tr\n></table>\n",
  18. value : 0,
  19. // showButtons: boolean
  20. // Show increment/decrement buttons at the ends of the slider?
  21. showButtons : true,
  22. // minimum:: integer
  23. // The minimum value allowed.
  24. minimum : 0,
  25. // maximum: integer
  26. // The maximum allowed value.
  27. maximum : 100,
  28. // discreteValues: integer
  29. // The maximum allowed values dispersed evenly between minimum
  30. // and maximum (inclusive).
  31. discreteValues : Infinity,
  32. // pageIncrement: integer
  33. // The amount of change with shift+arrow
  34. pageIncrement : 2,
  35. // clickSelect: boolean
  36. // If clicking the progress bar changes the value or not
  37. clickSelect : true,
  38. widgetsInTemplate : true,
  39. attributeMap : dojo
  40. .mixin(
  41. dojo
  42. .clone(dijit.form._FormWidget.prototype.attributeMap),
  43. {
  44. id : "",
  45. name : "valueNode"
  46. }),
  47. baseClass : "dijitSlider",
  48. _mousePixelCoord : "pageX",
  49. _pixelCount : "w",
  50. _startingPixelCoord : "x",
  51. _startingPixelCount : "l",
  52. _handleOffsetCoord : "left",
  53. _progressPixelSize : "width",
  54. _upsideDown : false,
  55. _onKeyPress : function(/* Event */e) {
  56. if (this.disabled || e.altKey || e.ctrlKey) {
  57. return;
  58. }
  59. switch (e.keyCode) {
  60. case dojo.keys.HOME :
  61. this.setValue(this.minimum, false);
  62. break;
  63. case dojo.keys.END :
  64. this.setValue(this.maximum, false);
  65. break;
  66. case dojo.keys.UP_ARROW :
  67. case (this._isReversed()
  68. ? dojo.keys.LEFT_ARROW
  69. : dojo.keys.RIGHT_ARROW) :
  70. case dojo.keys.PAGE_UP :
  71. this.increment(e);
  72. break;
  73. case dojo.keys.DOWN_ARROW :
  74. case (this._isReversed()
  75. ? dojo.keys.RIGHT_ARROW
  76. : dojo.keys.LEFT_ARROW) :
  77. case dojo.keys.PAGE_DOWN :
  78. this.decrement(e);
  79. break;
  80. default :
  81. this.inherited("_onKeyPress", arguments);
  82. return;
  83. }
  84. dojo.stopEvent(e);
  85. },
  86. _onHandleClick : function(e) {
  87. if (this.disabled) {
  88. return;
  89. }
  90. if (!dojo.isIE) {
  91. // make sure you get focus when dragging the handle
  92. // (but don't do on IE because it causes a flicker on
  93. // mouse up (due to blur then focus)
  94. dijit.focus(this.sliderHandle);
  95. }
  96. dojo.stopEvent(e);
  97. },
  98. _isReversed : function() {
  99. return !(this._upsideDown || this.isLeftToRight());
  100. },
  101. _onBarClick : function(e) {
  102. if (this.disabled || !this.clickSelect) {
  103. return;
  104. }
  105. dijit.focus(this.sliderHandle);
  106. dojo.stopEvent(e);
  107. var abspos = dojo.coords(this.sliderBarContainer, true);
  108. var pixelValue = e[this._mousePixelCoord]
  109. - abspos[this._startingPixelCoord];
  110. this._setPixelValue(this._isReversed() || this._upsideDown
  111. ? (abspos[this._pixelCount] - pixelValue)
  112. : pixelValue, abspos[this._pixelCount],
  113. true);
  114. },
  115. _setPixelValue : function(/* Number */pixelValue, /* Number */
  116. maxPixels, /* Boolean, optional */priorityChange) {
  117. if (this.disabled) {
  118. return;
  119. }
  120. pixelValue = pixelValue < 0 ? 0 : maxPixels < pixelValue
  121. ? maxPixels
  122. : pixelValue;
  123. var count = this.discreteValues;
  124. if (count <= 1 || count == Infinity) {
  125. count = maxPixels;
  126. }
  127. count--;
  128. var pixelsPerValue = maxPixels / count;
  129. var wholeIncrements = Math.round(pixelValue
  130. / pixelsPerValue);
  131. this.setValue((this.maximum - this.minimum)
  132. * wholeIncrements / count + this.minimum,
  133. priorityChange);
  134. },
  135. setValue : function(/* Number */value, /* Boolean, optional */
  136. priorityChange) {
  137. this.valueNode.value = this.value = value;
  138. this.inherited('setValue', arguments);
  139. var percent = (value - this.minimum)
  140. / (this.maximum - this.minimum);
  141. this.progressBar.style[this._progressPixelSize] = (percent * 100)
  142. + "%";
  143. this.remainingBar.style[this._progressPixelSize] = ((1 - percent) * 100)
  144. + "%";
  145. },
  146. _bumpValue : function(signedChange) {
  147. if (this.disabled) {
  148. return;
  149. }
  150. var s = dojo.getComputedStyle(this.sliderBarContainer);
  151. var c = dojo._getContentBox(this.sliderBarContainer, s);
  152. var count = this.discreteValues;
  153. if (count <= 1 || count == Infinity) {
  154. count = c[this._pixelCount];
  155. }
  156. count--;
  157. var value = (this.value - this.minimum) * count
  158. / (this.maximum - this.minimum) + signedChange;
  159. if (value < 0) {
  160. value = 0;
  161. }
  162. if (value > count) {
  163. value = count;
  164. }
  165. value = value * (this.maximum - this.minimum) / count
  166. + this.minimum;
  167. this.setValue(value, true);
  168. },
  169. decrement : function(e) {
  170. // summary
  171. // decrement slider by 1 unit
  172. this._bumpValue(e.keyCode == dojo.keys.PAGE_DOWN
  173. ? -this.pageIncrement
  174. : -1);
  175. },
  176. increment : function(e) {
  177. // summary
  178. // increment slider by 1 unit
  179. this._bumpValue(e.keyCode == dojo.keys.PAGE_UP
  180. ? this.pageIncrement
  181. : 1);
  182. },
  183. _mouseWheeled : function(/* Event */evt) {
  184. dojo.stopEvent(evt);
  185. var scrollAmount = 0;
  186. if (typeof evt.wheelDelta == 'number') { // IE
  187. scrollAmount = evt.wheelDelta;
  188. } else if (typeof evt.detail == 'number') { // Mozilla+Firefox
  189. scrollAmount = -evt.detail;
  190. }
  191. if (scrollAmount > 0) {
  192. this.increment(evt);
  193. } else if (scrollAmount < 0) {
  194. this.decrement(evt);
  195. }
  196. },
  197. startup : function() {
  198. dojo.forEach(this.getChildren(), function(child) {
  199. if (this[child.container] != this.containerNode) {
  200. this[child.container]
  201. .appendChild(child.domNode);
  202. }
  203. }, this);
  204. },
  205. _onBlur : function() {
  206. dijit.form.HorizontalSlider.superclass.setValue.call(this,
  207. this.value, true);
  208. },
  209. postCreate : function() {
  210. if (this.showButtons) {
  211. this.incrementButton.style.display = "";
  212. this.decrementButton.style.display = "";
  213. }
  214. this.connect(this.domNode, dojo.isIE
  215. ? "onmousewheel"
  216. : 'DOMMouseScroll', "_mouseWheeled");
  217. // define a custom constructor for a SliderMover that points
  218. // back to me
  219. var _self = this;
  220. var mover = function() {
  221. dijit.form._SliderMover.apply(this, arguments);
  222. this.widget = _self;
  223. };
  224. dojo.extend(mover, dijit.form._SliderMover.prototype);
  225. this._movable = new dojo.dnd.Moveable(this.sliderHandle, {
  226. mover : mover
  227. });
  228. this.inherited('postCreate', arguments);
  229. },
  230. destroy : function() {
  231. this._movable.destroy();
  232. this.inherited('destroy', arguments);
  233. }
  234. });
  235. dojo.declare("dijit.form.VerticalSlider", dijit.form.HorizontalSlider, {
  236. // summary
  237. // A form widget that allows one to select a value with a vertically
  238. // draggable image
  239. templateString : "<table class=\"dijitReset dijitSlider\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" rules=\"none\"\n><tbody class=\"dijitReset\"\n\t><tr class=\"dijitReset\"\n\t\t><td class=\"dijitReset\"></td\n\t\t><td class=\"dijitReset dijitSliderButtonContainer dijitVerticalSliderButtonContainer\"\n\t\t\t><div class=\"dijitVerticalSliderIncrementIcon\" tabIndex=\"-1\" style=\"display:none\" dojoAttachPoint=\"incrementButton\" dojoAttachEvent=\"onclick: increment\"><span class=\"dijitSliderButtonInner\">+</span></div\n\t\t></td\n\t\t><td class=\"dijitReset\"></td\n\t></tr\n\t><tr class=\"dijitReset\"\n\t\t><td class=\"dijitReset\"></td\n\t\t><td class=\"dijitReset\"\n\t\t\t><center><div class=\"dijitSliderBar dijitSliderBumper dijitVerticalSliderBumper dijitSliderTopBumper dijitVerticalSliderTopBumper\"></div></center\n\t\t></td\n\t\t><td class=\"dijitReset\"></td\n\t></tr\n\t><tr class=\"dijitReset\"\n\t\t><td dojoAttachPoint=\"leftDecoration\" class=\"dijitReset\" style=\"text-align:center;height:100%;\"></td\n\t\t><td class=\"dijitReset\" style=\"height:100%;\"\n\t\t\t><input dojoAttachPoint=\"valueNode\" type=\"hidden\" name=\"${name}\"\n\t\t\t/><center style=\"position:relative;height:100%;\" dojoAttachPoint=\"sliderBarContainer\"\n\t\t\t\t><div dojoAttachPoint=\"remainingBar\" class=\"dijitSliderBar dijitVerticalSliderBar dijitSliderRemainingBar dijitVerticalSliderRemainingBar\" dojoAttachEvent=\"onclick:_onBarClick\"></div\n\t\t\t\t><div dojoAttachPoint=\"progressBar\" class=\"dijitSliderBar dijitVerticalSliderBar dijitSliderProgressBar dijitVerticalSliderProgressBar\" dojoAttachEvent=\"onclick:_onBarClick\"\n\t\t\t\t\t><div dojoAttachPoint=\"sliderHandle,focusNode\" class=\"dijitSliderMoveable\" dojoAttachEvent=\"onkeypress:_onKeyPress,onclick:_onHandleClick\" style=\"vertical-align:top;\" waiRole=\"slider\" valuemin=\"${minimum}\" valuemax=\"${maximum}\"\n\t\t\t\t\t\t><div class=\"dijitSliderImageHandle dijitVerticalSliderImageHandle\"></div\n\t\t\t\t\t></div\n\t\t\t\t></div\n\t\t\t></center\n\t\t></td\n\t\t><td dojoAttachPoint=\"containerNode,rightDecoration\" class=\"dijitReset\" style=\"text-align:center;height:100%;\"></td\n\t></tr\n\t><tr class=\"dijitReset\"\n\t\t><td class=\"dijitReset\"></td\n\t\t><td class=\"dijitReset\"\n\t\t\t><center><div class=\"dijitSliderBar dijitSliderBumper dijitVerticalSliderBumper dijitSliderBottomBumper dijitVerticalSliderBottomBumper\"></div></center\n\t\t></td\n\t\t><td class=\"dijitReset\"></td\n\t></tr\n\t><tr class=\"dijitReset\"\n\t\t><td class=\"dijitReset\"></td\n\t\t><td class=\"dijitReset dijitSliderButtonContainer dijitVerticalSliderButtonContainer\"\n\t\t\t><div class=\"dijitVerticalSliderDecrementIcon\" tabIndex=\"-1\" style=\"display:none\" dojoAttachPoint=\"decrementButton\" dojoAttachEvent=\"onclick: decrement\"><span class=\"dijitSliderButtonInner\">-</span></div\n\t\t></td\n\t\t><td class=\"dijitReset\"></td\n\t></tr\n></tbody></table>\n",
  240. _mousePixelCoord : "pageY",
  241. _pixelCount : "h",
  242. _startingPixelCoord : "y",
  243. _startingPixelCount : "t",
  244. _handleOffsetCoord : "top",
  245. _progressPixelSize : "height",
  246. _upsideDown : true
  247. });
  248. dojo.declare("dijit.form._SliderMover", dojo.dnd.Mover, {
  249. onMouseMove : function(e) {
  250. var widget = this.widget;
  251. var c = this.constraintBox;
  252. if (!c) {
  253. var container = widget.sliderBarContainer;
  254. var s = dojo.getComputedStyle(container);
  255. var c = dojo._getContentBox(container, s);
  256. c[widget._startingPixelCount] = 0;
  257. this.constraintBox = c;
  258. }
  259. var m = this.marginBox;
  260. var pixelValue = widget._isReversed()
  261. ? e[widget._mousePixelCoord]
  262. - dojo._abs(widget.sliderBarContainer).x
  263. : m[widget._startingPixelCount]
  264. + e[widget._mousePixelCoord];
  265. dojo.hitch(widget, "_setPixelValue")(widget._isReversed()
  266. || widget._upsideDown
  267. ? (c[widget._pixelCount] - pixelValue)
  268. : pixelValue, c[widget._pixelCount]);
  269. },
  270. destroy : function(e) {
  271. var widget = this.widget;
  272. widget.setValue(widget.value, true);
  273. dojo.dnd.Mover.prototype.destroy.call(this);
  274. }
  275. });
  276. dojo.declare("dijit.form.HorizontalRule",
  277. [dijit._Widget, dijit._Templated], {
  278. // Summary:
  279. // Create hash marks for the Horizontal slider
  280. templateString : '<div class="RuleContainer HorizontalRuleContainer"></div>',
  281. // count: Integer
  282. // Number of hash marks to generate
  283. count : 3,
  284. // container: Node
  285. // If this is a child widget, connect it to this parent node
  286. container : "containerNode",
  287. // ruleStyle: String
  288. // CSS style to apply to individual hash marks
  289. ruleStyle : "",
  290. _positionPrefix : '<div class="RuleMark HorizontalRuleMark" style="left:',
  291. _positionSuffix : '%;',
  292. _suffix : '"></div>',
  293. _genHTML : function(pos, ndx) {
  294. return this._positionPrefix + pos + this._positionSuffix
  295. + this.ruleStyle + this._suffix;
  296. },
  297. _isHorizontal : true,
  298. postCreate : function() {
  299. if (this.count == 1) {
  300. var innerHTML = this._genHTML(50, 0);
  301. } else {
  302. var interval = 100 / (this.count - 1);
  303. if (!this._isHorizontal || this.isLeftToRight()) {
  304. var innerHTML = this._genHTML(0, 0);
  305. for (var i = 1; i < this.count - 1; i++) {
  306. innerHTML += this._genHTML(interval * i, i);
  307. }
  308. innerHTML += this._genHTML(100, this.count - 1);
  309. } else {
  310. var innerHTML = this._genHTML(100, 0);
  311. for (var i = 1; i < this.count - 1; i++) {
  312. innerHTML += this._genHTML(100 - interval * i,
  313. i);
  314. }
  315. innerHTML += this._genHTML(0, this.count - 1);
  316. }
  317. }
  318. this.domNode.innerHTML = innerHTML;
  319. }
  320. });
  321. dojo.declare("dijit.form.VerticalRule", dijit.form.HorizontalRule, {
  322. // Summary:
  323. // Create hash marks for the Vertical slider
  324. templateString : '<div class="RuleContainer VerticalRuleContainer"></div>',
  325. _positionPrefix : '<div class="RuleMark VerticalRuleMark" style="top:',
  326. _isHorizontal : false
  327. });
  328. dojo.declare("dijit.form.HorizontalRuleLabels", dijit.form.HorizontalRule,
  329. {
  330. // Summary:
  331. // Create labels for the Horizontal slider
  332. templateString : '<div class="RuleContainer HorizontalRuleContainer"></div>',
  333. // labelStyle: String
  334. // CSS style to apply to individual text labels
  335. labelStyle : "",
  336. // labels: Array
  337. // Array of text labels to render - evenly spaced from
  338. // left-to-right or bottom-to-top
  339. labels : [],
  340. // numericMargin: Integer
  341. // Number of generated numeric labels that should be rendered as
  342. // '' on the ends when labels[] are not specified
  343. numericMargin : 0,
  344. // numericMinimum: Integer
  345. // Leftmost label value for generated numeric labels when
  346. // labels[] are not specified
  347. minimum : 0,
  348. // numericMaximum: Integer
  349. // Rightmost label value for generated numeric labels when
  350. // labels[] are not specified
  351. maximum : 1,
  352. // constraints: object
  353. // pattern, places, lang, et al (see dojo.number) for generated
  354. // numeric labels when labels[] are not specified
  355. constraints : {
  356. pattern : "#%"
  357. },
  358. _positionPrefix : '<div class="RuleLabelContainer HorizontalRuleLabelContainer" style="left:',
  359. _labelPrefix : '"><span class="RuleLabel HorizontalRuleLabel">',
  360. _suffix : '</span></div>',
  361. _calcPosition : function(pos) {
  362. return pos;
  363. },
  364. _genHTML : function(pos, ndx) {
  365. return this._positionPrefix + this._calcPosition(pos)
  366. + this._positionSuffix + this.labelStyle
  367. + this._labelPrefix + this.labels[ndx]
  368. + this._suffix;
  369. },
  370. getLabels : function() {
  371. // summary: user replaceable function to return the labels
  372. // array
  373. // if the labels array was not specified directly, then see
  374. // if <li> children were
  375. var labels = this.labels;
  376. if (!labels.length) {
  377. // for markup creation, labels are specified as child
  378. // elements
  379. labels = dojo.query("> li", this.srcNodeRef).map(
  380. function(node) {
  381. return String(node.innerHTML);
  382. });
  383. }
  384. this.srcNodeRef.innerHTML = '';
  385. // if the labels were not specified directly and not as <li>
  386. // children, then calculate numeric labels
  387. if (!labels.length && this.count > 1) {
  388. var start = this.minimum;
  389. var inc = (this.maximum - start) / (this.count - 1);
  390. for (var i = 0; i < this.count; i++) {
  391. labels
  392. .push((i < this.numericMargin || i >= (this.count - this.numericMargin))
  393. ? ''
  394. : dojo.number.format(start,
  395. this.constraints));
  396. start += inc;
  397. }
  398. }
  399. return labels;
  400. },
  401. postMixInProperties : function() {
  402. this.inherited('postMixInProperties', arguments);
  403. this.labels = this.getLabels();
  404. this.count = this.labels.length;
  405. }
  406. });
  407. dojo.declare("dijit.form.VerticalRuleLabels",
  408. dijit.form.HorizontalRuleLabels, {
  409. // Summary:
  410. // Create labels for the Vertical slider
  411. templateString : '<div class="RuleContainer VerticalRuleContainer"></div>',
  412. _positionPrefix : '<div class="RuleLabelContainer VerticalRuleLabelContainer" style="top:',
  413. _labelPrefix : '"><span class="RuleLabel VerticalRuleLabel">',
  414. _calcPosition : function(pos) {
  415. return 100 - pos;
  416. },
  417. _isHorizontal : false
  418. });
  419. }