| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 <!-- |  | 
| 2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |  | 
| 3 This code may only be used under the BSD style license found at http://polymer.g
     ithub.io/LICENSE.txt |  | 
| 4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |  | 
| 5 The complete set of contributors may be found at http://polymer.github.io/CONTRI
     BUTORS.txt |  | 
| 6 Code distributed by Google as part of the polymer project is also |  | 
| 7 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
     TS.txt |  | 
| 8 --> |  | 
| 9 |  | 
| 10 <!-- |  | 
| 11 `paper-slider` allows user to select a value from a range of values by |  | 
| 12 moving the slider thumb.  The interactive nature of the slider makes it a |  | 
| 13 great choice for settings that reflect intensity levels, such as volume, |  | 
| 14 brightness, or color saturation. |  | 
| 15 |  | 
| 16 Example: |  | 
| 17 |  | 
| 18     <paper-slider></paper-slider> |  | 
| 19 |  | 
| 20 Use `min` and `max` to specify the slider range.  Default is 0 to 100. |  | 
| 21 |  | 
| 22 Example: |  | 
| 23 |  | 
| 24     <paper-slider min="10" max="200" value="110"></paper-slider> |  | 
| 25 |  | 
| 26 Styling slider: |  | 
| 27 |  | 
| 28 To change the slider progress bar color: |  | 
| 29 |  | 
| 30     paper-slider::shadow #sliderBar::shadow #activeProgress { |  | 
| 31       background-color: #0f9d58; |  | 
| 32     } |  | 
| 33 |  | 
| 34 To change the slider knob color: |  | 
| 35 |  | 
| 36     paper-slider::shadow #sliderKnobInner { |  | 
| 37       background-color: #0f9d58; |  | 
| 38     } |  | 
| 39 |  | 
| 40 To change the slider pin color: |  | 
| 41 |  | 
| 42     paper-slider::shadow #sliderKnobInner::before { |  | 
| 43       background-color: #0f9d58; |  | 
| 44     } |  | 
| 45 |  | 
| 46 To change the slider pin's value: |  | 
| 47 |  | 
| 48     paper-slider::shadow #sliderKnobInner::after { |  | 
| 49       color: #0f9d58 |  | 
| 50     } |  | 
| 51 |  | 
| 52 To change the slider secondary progress bar color: |  | 
| 53 |  | 
| 54     paper-slider::shadow #sliderBar::shadow #secondaryProgress { |  | 
| 55       background-color: #0f9d58; |  | 
| 56     } |  | 
| 57 |  | 
| 58 @group Paper Elements |  | 
| 59 @element paper-slider |  | 
| 60 @extends core-range |  | 
| 61 @homepage github.io |  | 
| 62 --> |  | 
| 63 |  | 
| 64 <link rel="import" href="../core-a11y-keys/core-a11y-keys.html"> |  | 
| 65 <link rel="import" href="../paper-progress/paper-progress.html"> |  | 
| 66 <link rel="import" href="../paper-input/paper-input.html"> |  | 
| 67 |  | 
| 68 <polymer-element name="paper-slider" extends="core-range" attributes="snaps pin 
     disabled secondaryProgress editable immediateValue" role="slider" tabindex="0" a
     ria-valuemin="0" aria-valuemax="100"> |  | 
| 69 <template> |  | 
| 70 |  | 
| 71   <link rel="stylesheet" href="paper-slider.css"> |  | 
| 72 |  | 
| 73   <template if="{{!disabled}}"> |  | 
| 74     <core-a11y-keys target="{{}}" keys="left down pagedown home" on-keys-pressed
     ="{{decrementKey}}"></core-a11y-keys> |  | 
| 75     <core-a11y-keys target="{{}}" keys="right up pageup end" on-keys-pressed="{{
     incrementKey}}"></core-a11y-keys> |  | 
