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.

108 lines
2.6 KiB

  1. /**
  2. A control that presents a range of selection options in the form of a
  3. horizontal slider with a control knob. The knob may be tapped and dragged
  4. to the desired location.
  5. {kind: "onyx.Slider", value: 30}
  6. The *onChanging* event is fired when dragging the control knob.
  7. The *onChange* event is fired when the position is set, either by finishing
  8. a drag or by tapping the bar.
  9. */
  10. enyo.kind({
  11. name: "onyx.Slider",
  12. kind: "onyx.ProgressBar",
  13. classes: "onyx-slider",
  14. published: {
  15. value: 0,
  16. lockBar: true,
  17. tappable: true
  18. },
  19. events: {
  20. onChange: "",
  21. onChanging: "",
  22. onAnimateFinish: ""
  23. },
  24. showStripes: false,
  25. //* @protected
  26. handlers: {
  27. ondragstart: "dragstart",
  28. ondrag: "drag",
  29. ondragfinish: "dragfinish"
  30. },
  31. moreComponents: [
  32. {kind: "Animator", onStep: "animatorStep", onEnd: "animatorComplete"},
  33. {classes: "onyx-slider-taparea"},
  34. {name: "knob", classes: "onyx-slider-knob"}
  35. ],
  36. create: function() {
  37. this.inherited(arguments);
  38. this.createComponents(this.moreComponents);
  39. this.valueChanged();
  40. },
  41. valueChanged: function() {
  42. this.value = this.clampValue(this.min, this.max, this.value);
  43. var p = this.calcPercent(this.value);
  44. this.updateKnobPosition(p);
  45. if (this.lockBar) {
  46. this.setProgress(this.value);
  47. }
  48. },
  49. updateKnobPosition: function(inPercent) {
  50. this.$.knob.applyStyle("left", inPercent + "%");
  51. },
  52. calcKnobPosition: function(inEvent) {
  53. var x = inEvent.clientX - this.hasNode().getBoundingClientRect().left;
  54. return (x / this.getBounds().width) * (this.max - this.min) + this.min;
  55. },
  56. dragstart: function(inSender, inEvent) {
  57. if (inEvent.horizontal) {
  58. inEvent.preventDefault();
  59. this.dragging = true;
  60. return true;
  61. }
  62. },
  63. drag: function(inSender, inEvent) {
  64. if (this.dragging) {
  65. var v = this.calcKnobPosition(inEvent);
  66. this.setValue(v);
  67. this.doChanging({value: this.value});
  68. return true;
  69. }
  70. },
  71. dragfinish: function(inSender, inEvent) {
  72. this.dragging = false;
  73. inEvent.preventTap();
  74. this.doChange({value: this.value});
  75. return true;
  76. },
  77. tap: function(inSender, inEvent) {
  78. if (this.tappable) {
  79. var v = this.calcKnobPosition(inEvent);
  80. this.tapped = true;
  81. this.animateTo(v);
  82. return true;
  83. }
  84. },
  85. //* @public
  86. //* Animates to the given value.
  87. animateTo: function(inValue) {
  88. this.$.animator.play({
  89. startValue: this.value,
  90. endValue: inValue,
  91. node: this.hasNode()
  92. });
  93. },
  94. //* @protected
  95. animatorStep: function(inSender) {
  96. this.setValue(inSender.value);
  97. return true;
  98. },
  99. animatorComplete: function(inSender) {
  100. if (this.tapped) {
  101. this.tapped = false;
  102. this.doChange({value: this.value});
  103. }
  104. this.doAnimateFinish(inSender);
  105. return true;
  106. }
  107. });