3 Polymer('paper-slider', {
6 * Fired when the slider's value changes.
12 * Fired when the slider's immediateValue changes.
14 * @event immediate-value-change
18 * Fired when the slider's value changes due to user interaction.
20 * Changes to the slider's value due to changes in an underlying
21 * bound variable will not trigger this event.
27 * If true, the slider thumb snaps to tick marks evenly spaced based
28 * on the `step` property value.
37 * If true, a pin with numeric value label is shown when the slider thumb
38 * is pressed. Use for settings for which users need to know the exact
39 * value of the setting.
48 * If true, this slider is disabled. A disabled slider cannot be tapped
49 * or dragged to change the slider value.
58 * The number that represents the current secondary progress.
60 * @attribute secondaryProgress
67 * If true, an input is shown and user can use it to set the slider value.
76 * The immediate value of the slider. This value is updated while the user
77 * is dragging the slider.
79 * @attribute immediateValue
87 'step snaps': 'update'
95 this.positionKnob(this.calcRatio(this.value));
99 minChanged: function() {
101 this.setAttribute('aria-valuemin', this.min);
104 maxChanged: function() {
106 this.setAttribute('aria-valuemax', this.max);
109 valueChanged: function() {
111 this.setAttribute('aria-valuenow', this.value);
112 this.fire('core-change');
115 disabledChanged: function() {
117 this.removeAttribute('tabindex');
123 immediateValueChanged: function() {
124 if (!this.dragging) {
125 this.value = this.immediateValue;
127 this.fire('immediate-value-change');
130 expandKnob: function() {
134 resetKnob: function() {
135 this.expandJob && this.expandJob.stop();
139 positionKnob: function(ratio) {
140 this.immediateValue = this.calcStep(this.calcKnobPosition(ratio)) || 0;
141 this._ratio = this.snaps ? this.calcRatio(this.immediateValue) : ratio;
142 this.$.sliderKnob.style.left = this._ratio * 100 + '%';
145 inputChange: function() {
146 this.value = this.$.input.value;
150 calcKnobPosition: function(ratio) {
151 return (this.max - this.min) * ratio + this.min;
154 trackStart: function(e) {
155 this._w = this.$.sliderBar.offsetWidth;
156 this._x = this._ratio * this._w;
157 this._startx = this._x || 0;
158 this._minx = - this._startx;
159 this._maxx = this._w - this._startx;
160 this.$.sliderKnob.classList.add('dragging');
161 this.dragging = true;
165 trackx: function(e) {
166 var x = Math.min(this._maxx, Math.max(this._minx, e.dx));
167 this._x = this._startx + x;
168 this.immediateValue = this.calcStep(
169 this.calcKnobPosition(this._x / this._w)) || 0;
170 var s = this.$.sliderKnob.style;
171 s.transform = s.webkitTransform = 'translate3d(' + (this.snaps ?
172 (this.calcRatio(this.immediateValue) * this._w) - this._startx : x) + 'px, 0, 0)';
175 trackEnd: function() {
176 var s = this.$.sliderKnob.style;
177 s.transform = s.webkitTransform = '';
178 this.$.sliderKnob.classList.remove('dragging');
179 this.dragging = false;
181 this.value = this.immediateValue;
185 knobdown: function(e) {
190 bardown: function(e) {
192 this.transiting = true;
193 this._w = this.$.sliderBar.offsetWidth;
194 var rect = this.$.sliderBar.getBoundingClientRect();
195 var ratio = (e.x - rect.left) / this._w;
196 this.positionKnob(ratio);
197 this.expandJob = this.job(this.expandJob, this.expandKnob, 60);
201 knobTransitionEnd: function(e) {
202 if (e.target === this.$.sliderKnob) {
203 this.transiting = false;
207 updateMarkers: function() {
209 var l = (this.max - this.min) / this.step;
210 if (!this.snaps && l > this.maxMarkers) {
213 for (var i = 0; i < l; i++) {
214 this.markers.push('');
218 increment: function() {
219 this.value = this.clampValue(this.value + this.step);
222 decrement: function() {
223 this.value = this.clampValue(this.value - this.step);
226 incrementKey: function(ev, keys) {
227 if (keys.key === "end") {
228 this.value = this.max;
235 decrementKey: function(ev, keys) {
236 if (keys.key === "home") {
237 this.value = this.min;