| 76   </template> |  | 
| 77 |  | 
| 78   <div id="sliderContainer" class="{{ {disabled: disabled, pin: pin, snaps: snap
     s, ring: immediateValue <= min, expand: expand, dragging: dragging, transiting: 
     transiting, editable: editable} | tokenList }}"> |  | 
| 79 |  | 
| 80     <div class="bar-container"> |  | 
| 81       <paper-progress id="sliderBar" aria-hidden="true" min="{{min}}" max="{{max
     }}" value="{{immediateValue}}" secondaryProgress="{{secondaryProgress}}" |  | 
| 82           on-down="{{bardown}}" on-up="{{resetKnob}}" |  | 
| 83           on-trackstart="{{trackStart}}" on-trackx="{{trackx}}" on-trackend="{{t
     rackEnd}}"></paper-progress> |  | 
| 84     </div> |  | 
| 85 |  | 
| 86     <template if="{{snaps && !disabled}}"> |  | 
| 87       <div class="slider-markers" horizontal layout> |  | 
| 88         <template repeat="{{markers}}"> |  | 
| 89           <div flex class="slider-marker"></div> |  | 
| 90         </template> |  | 
| 91       </div> |  | 
| 92     </template> |  | 
| 93 |  | 
| 94     <div id="sliderKnob" on-down="{{expandKnob}}" on-up="{{resetKnob}}" |  | 
| 95         on-trackstart="{{trackStart}}" on-trackx="{{trackx}}" on-trackend="{{tra
     ckEnd}}" |  | 
| 96         on-transitionend="{{knobTransitionEnd}}" |  | 
| 97         center-justified center horizontal layout> |  | 
| 98 |  | 
| 99       <div id="sliderKnobInner" value="{{immediateValue}}"></div> |  | 
| 100 |  | 
| 101     </div> |  | 
| 102 |  | 
| 103   </div> |  | 
| 104 |  | 
| 105   <template if="{{editable}}"> |  | 
| 106     <paper-input id="input" class="slider-input" value="{{immediateValue}}" disa
     bled?="{{disabled}}" on-change="{{inputChange}}"></paper-input> |  | 
