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

Side by Side Diff: third_party/polymer/components-chromium/core-drawer-panel/core-drawer-panel-extracted.js

Issue 1215543002: Remove Polymer 0.5. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix unit test Created 5 years, 5 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
(Empty)
1
2
3 Polymer('core-drawer-panel', {
4
5 /**
6 * Fired when the narrow layout changes.
7 *
8 * @event core-responsive-change
9 * @param {Object} detail
10 * @param {boolean} detail.narrow true if the panel is in narrow layout.
11 */
12
13 /**
14 * Fired when the selected panel changes.
15 *
16 * Listening for this event is an alternative to observing changes in the `s elected` attribute.
17 * This event is fired both when a panel is selected and deselected.
18 * The `isSelected` detail property contains the selection state.
19 *
20 * @event core-select
21 * @param {Object} detail
22 * @param {boolean} detail.isSelected true for selection and false for desel ection
23 * @param {Object} detail.item the panel that the event refers to
24 */
25
26 publish: {
27
28 /**
29 * Width of the drawer panel.
30 *
31 * @attribute drawerWidth
32 * @type string
33 * @default '256px'
34 */
35 drawerWidth: '256px',
36
37 /**
38 * Max-width when the panel changes to narrow layout.
39 *
40 * @attribute responsiveWidth
41 * @type string
42 * @default '640px'
43 */
44 responsiveWidth: '640px',
45
46 /**
47 * The panel that is being selected. `drawer` for the drawer panel and
48 * `main` for the main panel.
49 *
50 * @attribute selected
51 * @type string
52 * @default null
53 */
54 selected: {value: null, reflect: true},
55
56 /**
57 * The panel to be selected when `core-drawer-panel` changes to narrow
58 * layout.
59 *
60 * @attribute defaultSelected
61 * @type string
62 * @default 'main'
63 */
64 defaultSelected: 'main',
65
66 /**
67 * Returns true if the panel is in narrow layout. This is useful if you
68 * need to show/hide elements based on the layout.
69 *
70 * @attribute narrow
71 * @type boolean
72 * @default false
73 */
74 narrow: {value: false, reflect: true},
75
76 /**
77 * If true, position the drawer to the right.
78 *
79 * @attribute rightDrawer
80 * @type boolean
81 * @default false
82 */
83 rightDrawer: false,
84
85 /**
86 * If true, swipe to open/close the drawer is disabled.
87 *
88 * @attribute disableSwipe
89 * @type boolean
90 * @default false
91 */
92 disableSwipe: false,
93
94 /**
95 * If true, ignore `responsiveWidth` setting and force the narrow layout.
96 *
97 * @attribute forceNarrow
98 * @type boolean
99 * @default false
100 */
101 forceNarrow: false
102 },
103
104 eventDelegates: {
105 trackstart: 'trackStart',
106 trackx: 'trackx',
107 trackend: 'trackEnd',
108 down: 'downHandler',
109 up: 'upHandler',
110 tap: 'tapHandler'
111 },
112
113 // Whether the transition is enabled.
114 transition: false,
115
116 // How many pixels on the side of the screen are sensitive to edge swipes an d peek.
117 edgeSwipeSensitivity: 15,
118
119 // Whether the drawer is peeking out from the edge.
120 peeking: false,
121
122 // Whether the user is dragging the drawer interactively.
123 dragging: false,
124
125 // Whether the browser has support for the transform CSS property.
126 hasTransform: true,
127
128 // Whether the browser has support for the will-change CSS property.
129 hasWillChange: true,
130
131 // The attribute on elements that should toggle the drawer on tap, also
132 // elements will automatically be hidden in wide layout.
133 toggleAttribute: 'core-drawer-toggle',
134
135 created: function() {
136 this.hasTransform = 'transform' in this.style;
137 this.hasWillChange = 'willChange' in this.style;
138 },
139
140 domReady: function() {
141 // to avoid transition at the beginning e.g. page loads
142 // NOTE: domReady is already raf delayed and delaying another frame
143 // ensures a layout has occurred.
144 this.async(function() {
145 this.transition = true;
146 });
147 },
148
149 /**
150 * Toggles the panel open and closed.
151 *
152 * @method togglePanel
153 */
154 togglePanel: function() {
155 this.selected = this.isMainSelected() ? 'drawer' : 'main';
156 },
157
158 /**
159 * Opens the drawer.
160 *
161 * @method openDrawer
162 */
163 openDrawer: function() {
164 this.selected = 'drawer';
165 },
166
167 /**
168 * Closes the drawer.
169 *
170 * @method closeDrawer
171 */
172 closeDrawer: function() {
173 this.selected = 'main';
174 },
175
176 queryMatchesChanged: function() {
177 this.narrow = this.queryMatches || this.forceNarrow;
178 if (this.narrow) {
179 this.selected = this.defaultSelected;
180 }
181 this.setAttribute('touch-action', this.swipeAllowed() ? 'pan-y' : '');
182 this.fire('core-responsive-change', {narrow: this.narrow});
183 },
184
185 forceNarrowChanged: function() {
186 this.queryMatchesChanged();
187 },
188
189 swipeAllowed: function() {
190 return this.narrow && !this.disableSwipe;
191 },
192
193 isMainSelected: function() {
194 return this.selected === 'main';
195 },
196
197 startEdgePeek: function() {
198 this.width = this.$.drawer.offsetWidth;
199 this.moveDrawer(this.translateXForDeltaX(this.rightDrawer ?
200 -this.edgeSwipeSensitivity : this.edgeSwipeSensitivity));
201 this.peeking = true;
202 },
203
204 stopEdgePeak: function() {
205 if (this.peeking) {
206 this.peeking = false;
207 this.moveDrawer(null);
208 }
209 },
210
211 downHandler: function(e) {
212 if (!this.dragging && this.isMainSelected() && this.isEdgeTouch(e)) {
213 this.startEdgePeek();
214 }
215 },
216
217 upHandler: function(e) {
218 this.stopEdgePeak();
219 },
220
221 tapHandler: function(e) {
222 if (e.target && this.toggleAttribute &&
223 e.target.hasAttribute(this.toggleAttribute)) {
224 this.togglePanel();
225 }
226 },
227
228 isEdgeTouch: function(e) {
229 return this.swipeAllowed() && (this.rightDrawer ?
230 e.pageX >= this.offsetWidth - this.edgeSwipeSensitivity :
231 e.pageX <= this.edgeSwipeSensitivity);
232 },
233
234 trackStart : function(e) {
235 if (this.swipeAllowed()) {
236 this.dragging = true;
237
238 if (this.isMainSelected()) {
239 this.dragging = this.peeking || this.isEdgeTouch(e);
240 }
241
242 if (this.dragging) {
243 this.width = this.$.drawer.offsetWidth;
244 this.transition = false;
245 e.preventTap();
246 }
247 }
248 },
249
250 translateXForDeltaX: function(deltaX) {
251 var isMain = this.isMainSelected();
252 if (this.rightDrawer) {
253 return Math.max(0, isMain ? this.width + deltaX : deltaX);
254 } else {
255 return Math.min(0, isMain ? deltaX - this.width : deltaX);
256 }
257 },
258
259 trackx : function(e) {
260 if (this.dragging) {
261 if (this.peeking) {
262 if (Math.abs(e.dx) <= this.edgeSwipeSensitivity) {
263 return; // Ignore trackx until we move past the edge peek.
264 }
265 this.peeking = false;
266 }
267 this.moveDrawer(this.translateXForDeltaX(e.dx));
268 }
269 },
270
271 trackEnd : function(e) {
272 if (this.dragging) {
273 this.dragging = false;
274 this.transition = true;
275 this.moveDrawer(null);
276
277 if (this.rightDrawer) {
278 this.selected = e.xDirection > 0 ? 'main' : 'drawer';
279 } else {
280 this.selected = e.xDirection > 0 ? 'drawer' : 'main';
281 }
282 }
283 },
284
285 transformForTranslateX: function(translateX) {
286 if (translateX === null) {
287 return '';
288 }
289 return this.hasWillChange ? 'translateX(' + translateX + 'px)' :
290 'translate3d(' + translateX + 'px, 0, 0)';
291 },
292
293 moveDrawer: function(translateX) {
294 var s = this.$.drawer.style;
295
296 if (this.hasTransform) {
297 s.transform = this.transformForTranslateX(translateX);
298 } else {
299 s.webkitTransform = this.transformForTranslateX(translateX);
300 }
301 }
302
303 });
304
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698