This repository has been archived by the owner on Jun 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 254
/
layout-patch.diff
279 lines (250 loc) · 8.98 KB
/
layout-patch.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
From 6bee05490698ddb98cbc46e92c6eedd9f368208f Mon Sep 17 00:00:00 2001
From: Tommy Leunen <[email protected]>
Date: Sun, 11 Sep 2016 20:28:07 -0400
Subject: [PATCH] react mdl 1.2.1
---
src/layout/_layout.scss | 34 +++++++++++++++++-----------------
src/layout/layout.js | 36 ++++++++++++------------------------
src/mdlComponentHandler.js | 3 ++-
src/tabs/tabs.js | 4 ----
4 files changed, 31 insertions(+), 46 deletions(-)
diff --git a/src/layout/_layout.scss b/src/layout/_layout.scss
index 05a317a..440eed8 100644
--- a/src/layout/_layout.scss
+++ b/src/layout/_layout.scss
@@ -39,14 +39,9 @@
// Main layout class.
.mdl-layout {
+ position: absolute;
width: 100%;
height: 100%;
- display: flex;
- flex-direction: column;
- overflow-y: auto;
- overflow-x: hidden;
- position: relative;
- -webkit-overflow-scrolling: touch;
}
// Utility classes for screen sizes.
@@ -58,10 +53,15 @@
display: none;
}
-.mdl-layout__container {
- position: absolute;
+.mdl-layout__inner-container {
width: 100%;
height: 100%;
+ display: flex;
+ flex-direction: column;
+ overflow-y: auto;
+ overflow-x: hidden;
+ position: relative;
+ -webkit-overflow-scrolling: touch;
}
@@ -166,7 +166,7 @@
}
@media screen and (min-width: $layout-screen-size-threshold + 1px) {
- .mdl-layout--fixed-drawer > & {
+ .mdl-layout--fixed-drawer > .mdl-layout__inner-container > & {
transform: translateX(0);
}
}
@@ -217,7 +217,7 @@
line-height: 54px;
.mdl-layout--no-desktop-drawer-button &,
- .mdl-layout--fixed-drawer > &,
+ .mdl-layout--fixed-drawer > .mdl-layout__inner-container > &,
.mdl-layout--no-drawer-button & {
display: none;
}
@@ -251,13 +251,13 @@
min-height: $layout-mobile-header-height;
}
- .mdl-layout--fixed-drawer.is-upgraded:not(.is-small-screen) > & {
+ .mdl-layout--fixed-drawer.is-upgraded:not(.is-small-screen) > .mdl-layout__inner-container > & {
margin-left: $layout-drawer-width;
width: calc(100% - #{$layout-drawer-width});
}
@media screen and (min-width: $layout-screen-size-threshold + 1px) {
- .mdl-layout--fixed-drawer > & {
+ .mdl-layout--fixed-drawer > .mdl-layout__inner-container > & {
.mdl-layout__header-row {
padding-left: 40px;
}
@@ -305,7 +305,7 @@
display: none;
}
- .mdl-layout--fixed-header > & {
+ .mdl-layout--fixed-header > .mdl-layout__inner-container > & {
display: flex;
}
}
@@ -446,20 +446,20 @@
z-index: 1;
-webkit-overflow-scrolling: touch;
- .mdl-layout--fixed-drawer > & {
+ .mdl-layout--fixed-drawer > .mdl-layout__inner-container > & {
margin-left: $layout-drawer-width;
}
- .mdl-layout__container.has-scrolling-header & {
+ .mdl-layout.has-scrolling-header & {
overflow: visible;
}
@media screen and (max-width: $layout-screen-size-threshold) {
- .mdl-layout--fixed-drawer > & {
+ .mdl-layout--fixed-drawer > .mdl-layout__inner-container > & {
margin-left: 0;
}
- .mdl-layout__container.has-scrolling-header & {
+ .mdl-layout.has-scrolling-header & {
overflow-y: auto;
overflow-x: hidden;
}
diff --git a/src/layout/layout.js b/src/layout/layout.js
index 9e1e4e6..54955a1 100644
--- a/src/layout/layout.js
+++ b/src/layout/layout.js
@@ -28,6 +28,7 @@
*/
var MaterialLayout = function MaterialLayout(element) {
this.element_ = element;
+ this.innerContainer_ = element.querySelector('.' + this.CssClasses_.INNER_CONTAINER);
// Initialize instance.
this.init();
@@ -84,7 +85,7 @@
* @private
*/
MaterialLayout.prototype.CssClasses_ = {
- CONTAINER: 'mdl-layout__container',
+ INNER_CONTAINER: 'mdl-layout__inner-container',
HEADER: 'mdl-layout__header',
DRAWER: 'mdl-layout__drawer',
CONTENT: 'mdl-layout__content',
@@ -260,7 +261,7 @@
* @public
*/
MaterialLayout.prototype.toggleDrawer = function() {
- var drawerButton = this.element_.querySelector('.' + this.CssClasses_.DRAWER_BTN);
+ var drawerButton = this.innerContainer_.querySelector('.' + this.CssClasses_.DRAWER_BTN);
this.drawer_.classList.toggle(this.CssClasses_.IS_DRAWER_OPEN);
this.obfuscator_.classList.toggle(this.CssClasses_.IS_DRAWER_OPEN);
@@ -281,20 +282,13 @@
*/
MaterialLayout.prototype.init = function() {
if (this.element_) {
- var container = document.createElement('div');
- container.classList.add(this.CssClasses_.CONTAINER);
-
var focusedElement = this.element_.querySelector(':focus');
- this.element_.parentElement.insertBefore(container, this.element_);
- this.element_.parentElement.removeChild(this.element_);
- container.appendChild(this.element_);
-
if (focusedElement) {
focusedElement.focus();
}
- var directChildren = this.element_.childNodes;
+ var directChildren = this.innerContainer_.childNodes;
var numChildren = directChildren.length;
for (var c = 0; c < numChildren; c++) {
var child = directChildren[c];
@@ -317,9 +311,9 @@
window.addEventListener('pageshow', function(e) {
if (e.persisted) { // when page is loaded from back/forward cache
// trigger repaint to let layout scroll in safari
- this.element_.style.overflowY = 'hidden';
+ this.innerContainer_.style.overflowY = 'hidden';
requestAnimationFrame(function() {
- this.element_.style.overflowY = '';
+ this.innerContainer_.style.overflowY = '';
}.bind(this));
}
}.bind(this), false);
@@ -343,7 +337,7 @@
} else if (this.header_.classList.contains(
this.CssClasses_.HEADER_SCROLL)) {
mode = this.Mode_.SCROLL;
- container.classList.add(this.CssClasses_.HAS_SCROLLING_HEADER);
+ this.element_.classList.add(this.CssClasses_.HAS_SCROLLING_HEADER);
}
if (mode === this.Mode_.STANDARD) {
@@ -368,7 +362,7 @@
// Add drawer toggling button to our layout, if we have an openable drawer.
if (this.drawer_) {
- var drawerButton = this.element_.querySelector('.' +
+ var drawerButton = this.innerContainer_.querySelector('.' +
this.CssClasses_.DRAWER_BTN);
if (!drawerButton) {
drawerButton = document.createElement('div');
@@ -407,12 +401,12 @@
if (this.element_.classList.contains(this.CssClasses_.FIXED_HEADER)) {
this.header_.insertBefore(drawerButton, this.header_.firstChild);
} else {
- this.element_.insertBefore(drawerButton, this.content_);
+ this.innerContainer_.insertBefore(drawerButton, this.content_);
}
var obfuscator = document.createElement('div');
obfuscator.classList.add(this.CssClasses_.OBFUSCATOR);
- this.element_.appendChild(obfuscator);
+ this.innerContainer_.appendChild(obfuscator);
obfuscator.addEventListener('click',
this.drawerToggleHandler_.bind(this));
this.obfuscator_ = obfuscator;
@@ -530,12 +524,8 @@
* Auxiliary method to programmatically select a tab in the UI.
*/
function selectTab() {
- var href = tab.href.split('#')[1];
- var panel = layout.content_.querySelector('#' + href);
layout.resetTabState_(tabs);
- layout.resetPanelState_(panels);
tab.classList.add(layout.CssClasses_.IS_ACTIVE);
- panel.classList.add(layout.CssClasses_.IS_ACTIVE);
}
if (layout.tabBar_.classList.contains(
@@ -550,10 +540,8 @@
}
tab.addEventListener('click', function(e) {
- if (tab.getAttribute('href').charAt(0) === '#') {
- e.preventDefault();
- selectTab();
- }
+ e.preventDefault();
+ selectTab();
});
tab.show = selectTab;
diff --git a/src/mdlComponentHandler.js b/src/mdlComponentHandler.js
index e4e6523..5d3c1a8 100644
--- a/src/mdlComponentHandler.js
+++ b/src/mdlComponentHandler.js
@@ -1,3 +1,5 @@
+if (typeof window === 'undefined') return;
+
/**
* @license
* Copyright 2015 Google Inc. All Rights Reserved.
@@ -477,7 +479,6 @@ window.addEventListener('load', function() {
'querySelector' in document &&
'addEventListener' in window && Array.prototype.forEach) {
document.documentElement.classList.add('mdl-js');
- componentHandler.upgradeAllRegistered();
} else {
/**
* Dummy function to avoid JS errors.
diff --git a/src/tabs/tabs.js b/src/tabs/tabs.js
index 3f4d005..c85a4af 100644
--- a/src/tabs/tabs.js
+++ b/src/tabs/tabs.js
@@ -141,12 +141,8 @@
tab.addEventListener('click', function(e) {
e.preventDefault();
- var href = tab.href.split('#')[1];
- var panel = ctx.element_.querySelector('#' + href);
ctx.resetTabState_();
- ctx.resetPanelState_();
tab.classList.add(ctx.CssClasses_.ACTIVE_CLASS);
- panel.classList.add(ctx.CssClasses_.ACTIVE_CLASS);
});
}
--
2.10.0