Delete chrome.mediaGalleriesPrivate because the functionality unique to it has since...
[chromium-blink-merge.git] / third_party / polymer / components / paper-toggle-button / paper-toggle-button.html
blobd224bd0230bd45c26408c2029c6be959518504f6
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.github.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/CONTRIBUTORS.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/PATENTS.txt
8 -->
10 <!--
11 `paper-toggle-button` provides a ON/OFF switch that user can toggle the state
12 by tapping or by dragging the swtich.
14 Example:
16 <paper-toggle-button></paper-toggle-button>
18 Styling toggle button:
20 To change the ink color for checked state:
22 paper-toggle-button::shadow paper-radio-button::shadow #ink[checked] {
23 color: #4285f4;
26 To change the radio checked color:
28 paper-toggle-button::shadow paper-radio-button::shadow #onRadio {
29 background-color: #4285f4;
32 To change the bar color for checked state:
34 paper-toggle-button::shadow #toggleBar[checked] {
35 background-color: #4285f4;
38 To change the ink color for unchecked state:
40 paper-toggle-button::shadow paper-radio-button::shadow #ink {
41 color: #b5b5b5;
44 To change the radio unchecked color:
46 paper-toggle-button::shadow paper-radio-button::shadow #offRadio {
47 border-color: #b5b5b5;
50 To change the bar color for unchecked state:
52 paper-toggle-button::shadow #toggleBar {
53 background-color: red;
56 @group Paper Elements
57 @element paper-toggle-button
58 @homepage github.io
59 -->
61 <link rel="import" href="../paper-radio-button/paper-radio-button.html">
63 <polymer-element name="paper-toggle-button" attributes="checked disabled" role="button" aria-pressed="false" tabindex="0">
64 <template>
66 <link rel="stylesheet" href="paper-toggle-button.css">
68 <div id="toggleContainer" disabled?="{{disabled}}">
70 <div id="toggleBar" checked?="{{checked}}"></div>
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="{{trackEnd}}"></paper-radio-button>
75 </div>
77 </template>
78 <script>
80 Polymer('paper-toggle-button', {
82 /**
83 * Fired when the checked state changes due to user interaction.
85 * @event change
88 /**
89 * Fired when the checked state changes.
91 * @event core-change
94 /**
95 * Gets or sets the state, `true` is checked and `false` is unchecked.
97 * @attribute checked
98 * @type boolean
99 * @default false
101 checked: false,
104 * If true, the toggle button is disabled. A disabled toggle button cannot
105 * be tapped or dragged to change the checked state.
107 * @attribute disabled
108 * @type boolean
109 * @default false
111 disabled: false,
113 trackStart: function(e) {
114 this._w = this.$.toggleBar.offsetLeft + this.$.toggleBar.offsetWidth;
115 e.preventTap();
118 trackx: function(e) {
119 this._x = Math.min(this._w,
120 Math.max(0, this.checked ? this._w + e.dx : e.dx));
121 this.$.toggleRadio.classList.add('dragging');
122 var s = this.$.toggleRadio.style;
123 s.webkitTransform = s.transform = 'translate3d(' + this._x + 'px,0,0)';
126 trackEnd: function() {
127 var s = this.$.toggleRadio.style;
128 s.transform = s.webkitTransform = '';
129 this.$.toggleRadio.classList.remove('dragging');
130 var old = this.checked;
131 this.checked = Math.abs(this._x) > this._w / 2;
132 if (this.checked !== old) {
133 this.fire('change');
137 checkedChanged: function() {
138 this.setAttribute('aria-pressed', Boolean(this.checked));
139 this.fire('core-change');
142 changeAction: function(e) {
143 e.stopPropagation();
144 this.fire('change');
147 stopPropagation: function(e) {
148 e.stopPropagation();
153 </script>
154 </polymer-element>