| 107   </template> |  | 
| 108 |  | 
| 109 </template> |  | 
| 110 <script> |  | 
| 111 |  | 
| 112   Polymer('paper-slider', { |  | 
| 113 |  | 
| 114     /** |  | 
| 115      * Fired when the slider's value changes. |  | 
| 116      * |  | 
| 117      * @event core-change |  | 
| 118      */ |  | 
| 119 |  | 
| 120     /** |  | 
| 121      * Fired when the slider's value changes due to user interaction. |  | 
| 122      * |  | 
| 123      * Changes to the slider's value due to changes in an underlying |  | 
| 124      * bound variable will not trigger this event. |  | 
| 125      * |  | 
| 126      * @event change |  | 
| 127      */ |  | 
| 128 |  | 
| 129     /** |  | 
| 130      * If true, the slider thumb snaps to tick marks evenly spaced based |  | 
| 131      * on the `step` property value. |  | 
| 132      * |  | 
| 133      * @attribute snaps |  | 
| 134      * @type boolean |  | 
| 135      * @default false |  | 
| 136      */ |  | 
| 137     snaps: false, |  | 
| 138 |  | 
| 139     /** |  | 
| 140      * If true, a pin with numeric value label is shown when the slider thumb |  | 
| 141      * is pressed.  Use for settings for which users need to know the exact |  | 
| 142      * value of the setting. |  | 
| 143      * |  | 
| 144      * @attribute pin |  | 
| 145      * @type boolean |  | 
| 146      * @default false |  | 
| 147      */ |  | 
| 148     pin: false, |  | 
| 149 |  | 
| 150     /** |  | 
| 151      * If true, this slider is disabled.  A disabled slider cannot be tapped |  | 
| 152      * or dragged to change the slider value. |  | 
| 153      * |  | 
| 154      * @attribute disabled |  | 
| 155      * @type boolean |  | 
| 156      * @default false |  | 
| 157      */ |  | 
| 158     disabled: false, |  | 
| 159 |  | 
| 160     /** |  | 
| 161      * The number that represents the current secondary progress. |  | 
| 162      * |  | 
| 163      * @attribute secondaryProgress |  | 
| 164      * @type number |  | 
| 165      * @default 0 |  | 
| 166      */ |  | 
| 167     secondaryProgress: 0, |  | 
| 168 |  | 
| 169     /** |  | 
| 170      * If true, an input is shown and user can use it to set the slider value. |  | 
| 171      * |  | 
| 172      * @attribute editable |  | 
| 173      * @type boolean |  | 
| 174      * @default false |  | 
| 175      */ |  | 
| 176     editable: false, |  | 
| 177 |  | 
| 178     /** |  | 
| 179      * The immediate value of the slider.  This value is updated while the user |  | 
| 180      * is dragging the slider. |  | 
| 181      * |  | 
| 182      * @attribute immediateValue |  | 
| 183      * @type number |  | 
| 184      * @default 0 |  | 
| 185      */ |  | 
| 186 |  | 
| 187     observe: { |  | 
| 188       'step snaps': 'update' |  | 
| 189     }, |  | 
| 190 |  | 
| 191     ready: function() { |  | 
| 192       this.update(); |  | 
| 193     }, |  | 
| 194 |  | 
| 195     update: function() { |  | 
| 196       this.positionKnob(this.calcRatio(this.value)); |  | 
| 197       this.updateMarkers(); |  | 
| 198     }, |  | 
| 199 |  | 
| 200     minChanged: function() { |  | 
| 201       this.update(); |  | 
| 202       this.setAttribute('aria-valuemin', this.min); |  | 
| 203     }, |  | 
| 204 |  | 
| 205     maxChanged: function() { |  | 
| 206       this.update(); |  | 
| 207       this.setAttribute('aria-valuemax', this.max); |  | 
| 208     }, |  | 
| 209 |  | 
| 210     valueChanged: function() { |  | 
| 211       this.update(); |  | 
| 212       this.setAttribute('aria-valuenow', this.value); |  | 
| 213       this.fire('core-change'); |  | 
| 214     }, |  | 
| 215 |  | 
| 216     disabledChanged: function() { |  | 
| 217       if (this.disabled) { |  | 
| 218         this.removeAttribute('tabindex'); |  | 
| 219       } else { |  | 
| 220         this.tabIndex = 0; |  | 
| 221       } |  | 
| 222     }, |  | 
| 223 |  | 
| 224     immediateValueChanged: function() { |  | 
| 225       if (!this.dragging) { |  | 
| 226         this.value = this.immediateValue; |  | 
| 227       } |  | 
| 228     }, |  | 
| 229 |  | 
| 230     expandKnob: function() { |  | 
| 231       this.expand = true; |  | 
| 232     }, |  | 
| 233 |  | 
| 234     resetKnob: function() { |  | 
| 235       this.expandJob && this.expandJob.stop(); |  | 
| 236       this.expand = false; |  | 
| 237     }, |  | 
| 238 |  | 
| 239     positionKnob: function(ratio) { |  | 
| 240       this.immediateValue = this.calcStep(this.calcKnobPosition(ratio)) || 0; |  | 
| 241       this._ratio = this.snaps ? this.calcRatio(this.immediateValue) : ratio; |  | 
| 242       this.$.sliderKnob.style.left = this._ratio * 100 + '%'; |  | 
| 243     }, |  | 
| 244 |  | 
| 245     inputChange: function() { |  | 
| 246       this.value = this.$.input.value; |  | 
| 247       this.fire('change'); |  | 
| 248     }, |  | 
| 249 |  | 
| 250     calcKnobPosition: function(ratio) { |  | 
| 251       return (this.max - this.min) * ratio + this.min; |  | 
| 252     }, |  | 
| 253 |  | 
| 254     trackStart: function(e) { |  | 
| 255       this._w = this.$.sliderBar.offsetWidth; |  | 
| 256       this._x = this._ratio * this._w; |  | 
| 257       this._startx = this._x || 0; |  | 
| 258       this._minx = - this._startx; |  | 
| 259       this._maxx = this._w - this._startx; |  | 
| 260       this.$.sliderKnob.classList.add('dragging'); |  | 
| 261       this.dragging = true; |  | 
| 262       e.preventTap(); |  | 
| 263     }, |  | 
| 264 |  | 
| 265     trackx: function(e) { |  | 
| 266       var x = Math.min(this._maxx, Math.max(this._minx, e.dx)); |  | 
| 267       this._x = this._startx + x; |  | 
| 268       this.immediateValue = this.calcStep( |  | 
| 269           this.calcKnobPosition(this._x / this._w)) || 0; |  | 
| 270       var s =  this.$.sliderKnob.style; |  | 
| 271       s.transform = s.webkitTransform = 'translate3d(' + (this.snaps ? |  | 
| 272           (this.calcRatio(this.immediateValue) * this._w) - this._startx : x) + 
     'px, 0, 0)'; |  | 
| 273     }, |  | 
| 274 |  | 
| 275     trackEnd: function() { |  | 
| 276       var s =  this.$.sliderKnob.style; |  | 
| 277       s.transform = s.webkitTransform = ''; |  | 
| 278       this.$.sliderKnob.classList.remove('dragging'); |  | 
| 279       this.dragging = false; |  | 
| 280       this.resetKnob(); |  | 
| 281       this.value = this.immediateValue; |  | 
| 282       this.fire('change'); |  | 
| 283     }, |  | 
| 284 |  | 
| 285     bardown: function(e) { |  | 
| 286       this.transiting = true; |  | 
| 287       this._w = this.$.sliderBar.offsetWidth; |  | 
| 288       var rect = this.$.sliderBar.getBoundingClientRect(); |  | 
| 289       var ratio = (e.x - rect.left) / this._w; |  | 
| 290       this.positionKnob(ratio); |  | 
| 291       this.expandJob = this.job(this.expandJob, this.expandKnob, 60); |  | 
| 292       this.fire('change'); |  | 
| 293     }, |  | 
| 294 |  | 
| 295     knobTransitionEnd: function(e) { |  | 
| 296       if (e.target === this.$.sliderKnob) { |  | 
| 297         this.transiting = false; |  | 
| 298       } |  | 
| 299     }, |  | 
| 300 |  | 
| 301     updateMarkers: function() { |  | 
| 302       this.markers = [], l = (this.max - this.min) / this.step; |  | 
| 303       for (var i = 0; i < l; i++) { |  | 
| 304         this.markers.push(''); |  | 
| 305       } |  | 
| 306     }, |  | 
| 307 |  | 
| 308     increment: function() { |  | 
| 309       this.value = this.clampValue(this.value + this.step); |  | 
| 310     }, |  | 
| 311 |  | 
| 312     decrement: function() { |  | 
| 313       this.value = this.clampValue(this.value - this.step); |  | 
| 314     }, |  | 
| 315 |  | 
| 316     incrementKey: function(ev, keys) { |  | 
| 317       if (keys.key === "end") { |  | 
| 318         this.value = this.max; |  | 
| 319       } else { |  | 
| 320         this.increment(); |  | 
| 321       } |  | 
| 322       this.fire('change'); |  | 
| 323     }, |  | 
| 324 |  | 
| 325     decrementKey: function(ev, keys) { |  | 
| 326       if (keys.key === "home") { |  | 
| 327         this.value = this.min; |  | 
| 328       } else { |  | 
| 329         this.decrement(); |  | 
| 330       } |  | 
| 331       this.fire('change'); |  | 
| 332     } |  | 
| 333 |  | 
| 334   }); |  | 
| 335 |  | 
| 336 </script> |  | 
| 337 </polymer-element> |  | 
| OLD | NEW | 
|---|