73bcce88
luigser
COMPONENTS
|
1
2
3
4
5
6
7
8
9
10
11
|
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../polymer/polymer.html">
|
a1a3bc73
Luigi Serra
graphs updates
|
12
|
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
|
a1a3bc73
Luigi Serra
graphs updates
|
13
|
<link rel="import" href="../paper-styles/color.html">
|
c5169e0e
Renato De Donato
a new hope
|
14
15
16
17
18
19
20
|
<link rel="import" href="../paper-progress/paper-progress.html">
<link rel="import" href="../paper-input/paper-input.html">
<link rel="import" href="../paper-behaviors/paper-inky-focus-behavior.html">
<link rel="import" href="../paper-ripple/paper-ripple.html">
<link rel="import" href="../iron-a11y-keys-behavior/iron-a11y-keys-behavior.html">
<link rel="import" href="../iron-range-behavior/iron-range-behavior.html">
<link rel="import" href="../iron-form-element-behavior/iron-form-element-behavior.html">
|
73bcce88
luigser
COMPONENTS
|
21
22
|
<!--
|
eb240478
Luigi Serra
public room cards...
|
23
24
|
Material design: [Sliders](https://www.google.com/design/spec/components/sliders.html)
|
73bcce88
luigser
COMPONENTS
|
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
`paper-slider` allows user to select a value from a range of values by
moving the slider thumb. The interactive nature of the slider makes it a
great choice for settings that reflect intensity levels, such as volume,
brightness, or color saturation.
Example:
<paper-slider></paper-slider>
Use `min` and `max` to specify the slider range. Default is 0 to 100.
Example:
<paper-slider min="10" max="200" value="110"></paper-slider>
### Styling
The following custom properties and mixins are available for styling:
Custom property | Description | Default
----------------|-------------|----------
`--paper-slider-bar-color` | The background color of the slider | `transparent`
`--paper-slider-active-color` | The progress bar color | `--google-blue-700`
`--paper-slider-secondary-color` | The secondary progress bar color | `--google-blue-300`
`--paper-slider-knob-color` | The knob color | `--google-blue-700`
|
c5169e0e
Renato De Donato
a new hope
|
50
|
`--paper-slider-disabled-knob-color` | The disabled knob color | `--google-grey-500`
|
73bcce88
luigser
COMPONENTS
|
51
52
|
`--paper-slider-pin-color` | The pin color | `--google-blue-700`
`--paper-slider-font-color` | The pin's text color | `#fff`
|
c5169e0e
Renato De Donato
a new hope
|
53
54
|
`--paper-slider-disabled-active-color` | The disabled progress bar color | `--google-grey-500`
`--paper-slider-disabled-secondary-color` | The disabled secondary progress bar color | `--google-grey-300`
|
73bcce88
luigser
COMPONENTS
|
55
|
`--paper-slider-knob-start-color` | The fill color of the knob at the far left | `transparent`
|
c5169e0e
Renato De Donato
a new hope
|
56
57
|
`--paper-slider-knob-start-border-color` | The border color of the knob at the far left | `#c8c8c8`
`--paper-slider-pin-start-color` | The color of the pin at the far left | `#c8c8c8`
|
73bcce88
luigser
COMPONENTS
|
58
|
`--paper-slider-height` | Height of the progress bar | `2px`
|
73bcce88
luigser
COMPONENTS
|
59
60
61
62
63
64
65
66
|
@group Paper Elements
@element paper-slider
@demo demo/index.html
@hero hero.svg
-->
<dom-module id="paper-slider">
|
eb240478
Luigi Serra
public room cards...
|
67
68
69
|
<template strip-whitespace>
<style>
:host {
|
c5169e0e
Renato De Donato
a new hope
|
70
|
display: inline-block;
|
eb240478
Luigi Serra
public room cards...
|
71
72
73
74
75
76
77
78
79
|
width: 200px;
cursor: default;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
--paper-progress-active-color: var(--paper-slider-active-color, --google-blue-700);
--paper-progress-secondary-color: var(--paper-slider-secondary-color, --google-blue-300);
|
c5169e0e
Renato De Donato
a new hope
|
80
81
|
--paper-progress-disabled-active-color: var(--paper-slider-disabled-active-color, --google-grey-500);
--paper-progress-disabled-secondary-color: var(--paper-slider-disabled-secondary-color, --google-grey-300);
|
eb240478
Luigi Serra
public room cards...
|
82
83
84
85
86
87
88
89
90
|
}
/* focus shows the ripple */
:host(:focus) {
outline: none;
}
#sliderContainer {
position: relative;
|
c5169e0e
Renato De Donato
a new hope
|
91
92
|
width: calc(100% - 32px);
height: 32px;
|
eb240478
Luigi Serra
public room cards...
|
93
94
95
96
97
98
99
|
}
#sliderContainer:focus {
outline: 0;
}
#sliderContainer.editable {
|
c5169e0e
Renato De Donato
a new hope
|
100
101
102
|
float: left;
width: calc(100% - 72px);
margin: 12px 0;
|
eb240478
Luigi Serra
public room cards...
|
103
104
105
106
107
|
}
.bar-container {
position: absolute;
top: 0;
|
c5169e0e
Renato De Donato
a new hope
|
108
109
110
|
left: 16px;
height: 100%;
width: 100%;
|
eb240478
Luigi Serra
public room cards...
|
111
112
113
114
|
overflow: hidden;
}
.ring > .bar-container {
|
c5169e0e
Renato De Donato
a new hope
|
115
116
117
|
left: 20px;
width: calc(100% - 4px);
transition: left 0.18s ease, width 0.18s ease;
|
eb240478
Luigi Serra
public room cards...
|
118
119
|
}
|
c5169e0e
Renato De Donato
a new hope
|
120
121
122
|
.ring.expand:not(.pin) > .bar-container {
left: 30px;
width: calc(100% - 14px);
|
eb240478
Luigi Serra
public room cards...
|
123
124
|
}
|
c5169e0e
Renato De Donato
a new hope
|
125
126
|
.ring.expand.dragging > .bar-container {
transition: none;
|
a1a3bc73
Luigi Serra
graphs updates
|
127
128
|
}
|
eb240478
Luigi Serra
public room cards...
|
129
|
#sliderBar {
|
c5169e0e
Renato De Donato
a new hope
|
130
131
132
|
position: absolute;
top: 15px;
left: 0;
|
eb240478
Luigi Serra
public room cards...
|
133
|
width: 100%;
|
c5169e0e
Renato De Donato
a new hope
|
134
135
|
padding: 8px 0;
margin: -8px 0;
|
eb240478
Luigi Serra
public room cards...
|
136
|
background-color: var(--paper-slider-bar-color, transparent);
|
eb240478
Luigi Serra
public room cards...
|
137
138
139
|
--paper-progress-height: var(--paper-slider-height, 2px);
}
|
c5169e0e
Renato De Donato
a new hope
|
140
141
142
143
144
145
146
147
148
149
|
.ring #sliderBar {
left: -4px;
width: calc(100% + 4px);
}
.ring.expand:not(.pin) #sliderBar {
left: -14px;
width: calc(100% + 14px);
}
|
eb240478
Luigi Serra
public room cards...
|
150
151
|
.slider-markers {
position: absolute;
|
c5169e0e
Renato De Donato
a new hope
|
152
153
154
155
|
top: 15px;
left: 15px;
height: 2px;
width: calc(100% + 2px);
|
eb240478
Luigi Serra
public room cards...
|
156
157
|
box-sizing: border-box;
pointer-events: none;
|
eb240478
Luigi Serra
public room cards...
|
158
159
|
}
|
eb240478
Luigi Serra
public room cards...
|
160
161
162
163
|
.slider-markers::after,
.slider-marker::after {
content: "";
display: block;
|
eb240478
Luigi Serra
public room cards...
|
164
165
166
167
168
169
170
|
width: 2px;
height: 2px;
border-radius: 50%;
background-color: black;
}
#sliderKnob {
|
c5169e0e
Renato De Donato
a new hope
|
171
172
173
174
|
@apply(--layout-center-justified);
@apply(--layout-center);
@apply(--layout-horizontal);
|
eb240478
Luigi Serra
public room cards...
|
175
176
177
|
position: absolute;
left: 0;
top: 0;
|
c5169e0e
Renato De Donato
a new hope
|
178
179
|
width: 32px;
height: 32px;
|
eb240478
Luigi Serra
public room cards...
|
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
}
.transiting > #sliderKnob {
transition: left 0.08s ease;
}
#sliderKnob:focus {
outline: none;
}
#sliderKnob.dragging {
transition: none;
}
.snaps > #sliderKnob.dragging {
transition: -webkit-transform 0.08s ease;
transition: transform 0.08s ease;
}
#sliderKnobInner {
|
c5169e0e
Renato De Donato
a new hope
|
200
201
|
width: 12px;
height: 12px;
|
a1a3bc73
Luigi Serra
graphs updates
|
202
|
border-radius: 50%;
|
c5169e0e
Renato De Donato
a new hope
|
203
|
background-color: var(--paper-slider-knob-color, --google-blue-700);
|
eb240478
Luigi Serra
public room cards...
|
204
205
206
207
|
-moz-box-sizing: border-box;
box-sizing: border-box;
|
c5169e0e
Renato De Donato
a new hope
|
208
209
|
transition-property: height, width, background-color, border;
transition-duration: 0.1s;
|
eb240478
Luigi Serra
public room cards...
|
210
211
212
213
|
transition-timing-function: ease;
}
.expand:not(.pin) > #sliderKnob > #sliderKnobInner {
|
c5169e0e
Renato De Donato
a new hope
|
214
215
216
217
218
|
width: 100%;
height: 100%;
-webkit-transform: translateZ(0);
transform: translateZ(0);
|
eb240478
Luigi Serra
public room cards...
|
219
220
221
222
|
}
.ring > #sliderKnob > #sliderKnobInner {
background-color: var(--paper-slider-knob-start-color, transparent);
|
c5169e0e
Renato De Donato
a new hope
|
223
|
border: 2px solid var(--paper-slider-knob-start-border-color, #c8c8c8);
|
eb240478
Luigi Serra
public room cards...
|
224
225
226
227
228
229
230
231
232
233
|
}
#sliderKnobInner::before {
background-color: var(--paper-slider-pin-color, --google-blue-700);
}
.pin > #sliderKnob > #sliderKnobInner::before {
content: "";
position: absolute;
top: 0;
|
c5169e0e
Renato De Donato
a new hope
|
234
|
left: 0;
|
eb240478
Luigi Serra
public room cards...
|
235
236
|
width: 26px;
height: 26px;
|
c5169e0e
Renato De Donato
a new hope
|
237
|
margin-left: 3px;
|
eb240478
Luigi Serra
public room cards...
|
238
239
240
241
242
243
244
245
|
border-radius: 50% 50% 50% 0;
-webkit-transform: rotate(-45deg) scale(0) translate(0);
transform: rotate(-45deg) scale(0) translate(0);
}
#sliderKnobInner::before,
#sliderKnobInner::after {
|
c5169e0e
Renato De Donato
a new hope
|
246
247
|
transition: -webkit-transform .2s ease, background-color .18s ease;
transition: transform .2s ease, background-color .18s ease;
|
eb240478
Luigi Serra
public room cards...
|
248
249
250
|
}
.pin.ring > #sliderKnob > #sliderKnobInner::before {
|
c5169e0e
Renato De Donato
a new hope
|
251
|
background-color: var(--paper-slider-pin-start-color, #c8c8c8);
|
eb240478
Luigi Serra
public room cards...
|
252
253
254
255
256
257
258
259
260
261
262
|
}
.pin.expand > #sliderKnob > #sliderKnobInner::before {
-webkit-transform: rotate(-45deg) scale(1) translate(17px, -17px);
transform: rotate(-45deg) scale(1) translate(17px, -17px);
}
.pin > #sliderKnob > #sliderKnobInner::after {
content: attr(value);
position: absolute;
top: 0;
|
c5169e0e
Renato De Donato
a new hope
|
263
|
left: 0;
|
eb240478
Luigi Serra
public room cards...
|
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
width: 32px;
height: 26px;
text-align: center;
color: var(--paper-slider-font-color, #fff);
font-size: 10px;
-webkit-transform: scale(0) translate(0);
transform: scale(0) translate(0);
}
.pin.expand > #sliderKnob > #sliderKnobInner::after {
-webkit-transform: scale(1) translate(0, -17px);
transform: scale(1) translate(0, -17px);
}
/* paper-input */
.slider-input {
width: 50px;
|
c5169e0e
Renato De Donato
a new hope
|
282
|
float: right;
|
eb240478
Luigi Serra
public room cards...
|
283
284
285
286
|
overflow: hidden;
--paper-input-container-input: {
text-align: center;
};
|
eb240478
Luigi Serra
public room cards...
|
287
|
}
|
73bcce88
luigser
COMPONENTS
|
288
|
|
eb240478
Luigi Serra
public room cards...
|
289
290
291
292
293
294
|
/* disabled state */
#sliderContainer.disabled {
pointer-events: none;
}
.disabled > #sliderKnob > #sliderKnobInner {
|
c5169e0e
Renato De Donato
a new hope
|
295
296
297
|
width: 8px;
height: 8px;
background-color: var(--paper-slider-disabled-knob-color, --google-grey-500);
|
eb240478
Luigi Serra
public room cards...
|
298
299
300
|
}
.disabled.ring > #sliderKnob > #sliderKnobInner {
|
c5169e0e
Renato De Donato
a new hope
|
301
|
background-color: transparent;
|
eb240478
Luigi Serra
public room cards...
|
302
303
304
305
306
|
}
paper-ripple {
color: var(--paper-slider-knob-color, --google-blue-700);
}
|
a1a3bc73
Luigi Serra
graphs updates
|
307
|
|
c5169e0e
Renato De Donato
a new hope
|
308
|
</style>
|
73bcce88
luigser
COMPONENTS
|
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
|
<div id="sliderContainer"
class$="[[_getClassNames(disabled, pin, snaps, immediateValue, min, expand, dragging, transiting, editable)]]">
<div class="bar-container">
<paper-progress
disabled$="[[disabled]]"
id="sliderBar"
aria-hidden="true"
min="[[min]]"
max="[[max]]"
step="[[step]]"
value="[[immediateValue]]"
secondary-progress="[[secondaryProgress]]"
on-down="_bardown"
on-up="_resetKnob"
on-track="_onTrack">
</paper-progress>
</div>
<template is="dom-if" if="[[snaps]]">
|
c5169e0e
Renato De Donato
a new hope
|
329
|
<div class="slider-markers horizontal layout">
|
73bcce88
luigser
COMPONENTS
|
330
|
<template is="dom-repeat" items="[[markers]]">
|
c5169e0e
Renato De Donato
a new hope
|
331
|
<div class="slider-marker flex"></div>
|
73bcce88
luigser
COMPONENTS
|
332
333
334
335
336
|
</template>
</div>
</template>
<div id="sliderKnob"
|
c5169e0e
Renato De Donato
a new hope
|
337
|
class="center-justified center horizontal layout"
|
73bcce88
luigser
COMPONENTS
|
338
339
340
341
|
on-down="_knobdown"
on-up="_resetKnob"
on-track="_onTrack"
on-transitionend="_knobTransitionEnd">
|
73bcce88
luigser
COMPONENTS
|
342
343
344
|
<div id="sliderKnobInner" value$="[[immediateValue]]"></div>
</div>
</div>
|
73bcce88
luigser
COMPONENTS
|
345
346
347
|
<template is="dom-if" if="[[editable]]">
<paper-input
id="input"
|
eb240478
Luigi Serra
public room cards...
|
348
349
350
351
|
type="number"
step="[[step]]"
min="[[min]]"
max="[[max]]"
|
73bcce88
luigser
COMPONENTS
|
352
353
|
class="slider-input"
disabled$="[[disabled]]"
|
eb240478
Luigi Serra
public room cards...
|
354
355
356
357
|
value="[[immediateValue]]"
on-change="_changeValue"
on-keydown="_inputKeyDown"
no-label-float>
|
73bcce88
luigser
COMPONENTS
|
358
359
360
|
</paper-input>
</template>
</template>
|
c5169e0e
Renato De Donato
a new hope
|
361
|
</dom-module>
|
73bcce88
luigser
COMPONENTS
|
362
|
|
c5169e0e
Renato De Donato
a new hope
|
363
|
<script>
|
73bcce88
luigser
COMPONENTS
|
364
|
|
c5169e0e
Renato De Donato
a new hope
|
365
366
|
Polymer({
is: 'paper-slider',
|
73bcce88
luigser
COMPONENTS
|
367
|
|
c5169e0e
Renato De Donato
a new hope
|
368
369
370
371
372
|
behaviors: [
Polymer.IronFormElementBehavior,
Polymer.PaperInkyFocusBehavior,
Polymer.IronRangeBehavior
],
|
73bcce88
luigser
COMPONENTS
|
373
|
|
c5169e0e
Renato De Donato
a new hope
|
374
|
properties: {
|
73bcce88
luigser
COMPONENTS
|
375
|
|
c5169e0e
Renato De Donato
a new hope
|
376
377
378
379
380
381
382
383
|
/**
* If true, the slider thumb snaps to tick marks evenly spaced based
* on the `step` property value.
*/
snaps: {
type: Boolean,
value: false,
notify: true
|
73bcce88
luigser
COMPONENTS
|
384
385
386
|
},
/**
|
c5169e0e
Renato De Donato
a new hope
|
387
388
389
|
* If true, a pin with numeric value label is shown when the slider thumb
* is pressed. Use for settings for which users need to know the exact
* value of the setting.
|
73bcce88
luigser
COMPONENTS
|
390
|
*/
|
c5169e0e
Renato De Donato
a new hope
|
391
392
393
394
|
pin: {
type: Boolean,
value: false,
notify: true
|
73bcce88
luigser
COMPONENTS
|
395
396
397
|
},
/**
|
c5169e0e
Renato De Donato
a new hope
|
398
|
* The number that represents the current secondary progress.
|
73bcce88
luigser
COMPONENTS
|
399
|
*/
|
c5169e0e
Renato De Donato
a new hope
|
400
401
402
403
404
|
secondaryProgress: {
type: Number,
value: 0,
notify: true,
observer: '_secondaryProgressChanged'
|
73bcce88
luigser
COMPONENTS
|
405
406
|
},
|
c5169e0e
Renato De Donato
a new hope
|
407
408
409
410
411
412
|
/**
* If true, an input is shown and user can use it to set the slider value.
*/
editable: {
type: Boolean,
value: false
|
73bcce88
luigser
COMPONENTS
|
413
414
|
},
|
c5169e0e
Renato De Donato
a new hope
|
415
416
417
418
419
420
421
422
423
|
/**
* The immediate value of the slider. This value is updated while the user
* is dragging the slider.
*/
immediateValue: {
type: Number,
value: 0,
readOnly: true,
notify: true
|
73bcce88
luigser
COMPONENTS
|
424
425
|
},
|
c5169e0e
Renato De Donato
a new hope
|
426
427
428
429
430
431
432
433
|
/**
* The maximum number of markers
*/
maxMarkers: {
type: Number,
value: 0,
notify: true,
observer: '_maxMarkersChanged'
|
73bcce88
luigser
COMPONENTS
|
434
435
|
},
|
c5169e0e
Renato De Donato
a new hope
|
436
437
438
439
440
441
442
|
/**
* If true, the knob is expanded
*/
expand: {
type: Boolean,
value: false,
readOnly: true
|
73bcce88
luigser
COMPONENTS
|
443
444
|
},
|
c5169e0e
Renato De Donato
a new hope
|
445
446
447
448
449
450
451
|
/**
* True when the user is dragging the slider.
*/
dragging: {
type: Boolean,
value: false,
readOnly: true
|
73bcce88
luigser
COMPONENTS
|
452
453
|
},
|
c5169e0e
Renato De Donato
a new hope
|
454
455
456
457
|
transiting: {
type: Boolean,
value: false,
readOnly: true
|
73bcce88
luigser
COMPONENTS
|
458
|
},
|
73bcce88
luigser
COMPONENTS
|
459
|
|
c5169e0e
Renato De Donato
a new hope
|
460
461
462
463
|
markers: {
type: Array,
readOnly: true,
value: []
|
a1a3bc73
Luigi Serra
graphs updates
|
464
|
},
|
c5169e0e
Renato De Donato
a new hope
|
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
|
},
observers: [
'_updateKnob(value, min, max, snaps, step)',
'_valueChanged(value)',
'_immediateValueChanged(immediateValue)'
],
hostAttributes: {
role: 'slider',
tabindex: 0
},
keyBindings: {
'left down pagedown home': '_decrementKey',
'right up pageup end': '_incrementKey'
},
ready: function() {
// issue polymer/polymer#1305
this.async(function() {
this._updateKnob(this.value);
}, 1);
},
|
73bcce88
luigser
COMPONENTS
|
489
|
|
c5169e0e
Renato De Donato
a new hope
|
490
491
492
493
494
495
496
|
/**
* Increases value by `step` but not above `max`.
* @method increment
*/
increment: function() {
this.value = this._clampValue(this.value + this.step);
},
|
73bcce88
luigser
COMPONENTS
|
497
|
|
c5169e0e
Renato De Donato
a new hope
|
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
|
/**
* Decreases value by `step` but not below `min`.
* @method decrement
*/
decrement: function() {
this.value = this._clampValue(this.value - this.step);
},
_updateKnob: function(value, min, max, snaps, step) {
this.setAttribute('aria-valuemin', min);
this.setAttribute('aria-valuemax', max);
this.setAttribute('aria-valuenow', value);
this._positionKnob(this._calcRatio(value));
},
_valueChanged: function() {
this.fire('value-change');
},
_immediateValueChanged: function() {
if (this.dragging) {
this.fire('immediate-value-change');
} else {
this.value = this.immediateValue;
}
},
|
73bcce88
luigser
COMPONENTS
|
525
|
|
c5169e0e
Renato De Donato
a new hope
|
526
527
528
|
_secondaryProgressChanged: function() {
this.secondaryProgress = this._clampValue(this.secondaryProgress);
},
|
73bcce88
luigser
COMPONENTS
|
529
|
|
c5169e0e
Renato De Donato
a new hope
|
530
531
532
|
_expandKnob: function() {
this._setExpand(true);
},
|
73bcce88
luigser
COMPONENTS
|
533
|
|
c5169e0e
Renato De Donato
a new hope
|
534
535
536
537
|
_resetKnob: function() {
this.cancelDebouncer('expandKnob');
this._setExpand(false);
},
|
73bcce88
luigser
COMPONENTS
|
538
|
|
c5169e0e
Renato De Donato
a new hope
|
539
540
541
|
_positionKnob: function(ratio) {
this._setImmediateValue(this._calcStep(this._calcKnobPosition(ratio)));
this._setRatio(this._calcRatio(this.immediateValue));
|
73bcce88
luigser
COMPONENTS
|
542
|
|
c5169e0e
Renato De Donato
a new hope
|
543
544
|
this.$.sliderKnob.style.left = (this.ratio * 100) + '%';
},
|
73bcce88
luigser
COMPONENTS
|
545
|
|
c5169e0e
Renato De Donato
a new hope
|
546
547
548
|
_calcKnobPosition: function(ratio) {
return (this.max - this.min) * ratio + this.min;
},
|
73bcce88
luigser
COMPONENTS
|
549
|
|
c5169e0e
Renato De Donato
a new hope
|
550
551
552
553
554
555
556
557
558
559
560
561
562
563
|
_onTrack: function(event) {
event.stopPropagation();
switch (event.detail.state) {
case 'start':
this._trackStart(event);
break;
case 'track':
this._trackX(event);
break;
case 'end':
this._trackEnd();
break;
}
},
|
73bcce88
luigser
COMPONENTS
|
564
|
|
c5169e0e
Renato De Donato
a new hope
|
565
566
567
568
569
570
571
572
573
|
_trackStart: function(event) {
this._w = this.$.sliderBar.offsetWidth;
this._x = this.ratio * this._w;
this._startx = this._x || 0;
this._minx = - this._startx;
this._maxx = this._w - this._startx;
this.$.sliderKnob.classList.add('dragging');
this._setDragging(true);
},
|
73bcce88
luigser
COMPONENTS
|
574
|
|
c5169e0e
Renato De Donato
a new hope
|
575
576
577
578
|
_trackX: function(e) {
if (!this.dragging) {
this._trackStart(e);
}
|
73bcce88
luigser
COMPONENTS
|
579
|
|
c5169e0e
Renato De Donato
a new hope
|
580
581
|
var dx = Math.min(this._maxx, Math.max(this._minx, e.detail.dx));
this._x = this._startx + dx;
|
73bcce88
luigser
COMPONENTS
|
582
|
|
c5169e0e
Renato De Donato
a new hope
|
583
584
|
var immediateValue = this._calcStep(this._calcKnobPosition(this._x / this._w));
this._setImmediateValue(immediateValue);
|
73bcce88
luigser
COMPONENTS
|
585
|
|
c5169e0e
Renato De Donato
a new hope
|
586
587
588
589
|
// update knob's position
var translateX = ((this._calcRatio(immediateValue) * this._w) - this._startx);
this.translate3d(translateX + 'px', 0, 0, this.$.sliderKnob);
},
|
73bcce88
luigser
COMPONENTS
|
590
|
|
c5169e0e
Renato De Donato
a new hope
|
591
592
|
_trackEnd: function() {
var s = this.$.sliderKnob.style;
|
73bcce88
luigser
COMPONENTS
|
593
|
|
c5169e0e
Renato De Donato
a new hope
|
594
595
596
597
|
this.$.sliderKnob.classList.remove('dragging');
this._setDragging(false);
this._resetKnob();
this.value = this.immediateValue;
|
73bcce88
luigser
COMPONENTS
|
598
|
|
c5169e0e
Renato De Donato
a new hope
|
599
|
s.transform = s.webkitTransform = '';
|
73bcce88
luigser
COMPONENTS
|
600
|
|
c5169e0e
Renato De Donato
a new hope
|
601
602
|
this.fire('change');
},
|
73bcce88
luigser
COMPONENTS
|
603
|
|
c5169e0e
Renato De Donato
a new hope
|
604
605
|
_knobdown: function(event) {
this._expandKnob();
|
73bcce88
luigser
COMPONENTS
|
606
|
|
c5169e0e
Renato De Donato
a new hope
|
607
608
|
// cancel selection
event.preventDefault();
|
73bcce88
luigser
COMPONENTS
|
609
|
|
c5169e0e
Renato De Donato
a new hope
|
610
611
612
|
// set the focus manually because we will called prevent default
this.focus();
},
|
73bcce88
luigser
COMPONENTS
|
613
|
|
c5169e0e
Renato De Donato
a new hope
|
614
615
616
617
618
|
_bardown: function(event) {
this._w = this.$.sliderBar.offsetWidth;
var rect = this.$.sliderBar.getBoundingClientRect();
var ratio = (event.detail.x - rect.left) / this._w;
var prevRatio = this.ratio;
|
73bcce88
luigser
COMPONENTS
|
619
|
|
c5169e0e
Renato De Donato
a new hope
|
620
|
this._setTransiting(true);
|
73bcce88
luigser
COMPONENTS
|
621
|
|
c5169e0e
Renato De Donato
a new hope
|
622
|
this._positionKnob(ratio);
|
73bcce88
luigser
COMPONENTS
|
623
|
|
c5169e0e
Renato De Donato
a new hope
|
624
|
this.debounce('expandKnob', this._expandKnob, 60);
|
73bcce88
luigser
COMPONENTS
|
625
|
|
c5169e0e
Renato De Donato
a new hope
|
626
627
628
|
// if the ratio doesn't change, sliderKnob's animation won't start
// and `_knobTransitionEnd` won't be called
// Therefore, we need to manually update the `transiting` state
|
a1a3bc73
Luigi Serra
graphs updates
|
629
|
|
c5169e0e
Renato De Donato
a new hope
|
630
631
632
|
if (prevRatio === this.ratio) {
this._setTransiting(false);
}
|
73bcce88
luigser
COMPONENTS
|
633
|
|
c5169e0e
Renato De Donato
a new hope
|
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
|
this.async(function() {
this.fire('change');
});
// cancel selection
event.preventDefault();
},
_knobTransitionEnd: function(event) {
if (event.target === this.$.sliderKnob) {
this._setTransiting(false);
}
},
_maxMarkersChanged: function(maxMarkers) {
var l = (this.max - this.min) / this.step;
if (!this.snaps && l > maxMarkers) {
this._setMarkers([]);
} else {
this._setMarkers(new Array(l));
}
},
_mergeClasses: function(classes) {
return Object.keys(classes).filter(
function(className) {
return classes[className];
}).join(' ');
},
_getClassNames: function() {
return this._mergeClasses({
disabled: this.disabled,
pin: this.pin,
snaps: this.snaps,
ring: this.immediateValue <= this.min,
expand: this.expand,
dragging: this.dragging,
transiting: this.transiting,
editable: this.editable
});
},
_incrementKey: function(event) {
if (!this.disabled) {
if (event.detail.key === 'end') {
this.value = this.max;
} else {
this.increment();
|
eb240478
Luigi Serra
public room cards...
|
683
|
}
|
a1a3bc73
Luigi Serra
graphs updates
|
684
|
this.fire('change');
|
c5169e0e
Renato De Donato
a new hope
|
685
686
|
}
},
|
eb240478
Luigi Serra
public room cards...
|
687
|
|
c5169e0e
Renato De Donato
a new hope
|
688
689
690
691
692
693
|
_decrementKey: function(event) {
if (!this.disabled) {
if (event.detail.key === 'home') {
this.value = this.min;
} else {
this.decrement();
|
eb240478
Luigi Serra
public room cards...
|
694
|
}
|
c5169e0e
Renato De Donato
a new hope
|
695
|
this.fire('change');
|
a1a3bc73
Luigi Serra
graphs updates
|
696
|
}
|
c5169e0e
Renato De Donato
a new hope
|
697
|
},
|
a1a3bc73
Luigi Serra
graphs updates
|
698
|
|
c5169e0e
Renato De Donato
a new hope
|
699
700
701
702
|
_changeValue: function(event) {
this.value = event.target.value;
this.fire('change');
},
|
a1a3bc73
Luigi Serra
graphs updates
|
703
|
|
c5169e0e
Renato De Donato
a new hope
|
704
705
706
|
_inputKeyDown: function(event) {
event.stopPropagation();
},
|
a1a3bc73
Luigi Serra
graphs updates
|
707
|
|
c5169e0e
Renato De Donato
a new hope
|
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
|
// create the element ripple inside the `sliderKnob`
_createRipple: function() {
this._rippleContainer = this.$.sliderKnob;
return Polymer.PaperInkyFocusBehaviorImpl._createRipple.call(this);
},
// Hide the ripple when user is not interacting with keyboard.
// This behavior is different from other ripple-y controls, but is
// according to spec: https://www.google.com/design/spec/components/sliders.html
_focusedChanged: function(receivedFocusFromKeyboard) {
if (receivedFocusFromKeyboard) {
this.ensureRipple();
}
if (this.hasRipple()) {
// note, ripple must be un-hidden prior to setting `holdDown`
if (receivedFocusFromKeyboard) {
this._ripple.removeAttribute('hidden');
} else {
this._ripple.setAttribute('hidden', '');
}
this._ripple.holdDown = receivedFocusFromKeyboard;
}
}
});
/**
* Fired when the slider's value changes.
*
* @event value-change
*/
/**
* Fired when the slider's immediateValue changes.
*
* @event immediate-value-change
*/
/**
* Fired when the slider's value changes due to user interaction.
*
* Changes to the slider's value due to changes in an underlying
* bound variable will not trigger this event.
*
* @event change
*/
</script>
|