Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(802)

Side by Side Diff: polymer_0.5.4/bower_components/paper-button/paper-button-base.html

Issue 895523005: Added Polymer 0.5.4 (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!-- 1 <!--
2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved. 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 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 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 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 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 7 subject to an additional IP rights grant found at http://polymer.github.io/PATEN TS.txt
8 --> 8 -->
9 9
10 <!-- 10 <!--
11 @group Paper Elements 11 @group Paper Elements
12 12
13 `paper-button-base` is the base class for button-like elements with ripple and o ptional shadow. 13 `paper-button-base` is the base class for button-like elements with ripple and o ptional shadow.
14 14
15 @element paper-button-base 15 @element paper-button-base
16 @mixins Polymer.CoreFocusable 16 @mixins Polymer.CoreFocusable https://github.com/polymer/core-focusable
17 @status unstable 17 @status unstable
18 --> 18 -->
19 19
20 <link href="../polymer/polymer.html" rel="import"> 20 <link href="../polymer/polymer.html" rel="import">
21 <link href="../core-focusable/core-focusable.html" rel="import"> 21 <link href="../core-focusable/core-focusable.html" rel="import">
22 <link href="../paper-ripple/paper-ripple.html" rel="import"> 22 <link href="../paper-ripple/paper-ripple.html" rel="import">
23 23
24 <polymer-element name="paper-button-base" tabindex="0"> 24 <polymer-element name="paper-button-base" tabindex="0">
25 25
26 <script> 26 <script>
27 27
28 (function() { 28 (function() {
29 29
30 var p = { 30 var p = {
31 31
32 eventDelegates: { 32 eventDelegates: {
33 down: 'downAction' 33 down: 'downAction',
34 up: 'upAction'
35 },
36
37 toggleBackground: function() {
38 if (this.active) {
39
40 if (!this.$.bg) {
41 var bg = document.createElement('div');
42 bg.setAttribute('id', 'bg');
43 bg.setAttribute('fit', '');
44 bg.style.opacity = 0.25;
45 this.$.bg = bg;
46 this.shadowRoot.insertBefore(bg, this.shadowRoot.firstChild);
47 }
48 this.$.bg.style.backgroundColor = getComputedStyle(this).color;
49
50 } else {
51
52 if (this.$.bg) {
53 this.$.bg.style.backgroundColor = '';
54 }
55 }
34 }, 56 },
35 57
36 activeChanged: function() { 58 activeChanged: function() {
37 this.super(); 59 this.super();
38 60
39 if (this.$.ripple) { 61 if (this.toggle && (!this.lastEvent || this.matches(':host-context([noin k])'))) {
40 if (this.active) { 62 this.toggleBackground();
41 // FIXME: remove when paper-ripple can have a default 'down' state. 63 }
42 if (!this.lastEvent) { 64 },
43 var rect = this.getBoundingClientRect(); 65
44 this.lastEvent = { 66 pressedChanged: function() {
45 x: rect.left + rect.width / 2, 67 this.super();
46 y: rect.top + rect.height / 2 68
47 } 69 if (!this.lastEvent) {
48 } 70 return;
71 }
72
73 if (this.$.ripple && !this.hasAttribute('noink')) {
74 if (this.pressed) {
49 this.$.ripple.downAction(this.lastEvent); 75 this.$.ripple.downAction(this.lastEvent);
50 } else { 76 } else {
51 this.$.ripple.upAction(); 77 this.$.ripple.upAction();
52 } 78 }
53 } 79 }
54 80
55 this.adjustZ(); 81 this.adjustZ();
56 }, 82 },
57 83
84 focusedChanged: function() {
85 this.adjustZ();
86 },
87
58 disabledChanged: function() { 88 disabledChanged: function() {
59 this._disabledChanged(); 89 this._disabledChanged();
60 this.adjustZ(); 90 this.adjustZ();
61 }, 91 },
62 92
63 recenteringTouchChanged: function() { 93 recenteringTouchChanged: function() {
64 if (this.$.ripple) { 94 if (this.$.ripple) {
65 this.$.ripple.classList.toggle('recenteringTouch', this.recenteringTou ch); 95 this.$.ripple.classList.toggle('recenteringTouch', this.recenteringTou ch);
66 } 96 }
67 }, 97 },
68 98
69 fillChanged: function() { 99 fillChanged: function() {
70 if (this.$.ripple) { 100 if (this.$.ripple) {
71 this.$.ripple.classList.toggle('fill', this.fill); 101 this.$.ripple.classList.toggle('fill', this.fill);
72 } 102 }
73 }, 103 },
74 104
75 adjustZ: function() { 105 adjustZ: function() {
76 if (!this.$.shadow) { 106 if (!this.$.shadow) {
77 return; 107 return;
78 } 108 }
79 if (this.active) { 109 if (this.active) {
80 this.$.shadow.setZ(2); 110 this.$.shadow.setZ(2);
81 } else if (this.disabled) { 111 } else if (this.disabled) {
82 this.$.shadow.setZ(0); 112 this.$.shadow.setZ(0);
113 } else if (this.focused) {
114 this.$.shadow.setZ(3);
83 } else { 115 } else {
84 this.$.shadow.setZ(1); 116 this.$.shadow.setZ(1);
85 } 117 }
86 }, 118 },
87 119
88 downAction: function(e) { 120 downAction: function(e) {
89 this._downAction(); 121 this._downAction();
90 122
91 if (this.hasAttribute('noink')) { 123 if (this.hasAttribute('noink')) {
92 return; 124 return;
93 } 125 }
94 126
95 this.lastEvent = e; 127 this.lastEvent = e;
96 if (!this.$.ripple) { 128 if (!this.$.ripple) {
97 var ripple = document.createElement('paper-ripple'); 129 var ripple = document.createElement('paper-ripple');
98 ripple.setAttribute('id', 'ripple'); 130 ripple.setAttribute('id', 'ripple');
99 ripple.setAttribute('fit', ''); 131 ripple.setAttribute('fit', '');
100 if (this.recenteringTouch) { 132 if (this.recenteringTouch) {
101 ripple.classList.add('recenteringTouch'); 133 ripple.classList.add('recenteringTouch');
102 } 134 }
103 if (!this.fill) { 135 if (!this.fill) {
104 ripple.classList.add('circle'); 136 ripple.classList.add('circle');
105 } 137 }
106 this.$.ripple = ripple; 138 this.$.ripple = ripple;
107 this.shadowRoot.insertBefore(ripple, this.shadowRoot.firstChild); 139 this.shadowRoot.insertBefore(ripple, this.shadowRoot.firstChild);
108 // No need to forward the event to the ripple because the ripple 140 // No need to forward the event to the ripple because the ripple
109 // is triggered in activeChanged 141 // is triggered in activeChanged
110 } 142 }
143 },
144
145 upAction: function() {
146 this._upAction();
147
148 if (this.toggle) {
149 this.toggleBackground();
150 if (this.$.ripple) {
151 this.$.ripple.cancel();
152 }
153 }
111 } 154 }
112 155
113 }; 156 };
114 157
115 Polymer.mixin2(p, Polymer.CoreFocusable); 158 Polymer.mixin2(p, Polymer.CoreFocusable);
116 Polymer(p); 159 Polymer(p);
117 160
118 })(); 161 })();
119 162
120 </script> 163 </script>
121 </polymer-element> 164 </polymer-element>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698