2015-06-26 20:27:38 -07:00
|
|
|
<!--
|
|
|
|
@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">
|
|
|
|
<link rel="import" href="../iron-a11y-keys-behavior/iron-a11y-keys-behavior.html">
|
2016-01-12 10:58:06 -07:00
|
|
|
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
|
2015-06-26 20:27:38 -07:00
|
|
|
<link rel="import" href="../iron-form-element-behavior/iron-form-element-behavior.html">
|
2016-01-12 10:58:06 -07:00
|
|
|
<link rel="import" href="../iron-range-behavior/iron-range-behavior.html">
|
|
|
|
<link rel="import" href="../paper-behaviors/paper-inky-focus-behavior.html">
|
|
|
|
<link rel="import" href="../paper-input/paper-input.html">
|
|
|
|
<link rel="import" href="../paper-progress/paper-progress.html">
|
|
|
|
<link rel="import" href="../paper-styles/color.html">
|
2015-06-26 20:27:38 -07:00
|
|
|
|
|
|
|
<!--
|
2015-10-07 18:49:40 -07:00
|
|
|
Material design: [Sliders](https://www.google.com/design/spec/components/sliders.html)
|
|
|
|
|
2015-06-26 20:27:38 -07:00
|
|
|
`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`
|
2016-01-12 10:58:06 -07:00
|
|
|
`--paper-slider-disabled-knob-color` | The disabled knob color | `--paper-grey-400`
|
2015-06-26 20:27:38 -07:00
|
|
|
`--paper-slider-pin-color` | The pin color | `--google-blue-700`
|
|
|
|
`--paper-slider-font-color` | The pin's text color | `#fff`
|
2016-01-12 10:58:06 -07:00
|
|
|
`--paper-slider-disabled-active-color` | The disabled progress bar color | `--paper-grey-400`
|
|
|
|
`--paper-slider-disabled-secondary-color` | The disabled secondary progress bar color | `--paper-grey-400`
|
2015-08-04 07:26:36 -07:00
|
|
|
`--paper-slider-knob-start-color` | The fill color of the knob at the far left | `transparent`
|
2016-01-12 10:58:06 -07:00
|
|
|
`--paper-slider-knob-start-border-color` | The border color of the knob at the far left | `--paper-grey-400`
|
|
|
|
`--paper-slider-pin-start-color` | The color of the pin at the far left | `--paper-grey-400`
|
2015-09-14 18:17:19 -07:00
|
|
|
`--paper-slider-height` | Height of the progress bar | `2px`
|
2016-01-12 10:58:06 -07:00
|
|
|
`--paper-slider-input` | Mixin applied to the input in editable mode | `{}`
|
2015-06-26 20:27:38 -07:00
|
|
|
|
|
|
|
@group Paper Elements
|
|
|
|
@element paper-slider
|
|
|
|
@demo demo/index.html
|
|
|
|
@hero hero.svg
|
|
|
|
-->
|
|
|
|
|
|
|
|
<dom-module id="paper-slider">
|
2015-10-07 18:49:40 -07:00
|
|
|
<template strip-whitespace>
|
|
|
|
<style>
|
|
|
|
:host {
|
2015-12-14 08:43:03 -07:00
|
|
|
@apply(--layout);
|
|
|
|
@apply(--layout-justified);
|
|
|
|
@apply(--layout-center);
|
2015-10-07 18:49:40 -07:00
|
|
|
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);
|
2016-01-12 10:58:06 -07:00
|
|
|
--paper-progress-disabled-active-color: var(--paper-slider-disabled-active-color, --paper-grey-400);
|
|
|
|
--paper-progress-disabled-secondary-color: var(--paper-slider-disabled-secondary-color, --paper-grey-400);
|
2015-10-07 18:49:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* focus shows the ripple */
|
|
|
|
:host(:focus) {
|
|
|
|
outline: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
#sliderContainer {
|
|
|
|
position: relative;
|
2015-12-14 08:43:03 -07:00
|
|
|
width: 100%;
|
|
|
|
height: calc(30px + var(--paper-slider-height, 2px));
|
|
|
|
margin-left: calc(15px + var(--paper-slider-height, 2px)/2);
|
|
|
|
margin-right: calc(15px + var(--paper-slider-height, 2px)/2);
|
2015-10-07 18:49:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#sliderContainer:focus {
|
|
|
|
outline: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#sliderContainer.editable {
|
2015-12-14 08:43:03 -07:00
|
|
|
margin-top: 12px;
|
|
|
|
margin-bottom: 12px;
|
2015-10-07 18:49:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
.bar-container {
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
2015-12-14 08:43:03 -07:00
|
|
|
bottom: 0;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
2015-10-07 18:49:40 -07:00
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
.ring > .bar-container {
|
2015-12-14 08:43:03 -07:00
|
|
|
left: calc(5px + var(--paper-slider-height, 2px)/2);
|
2016-01-12 10:58:06 -07:00
|
|
|
transition: left 0.18s ease;
|
2015-10-07 18:49:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
.ring.expand.dragging > .bar-container {
|
|
|
|
transition: none;
|
|
|
|
}
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
.ring.expand:not(.pin) > .bar-container {
|
2016-01-12 10:58:06 -07:00
|
|
|
left: calc(8px + var(--paper-slider-height, 2px)/2);
|
2015-12-14 08:43:03 -07:00
|
|
|
}
|
|
|
|
|
2015-10-07 18:49:40 -07:00
|
|
|
#sliderBar {
|
2015-12-14 08:43:03 -07:00
|
|
|
padding: 15px 0;
|
2015-10-07 18:49:40 -07:00
|
|
|
width: 100%;
|
|
|
|
background-color: var(--paper-slider-bar-color, transparent);
|
2016-01-12 10:58:06 -07:00
|
|
|
--paper-progress-container-color: var(--paper-grey-400);
|
2015-10-07 18:49:40 -07:00
|
|
|
--paper-progress-height: var(--paper-slider-height, 2px);
|
|
|
|
}
|
|
|
|
|
|
|
|
.slider-markers {
|
|
|
|
position: absolute;
|
2015-12-14 08:43:03 -07:00
|
|
|
top: calc(14px + var(--paper-slider-height,2px)/2);
|
|
|
|
height: var(--paper-slider-height, 2px);
|
|
|
|
left: 0;
|
|
|
|
right: -1px;
|
2015-10-07 18:49:40 -07:00
|
|
|
box-sizing: border-box;
|
|
|
|
pointer-events: none;
|
2015-12-14 08:43:03 -07:00
|
|
|
@apply(--layout-horizontal);
|
2015-10-07 18:49:40 -07:00
|
|
|
}
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
.slider-marker {
|
|
|
|
@apply(--layout-flex);
|
|
|
|
}
|
2015-10-07 18:49:40 -07:00
|
|
|
.slider-markers::after,
|
|
|
|
.slider-marker::after {
|
|
|
|
content: "";
|
|
|
|
display: block;
|
2015-12-14 08:43:03 -07:00
|
|
|
margin-left: -1px;
|
2015-10-07 18:49:40 -07:00
|
|
|
width: 2px;
|
|
|
|
height: 2px;
|
|
|
|
border-radius: 50%;
|
|
|
|
background-color: black;
|
|
|
|
}
|
|
|
|
|
|
|
|
#sliderKnob {
|
|
|
|
position: absolute;
|
|
|
|
left: 0;
|
|
|
|
top: 0;
|
2015-12-14 08:43:03 -07:00
|
|
|
margin-left: calc(-15px - var(--paper-slider-height, 2px)/2);
|
|
|
|
width: calc(30px + var(--paper-slider-height, 2px));
|
|
|
|
height: calc(30px + var(--paper-slider-height, 2px));
|
2015-10-07 18:49:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
.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 {
|
2015-12-14 08:43:03 -07:00
|
|
|
margin: 10px;
|
|
|
|
width: calc(100% - 20px);
|
|
|
|
height: calc(100% - 20px);
|
2015-10-07 18:49:40 -07:00
|
|
|
background-color: var(--paper-slider-knob-color, --google-blue-700);
|
2016-01-12 10:58:06 -07:00
|
|
|
border: 2px solid var(--paper-slider-knob-color, --google-blue-700);
|
|
|
|
border-radius: 50%;
|
2015-10-07 18:49:40 -07:00
|
|
|
|
|
|
|
-moz-box-sizing: border-box;
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
transition-property: -webkit-transform, background-color, border;
|
|
|
|
transition-property: transform, background-color, border;
|
|
|
|
transition-duration: 0.18s;
|
2015-10-07 18:49:40 -07:00
|
|
|
transition-timing-function: ease;
|
|
|
|
}
|
|
|
|
|
|
|
|
.expand:not(.pin) > #sliderKnob > #sliderKnobInner {
|
2016-01-12 10:58:06 -07:00
|
|
|
-webkit-transform: scale(1.5);
|
|
|
|
transform: scale(1.5);
|
2015-10-07 18:49:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
.ring > #sliderKnob > #sliderKnobInner {
|
|
|
|
background-color: var(--paper-slider-knob-start-color, transparent);
|
2016-01-12 10:58:06 -07:00
|
|
|
border: 2px solid var(--paper-slider-knob-start-border-color, --paper-grey-400);
|
2015-10-07 18:49:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#sliderKnobInner::before {
|
|
|
|
background-color: var(--paper-slider-pin-color, --google-blue-700);
|
|
|
|
}
|
|
|
|
|
|
|
|
.pin > #sliderKnob > #sliderKnobInner::before {
|
|
|
|
content: "";
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
2015-12-14 08:43:03 -07:00
|
|
|
left: 50%;
|
|
|
|
margin-left: -13px;
|
2015-10-07 18:49:40 -07:00
|
|
|
width: 26px;
|
|
|
|
height: 26px;
|
|
|
|
border-radius: 50% 50% 50% 0;
|
|
|
|
|
|
|
|
-webkit-transform: rotate(-45deg) scale(0) translate(0);
|
|
|
|
transform: rotate(-45deg) scale(0) translate(0);
|
|
|
|
}
|
2015-06-26 20:27:38 -07:00
|
|
|
|
2015-10-07 18:49:40 -07:00
|
|
|
#sliderKnobInner::before,
|
|
|
|
#sliderKnobInner::after {
|
2016-01-12 10:58:06 -07:00
|
|
|
transition: -webkit-transform .18s ease, background-color .18s ease;
|
|
|
|
transition: transform .18s ease, background-color .18s ease;
|
2015-10-07 18:49:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
.pin.ring > #sliderKnob > #sliderKnobInner::before {
|
2016-01-12 10:58:06 -07:00
|
|
|
background-color: var(--paper-slider-pin-start-color, --paper-grey-400);
|
2015-10-07 18:49:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
.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;
|
2015-12-14 08:43:03 -07:00
|
|
|
left: 50%;
|
|
|
|
margin-left: -16px;
|
2015-10-07 18:49:40 -07:00
|
|
|
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;
|
|
|
|
overflow: hidden;
|
|
|
|
--paper-input-container-input: {
|
|
|
|
text-align: center;
|
|
|
|
};
|
2016-01-12 10:58:06 -07:00
|
|
|
@apply(--paper-slider-input);
|
2015-10-07 18:49:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* disabled state */
|
|
|
|
#sliderContainer.disabled {
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2015-10-07 18:49:40 -07:00
|
|
|
.disabled > #sliderKnob > #sliderKnobInner {
|
2016-01-12 10:58:06 -07:00
|
|
|
background-color: var(--paper-slider-disabled-knob-color, --paper-grey-400);
|
|
|
|
border: 2px solid var(--paper-slider-disabled-knob-color, --paper-grey-400);
|
|
|
|
-webkit-transform: scale3d(0.75, 0.75, 1);
|
|
|
|
transform: scale3d(0.75, 0.75, 1);
|
2015-10-07 18:49:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
.disabled.ring > #sliderKnob > #sliderKnobInner {
|
2016-01-12 10:58:06 -07:00
|
|
|
background-color: var(--paper-slider-knob-start-color, transparent);
|
|
|
|
border: 2px solid var(--paper-slider-knob-start-border-color, --paper-grey-400);
|
2015-10-07 18:49:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
paper-ripple {
|
|
|
|
color: var(--paper-slider-knob-color, --google-blue-700);
|
|
|
|
}
|
|
|
|
</style>
|
2016-01-12 10:58:06 -07:00
|
|
|
|
2015-08-04 07:26:36 -07:00
|
|
|
<div id="sliderContainer"
|
|
|
|
class$="[[_getClassNames(disabled, pin, snaps, immediateValue, min, expand, dragging, transiting, editable)]]">
|
|
|
|
|
|
|
|
<div class="bar-container">
|
|
|
|
<paper-progress
|
2015-09-14 18:17:19 -07:00
|
|
|
disabled$="[[disabled]]"
|
2015-08-04 07:26:36 -07:00
|
|
|
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]]">
|
2015-12-14 08:43:03 -07:00
|
|
|
<div class="slider-markers">
|
2015-08-04 07:26:36 -07:00
|
|
|
<template is="dom-repeat" items="[[markers]]">
|
2015-12-14 08:43:03 -07:00
|
|
|
<div class="slider-marker"></div>
|
2015-08-04 07:26:36 -07:00
|
|
|
</template>
|
2015-06-26 20:27:38 -07:00
|
|
|
</div>
|
2015-08-04 07:26:36 -07:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<div id="sliderKnob"
|
|
|
|
on-down="_knobdown"
|
|
|
|
on-up="_resetKnob"
|
|
|
|
on-track="_onTrack"
|
|
|
|
on-transitionend="_knobTransitionEnd">
|
2016-03-21 19:06:21 -07:00
|
|
|
<div id="sliderKnobInner" value$="[[immediateValue]]"></div>
|
2015-08-04 07:26:36 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
2016-01-12 10:58:06 -07:00
|
|
|
|
2015-08-04 07:26:36 -07:00
|
|
|
<template is="dom-if" if="[[editable]]">
|
|
|
|
<paper-input
|
|
|
|
id="input"
|
2015-10-07 18:49:40 -07:00
|
|
|
type="number"
|
|
|
|
step="[[step]]"
|
|
|
|
min="[[min]]"
|
|
|
|
max="[[max]]"
|
2015-08-04 07:26:36 -07:00
|
|
|
class="slider-input"
|
|
|
|
disabled$="[[disabled]]"
|
2015-10-07 18:49:40 -07:00
|
|
|
value="[[immediateValue]]"
|
|
|
|
on-change="_changeValue"
|
|
|
|
on-keydown="_inputKeyDown"
|
|
|
|
no-label-float>
|
2015-08-04 07:26:36 -07:00
|
|
|
</paper-input>
|
2015-06-26 20:27:38 -07:00
|
|
|
</template>
|
2015-08-04 07:26:36 -07:00
|
|
|
</template>
|
2015-06-26 20:27:38 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
<script>
|
|
|
|
Polymer({
|
|
|
|
is: 'paper-slider',
|
|
|
|
|
|
|
|
behaviors: [
|
|
|
|
Polymer.IronA11yKeysBehavior,
|
|
|
|
Polymer.IronFormElementBehavior,
|
|
|
|
Polymer.PaperInkyFocusBehavior,
|
|
|
|
Polymer.IronRangeBehavior
|
|
|
|
],
|
|
|
|
|
|
|
|
properties: {
|
|
|
|
/**
|
|
|
|
* If true, the slider thumb snaps to tick marks evenly spaced based
|
|
|
|
* on the `step` property value.
|
|
|
|
*/
|
|
|
|
snaps: {
|
|
|
|
type: Boolean,
|
|
|
|
value: false,
|
|
|
|
notify: true
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
pin: {
|
|
|
|
type: Boolean,
|
|
|
|
value: false,
|
|
|
|
notify: true
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The number that represents the current secondary progress.
|
|
|
|
*/
|
|
|
|
secondaryProgress: {
|
|
|
|
type: Number,
|
|
|
|
value: 0,
|
|
|
|
notify: true,
|
|
|
|
observer: '_secondaryProgressChanged'
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If true, an input is shown and user can use it to set the slider value.
|
|
|
|
*/
|
|
|
|
editable: {
|
|
|
|
type: Boolean,
|
|
|
|
value: false
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The maximum number of markers
|
|
|
|
*/
|
|
|
|
maxMarkers: {
|
|
|
|
type: Number,
|
|
|
|
value: 0,
|
|
|
|
notify: true,
|
|
|
|
observer: '_maxMarkersChanged'
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If true, the knob is expanded
|
|
|
|
*/
|
|
|
|
expand: {
|
|
|
|
type: Boolean,
|
|
|
|
value: false,
|
|
|
|
readOnly: true
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* True when the user is dragging the slider.
|
|
|
|
*/
|
|
|
|
dragging: {
|
|
|
|
type: Boolean,
|
|
|
|
value: false,
|
|
|
|
readOnly: true
|
|
|
|
},
|
|
|
|
|
|
|
|
transiting: {
|
|
|
|
type: Boolean,
|
|
|
|
value: false,
|
|
|
|
readOnly: true
|
|
|
|
},
|
|
|
|
|
|
|
|
markers: {
|
|
|
|
type: Array,
|
|
|
|
readOnly: true,
|
|
|
|
value: []
|
|
|
|
},
|
|
|
|
},
|
2015-06-26 20:27:38 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
observers: [
|
|
|
|
'_updateKnob(value, min, max, snaps, step)',
|
|
|
|
'_valueChanged(value)',
|
|
|
|
'_immediateValueChanged(immediateValue)'
|
|
|
|
],
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
hostAttributes: {
|
|
|
|
role: 'slider',
|
|
|
|
tabindex: 0
|
|
|
|
},
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
keyBindings: {
|
|
|
|
'left down pagedown home': '_decrementKey',
|
|
|
|
'right up pageup end': '_incrementKey'
|
|
|
|
},
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
ready: function() {
|
|
|
|
// issue polymer/polymer#1305
|
|
|
|
this.async(function() {
|
|
|
|
this._updateKnob(this.value);
|
|
|
|
}, 1);
|
2015-08-04 07:26:36 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2016-01-12 10:58:06 -07:00
|
|
|
* Increases value by `step` but not above `max`.
|
|
|
|
* @method increment
|
2015-08-04 07:26:36 -07:00
|
|
|
*/
|
2016-01-12 10:58:06 -07:00
|
|
|
increment: function() {
|
|
|
|
this.value = this._clampValue(this.value + this.step);
|
2015-08-04 07:26:36 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2016-01-12 10:58:06 -07:00
|
|
|
* Decreases value by `step` but not below `min`.
|
|
|
|
* @method decrement
|
2015-08-04 07:26:36 -07:00
|
|
|
*/
|
2016-01-12 10:58:06 -07:00
|
|
|
decrement: function() {
|
|
|
|
this.value = this._clampValue(this.value - this.step);
|
2015-08-04 07:26:36 -07:00
|
|
|
},
|
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_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));
|
2015-08-04 07:26:36 -07:00
|
|
|
},
|
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_valueChanged: function() {
|
|
|
|
this.fire('value-change');
|
2015-08-04 07:26:36 -07:00
|
|
|
},
|
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_immediateValueChanged: function() {
|
|
|
|
if (this.dragging) {
|
|
|
|
this.fire('immediate-value-change');
|
|
|
|
} else {
|
|
|
|
this.value = this.immediateValue;
|
|
|
|
}
|
2015-08-04 07:26:36 -07:00
|
|
|
},
|
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_secondaryProgressChanged: function() {
|
|
|
|
this.secondaryProgress = this._clampValue(this.secondaryProgress);
|
2015-08-04 07:26:36 -07:00
|
|
|
},
|
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_expandKnob: function() {
|
|
|
|
this._setExpand(true);
|
2015-08-04 07:26:36 -07:00
|
|
|
},
|
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_resetKnob: function() {
|
|
|
|
this.cancelDebouncer('expandKnob');
|
|
|
|
this._setExpand(false);
|
2015-08-04 07:26:36 -07:00
|
|
|
},
|
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_positionKnob: function(ratio) {
|
|
|
|
this._setImmediateValue(this._calcStep(this._calcKnobPosition(ratio)));
|
|
|
|
this._setRatio(this._calcRatio(this.immediateValue));
|
|
|
|
|
|
|
|
this.$.sliderKnob.style.left = (this.ratio * 100) + '%';
|
|
|
|
if (this.dragging) {
|
|
|
|
this._knobstartx = this.ratio * this._w;
|
|
|
|
this.translate3d(0, 0, 0, this.$.sliderKnob);
|
|
|
|
}
|
2015-08-04 07:26:36 -07:00
|
|
|
},
|
2015-06-26 20:27:38 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_calcKnobPosition: function(ratio) {
|
|
|
|
return (this.max - this.min) * ratio + this.min;
|
|
|
|
},
|
2015-06-26 20:27:38 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_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;
|
|
|
|
}
|
|
|
|
},
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_trackStart: function(event) {
|
|
|
|
this._w = this.$.sliderBar.offsetWidth;
|
|
|
|
this._x = this.ratio * this._w;
|
|
|
|
this._startx = this._x;
|
|
|
|
this._knobstartx = this._startx;
|
|
|
|
this._minx = - this._startx;
|
|
|
|
this._maxx = this._w - this._startx;
|
|
|
|
this.$.sliderKnob.classList.add('dragging');
|
|
|
|
this._setDragging(true);
|
|
|
|
},
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_trackX: function(e) {
|
|
|
|
if (!this.dragging) {
|
|
|
|
this._trackStart(e);
|
|
|
|
}
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
var dx = Math.min(this._maxx, Math.max(this._minx, e.detail.dx));
|
|
|
|
this._x = this._startx + dx;
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
var immediateValue = this._calcStep(this._calcKnobPosition(this._x / this._w));
|
|
|
|
this._setImmediateValue(immediateValue);
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
// update knob's position
|
|
|
|
var translateX = ((this._calcRatio(this.immediateValue) * this._w) - this._knobstartx);
|
|
|
|
this.translate3d(translateX + 'px', 0, 0, this.$.sliderKnob);
|
|
|
|
},
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_trackEnd: function() {
|
|
|
|
var s = this.$.sliderKnob.style;
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
this.$.sliderKnob.classList.remove('dragging');
|
|
|
|
this._setDragging(false);
|
|
|
|
this._resetKnob();
|
|
|
|
this.value = this.immediateValue;
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
s.transform = s.webkitTransform = '';
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
this.fire('change');
|
|
|
|
},
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_knobdown: function(event) {
|
|
|
|
this._expandKnob();
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
// cancel selection
|
|
|
|
event.preventDefault();
|
2015-10-07 18:49:40 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
// set the focus manually because we will called prevent default
|
|
|
|
this.focus();
|
|
|
|
},
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_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;
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
this._setTransiting(true);
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
this._positionKnob(ratio);
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
this.debounce('expandKnob', this._expandKnob, 60);
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
// 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
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
if (prevRatio === this.ratio) {
|
|
|
|
this._setTransiting(false);
|
|
|
|
}
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
this.async(function() {
|
|
|
|
this.fire('change');
|
|
|
|
});
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
// cancel selection
|
|
|
|
event.preventDefault();
|
2016-03-21 19:06:21 -07:00
|
|
|
|
|
|
|
// set the focus manually because we will called prevent default
|
|
|
|
this.focus();
|
2016-01-12 10:58:06 -07:00
|
|
|
},
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_knobTransitionEnd: function(event) {
|
|
|
|
if (event.target === this.$.sliderKnob) {
|
|
|
|
this._setTransiting(false);
|
|
|
|
}
|
|
|
|
},
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_maxMarkersChanged: function(maxMarkers) {
|
|
|
|
if (!this.snaps) {
|
|
|
|
this._setMarkers([]);
|
|
|
|
}
|
2016-03-21 19:06:21 -07:00
|
|
|
var steps = Math.round((this.max - this.min) / this.step);
|
2016-01-12 10:58:06 -07:00
|
|
|
if (steps > maxMarkers) {
|
|
|
|
steps = maxMarkers;
|
|
|
|
}
|
|
|
|
this._setMarkers(new Array(steps));
|
|
|
|
},
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_mergeClasses: function(classes) {
|
|
|
|
return Object.keys(classes).filter(
|
|
|
|
function(className) {
|
|
|
|
return classes[className];
|
|
|
|
}).join(' ');
|
|
|
|
},
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_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
|
|
|
|
});
|
|
|
|
},
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_incrementKey: function(event) {
|
|
|
|
if (!this.disabled) {
|
|
|
|
if (event.detail.key === 'end') {
|
|
|
|
this.value = this.max;
|
|
|
|
} else {
|
|
|
|
this.increment();
|
|
|
|
}
|
|
|
|
this.fire('change');
|
2015-10-07 18:49:40 -07:00
|
|
|
}
|
2016-01-12 10:58:06 -07:00
|
|
|
},
|
2015-08-04 07:26:36 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_decrementKey: function(event) {
|
|
|
|
if (!this.disabled) {
|
|
|
|
if (event.detail.key === 'home') {
|
|
|
|
this.value = this.min;
|
|
|
|
} else {
|
|
|
|
this.decrement();
|
|
|
|
}
|
|
|
|
this.fire('change');
|
2015-10-07 18:49:40 -07:00
|
|
|
}
|
2016-01-12 10:58:06 -07:00
|
|
|
},
|
2015-10-07 18:49:40 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_changeValue: function(event) {
|
|
|
|
this.value = event.target.value;
|
|
|
|
this.fire('change');
|
|
|
|
},
|
2015-10-07 18:49:40 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
_inputKeyDown: function(event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
},
|
2015-10-07 18:49:40 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
// create the element ripple inside the `sliderKnob`
|
|
|
|
_createRipple: function() {
|
|
|
|
this._rippleContainer = this.$.sliderKnob;
|
|
|
|
return Polymer.PaperInkyFocusBehaviorImpl._createRipple.call(this);
|
|
|
|
},
|
2015-10-07 18:49:40 -07:00
|
|
|
|
2016-01-12 10:58:06 -07:00
|
|
|
// 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) {
|
2015-10-07 18:49:40 -07:00
|
|
|
if (receivedFocusFromKeyboard) {
|
2016-01-12 10:58:06 -07:00
|
|
|
this.ensureRipple();
|
2015-10-07 18:49:40 -07:00
|
|
|
}
|
2016-01-12 10:58:06 -07:00
|
|
|
if (this.hasRipple()) {
|
|
|
|
// note, ripple must be un-hidden prior to setting `holdDown`
|
|
|
|
if (receivedFocusFromKeyboard) {
|
2016-03-21 19:06:21 -07:00
|
|
|
this._ripple.style.display = '';
|
2016-01-12 10:58:06 -07:00
|
|
|
} else {
|
2016-03-21 19:06:21 -07:00
|
|
|
this._ripple.style.display = 'none';
|
2016-01-12 10:58:06 -07:00
|
|
|
}
|
|
|
|
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>
|
|
|
|
</dom-module>
|