| 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-toggle-button` provides a ON/OFF switch that user can toggle the state |  | 
| 12 by tapping or by dragging the swtich. |  | 
| 13 |  | 
| 14 Example: |  | 
| 15 |  | 
| 16     <paper-toggle-button></paper-toggle-button> |  | 
| 17 |  | 
| 18 Styling toggle button: |  | 
| 19 |  | 
| 20 To change the ink color for checked state: |  | 
| 21 |  | 
| 22     paper-toggle-button::shadow paper-radio-button::shadow #ink[checked] { |  | 
| 23       color: #4285f4; |  | 
| 24     } |  | 
| 25 |  | 
| 26 To change the radio checked color: |  | 
| 27 |  | 
| 28     paper-toggle-button::shadow paper-radio-button::shadow #onRadio { |  | 
| 29       background-color: #4285f4; |  | 
| 30     } |  | 
| 31 |  | 
| 32 To change the bar color for checked state: |  | 
| 33 |  | 
| 34     paper-toggle-button::shadow #toggleBar[checked] { |  | 
| 35       background-color: #4285f4; |  | 
| 36     } |  | 
| 37 |  | 
| 38 To change the ink color for unchecked state: |  | 
| 39 |  | 
| 40     paper-toggle-button::shadow paper-radio-button::shadow #ink { |  | 
| 41       color: #b5b5b5; |  | 
| 42     } |  | 
| 43 |  | 
| 44 To change the radio unchecked color: |  | 
| 45 |  | 
| 46     paper-toggle-button::shadow paper-radio-button::shadow #offRadio { |  | 
| 47       border-color: #b5b5b5; |  | 
| 48     } |  | 
| 49 |  | 
| 50 To change the bar color for unchecked state: |  | 
| 51 |  | 
| 52     paper-toggle-button::shadow #toggleBar { |  | 
| 53       background-color: red; |  | 
| 54     } |  | 
| 55 |  | 
| 56 @group Paper Elements |  | 
| 57 @element paper-toggle-button |  | 
| 58 @homepage github.io |  | 
| 59 --> |  | 
| 60 |  | 
| 61 <link rel="import" href="../paper-radio-button/paper-radio-button.html"> |  | 
| 62 |  | 
| 63 <polymer-element name="paper-toggle-button" attributes="checked" role="button" a
     ria-pressed="false" tabindex="0"> |  | 
| 64 <template> |  | 
| 65 |  | 
| 66   <link rel="stylesheet" href="paper-toggle-button.css"> |  | 
| 67 |  | 
| 68   <div id="toggleContainer"> |  | 
| 69 |  | 
| 70     <div id="toggleBar" checked?="{{checked}}"></div> |  | 
| 71 |  | 
| 72     <paper-radio-button id="toggleRadio" toggles checked="{{checked}}" on-change
     ="{{changeAction}}" on-core-change="{{stopPropagation}}" |  | 
| 73         on-trackstart="{{trackStart}}" on-trackx="{{trackx}}" on-trackend="{{tra
     ckEnd}}"></paper-radio-button> |  | 
| 74 |  | 
| 75   </div> |  | 
| 76 |  | 
| 77 </template> |  | 
| 78 <script> |  | 
| 79 |  | 
| 80   Polymer('paper-toggle-button', { |  | 
| 81 |  | 
| 82     /** |  | 
| 83      * Fired when the checked state changes due to user interaction. |  | 
| 84      * |  | 
| 85      * @event change |  | 
| 86      */ |  | 
| 87 |  | 
| 88     /** |  | 
| 89      * Fired when the checked state changes. |  | 
| 90      * |  | 
| 91      * @event core-change |  | 
| 92      */ |  | 
| 93 |  | 
| 94     /** |  | 
| 95      * Gets or sets the state, `true` is checked and `false` is unchecked. |  | 
| 96      * |  | 
| 97      * @attribute checked |  | 
| 98      * @type boolean |  | 
| 99      * @default false |  | 
| 100      */ |  | 
| 101     checked: false, |  | 
| 102 |  | 
| 103     trackStart: function(e) { |  | 
| 104       this._w = this.$.toggleBar.offsetLeft + this.$.toggleBar.offsetWidth; |  | 
| 105       e.preventTap(); |  | 
| 106     }, |  | 
| 107 |  | 
| 108     trackx: function(e) { |  | 
| 109       this._x = Math.min(this._w, |  | 
| 110           Math.max(0, this.checked ? this._w + e.dx : e.dx)); |  | 
| 111       this.$.toggleRadio.classList.add('dragging'); |  | 
| 112       var s =  this.$.toggleRadio.style; |  | 
| 113       s.webkitTransform = s.transform = 'translate3d(' + this._x + 'px,0,0)'; |  | 
| 114     }, |  | 
| 115 |  | 
| 116     trackEnd: function() { |  | 
| 117       var s =  this.$.toggleRadio.style; |  | 
| 118       s.transform = s.webkitTransform = ''; |  | 
| 119       this.$.toggleRadio.classList.remove('dragging'); |  | 
| 120       var old = this.checked; |  | 
| 121       this.checked = Math.abs(this._x) > this._w / 2; |  | 
| 122       if (this.checked !== old) { |  | 
| 123         this.fire('change'); |  | 
| 124       } |  | 
| 125     }, |  | 
| 126 |  | 
| 127     checkedChanged: function() { |  | 
| 128       this.setAttribute('aria-pressed', Boolean(this.checked)); |  | 
| 129       this.fire('core-change'); |  | 
| 130     }, |  | 
| 131 |  | 
| 132     changeAction: function(e) { |  | 
| 133       e.stopPropagation(); |  | 
| 134       this.fire('change'); |  | 
| 135     }, |  | 
| 136 |  | 
| 137     stopPropagation: function(e) { |  | 
| 138       e.stopPropagation(); |  | 
| 139     } |  | 
| 140 |  | 
| 141   }); |  | 
| 142 |  | 
| 143 </script> |  | 
| 144 </polymer-element> |  | 
| OLD | NEW | 
|---|