material_design_lite-sass 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +108 -0
- data/Rakefile +4 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/material_design_lite-sass.rb +46 -0
- data/lib/material_design_lite/sass/engine.rb +13 -0
- data/lib/material_design_lite/sass/version.rb +5 -0
- data/material_design_lite-sass.gemspec +28 -0
- data/vendor/assets/javascripts/material.js +3919 -0
- data/vendor/assets/javascripts/material/button.js +132 -0
- data/vendor/assets/javascripts/material/checkbox.js +265 -0
- data/vendor/assets/javascripts/material/data-table.js +149 -0
- data/vendor/assets/javascripts/material/icon-toggle.js +248 -0
- data/vendor/assets/javascripts/material/layout.js +434 -0
- data/vendor/assets/javascripts/material/mdlComponentHandler.js +346 -0
- data/vendor/assets/javascripts/material/menu.js +468 -0
- data/vendor/assets/javascripts/material/progress.js +116 -0
- data/vendor/assets/javascripts/material/rAF.js +38 -0
- data/vendor/assets/javascripts/material/radio.js +257 -0
- data/vendor/assets/javascripts/material/ripple.js +244 -0
- data/vendor/assets/javascripts/material/slider.js +252 -0
- data/vendor/assets/javascripts/material/spinner.js +140 -0
- data/vendor/assets/javascripts/material/switch.js +269 -0
- data/vendor/assets/javascripts/material/tabs.js +152 -0
- data/vendor/assets/javascripts/material/textfield.js +247 -0
- data/vendor/assets/javascripts/material/tooltip.js +146 -0
- data/vendor/assets/stylesheets/_material.scss +50 -0
- data/vendor/assets/stylesheets/material/_animation.scss +34 -0
- data/vendor/assets/stylesheets/material/_badge.scss +66 -0
- data/vendor/assets/stylesheets/material/_button.scss +298 -0
- data/vendor/assets/stylesheets/material/_card.scss +111 -0
- data/vendor/assets/stylesheets/material/_checkbox.scss +175 -0
- data/vendor/assets/stylesheets/material/_color-definitions.scss +599 -0
- data/vendor/assets/stylesheets/material/_data-table.scss +105 -0
- data/vendor/assets/stylesheets/material/_functions.scss +3 -0
- data/vendor/assets/stylesheets/material/_grid.scss +180 -0
- data/vendor/assets/stylesheets/material/_icon-toggle.scss +121 -0
- data/vendor/assets/stylesheets/material/_layout.scss +580 -0
- data/vendor/assets/stylesheets/material/_mega_footer.scss +309 -0
- data/vendor/assets/stylesheets/material/_menu.scss +193 -0
- data/vendor/assets/stylesheets/material/_mini_footer.scss +88 -0
- data/vendor/assets/stylesheets/material/_mixins.scss +268 -0
- data/vendor/assets/stylesheets/material/_palette.scss +2303 -0
- data/vendor/assets/stylesheets/material/_progress.scss +115 -0
- data/vendor/assets/stylesheets/material/_radio.scss +155 -0
- data/vendor/assets/stylesheets/material/_resets.scss +55 -0
- data/vendor/assets/stylesheets/material/_ripple.scss +42 -0
- data/vendor/assets/stylesheets/material/_shadow.scss +42 -0
- data/vendor/assets/stylesheets/material/_slider.scss +396 -0
- data/vendor/assets/stylesheets/material/_spinner.scss +248 -0
- data/vendor/assets/stylesheets/material/_switch.scss +199 -0
- data/vendor/assets/stylesheets/material/_tabs.scss +115 -0
- data/vendor/assets/stylesheets/material/_textfield.scss +190 -0
- data/vendor/assets/stylesheets/material/_tooltip.scss +66 -0
- data/vendor/assets/stylesheets/material/_typography.scss +297 -0
- data/vendor/assets/stylesheets/material/_variables.scss +572 -0
- data/vendor/assets/stylesheets/material/resets/_h5bp.scss +284 -0
- data/vendor/assets/stylesheets/material/resets/_mobile.scss +25 -0
- metadata +151 -0
@@ -0,0 +1,132 @@
|
|
1
|
+
/**
|
2
|
+
* @license
|
3
|
+
* Copyright 2015 Google Inc. All Rights Reserved.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*/
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Class constructor for Button MDL component.
|
20
|
+
* Implements MDL component design pattern defined at:
|
21
|
+
* https://github.com/jasonmayes/mdl-component-design-pattern
|
22
|
+
* @param {HTMLElement} element The element that will be upgraded.
|
23
|
+
*/
|
24
|
+
function MaterialButton(element) {
|
25
|
+
'use strict';
|
26
|
+
|
27
|
+
this.element_ = element;
|
28
|
+
|
29
|
+
// Initialize instance.
|
30
|
+
this.init();
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Store constants in one place so they can be updated easily.
|
35
|
+
* @enum {string | number}
|
36
|
+
* @private
|
37
|
+
*/
|
38
|
+
MaterialButton.prototype.Constant_ = {
|
39
|
+
// None for now.
|
40
|
+
};
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Store strings for class names defined by this component that are used in
|
44
|
+
* JavaScript. This allows us to simply change it in one place should we
|
45
|
+
* decide to modify at a later date.
|
46
|
+
* @enum {string}
|
47
|
+
* @private
|
48
|
+
*/
|
49
|
+
MaterialButton.prototype.CssClasses_ = {
|
50
|
+
RIPPLE_EFFECT: 'mdl-js-ripple-effect',
|
51
|
+
RIPPLE_CONTAINER: 'mdl-button__ripple-container',
|
52
|
+
RIPPLE: 'mdl-ripple'
|
53
|
+
};
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Handle blur of element.
|
57
|
+
* @param {HTMLElement} element The instance of a button we want to blur.
|
58
|
+
* @private
|
59
|
+
*/
|
60
|
+
MaterialButton.prototype.blurHandler = function(event) {
|
61
|
+
'use strict';
|
62
|
+
|
63
|
+
if (event) {
|
64
|
+
this.element_.blur();
|
65
|
+
}
|
66
|
+
};
|
67
|
+
|
68
|
+
// Public methods.
|
69
|
+
|
70
|
+
/**
|
71
|
+
* Disable button.
|
72
|
+
* @public
|
73
|
+
*/
|
74
|
+
MaterialButton.prototype.disable = function() {
|
75
|
+
'use strict';
|
76
|
+
|
77
|
+
this.element_.disabled = true;
|
78
|
+
};
|
79
|
+
|
80
|
+
/**
|
81
|
+
* Enable button.
|
82
|
+
* @public
|
83
|
+
*/
|
84
|
+
MaterialButton.prototype.enable = function() {
|
85
|
+
'use strict';
|
86
|
+
|
87
|
+
this.element_.disabled = false;
|
88
|
+
};
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Initialize element.
|
92
|
+
*/
|
93
|
+
MaterialButton.prototype.init = function() {
|
94
|
+
'use strict';
|
95
|
+
|
96
|
+
if (this.element_) {
|
97
|
+
if (this.element_.classList.contains(this.CssClasses_.RIPPLE_EFFECT)) {
|
98
|
+
var rippleContainer = document.createElement('span');
|
99
|
+
rippleContainer.classList.add(this.CssClasses_.RIPPLE_CONTAINER);
|
100
|
+
this.rippleElement_ = document.createElement('span');
|
101
|
+
this.rippleElement_.classList.add(this.CssClasses_.RIPPLE);
|
102
|
+
rippleContainer.appendChild(this.rippleElement_);
|
103
|
+
this.boundRippleBlurHandler = this.blurHandler.bind(this);
|
104
|
+
this.rippleElement_.addEventListener('mouseup', this.boundRippleBlurHandler);
|
105
|
+
this.element_.appendChild(rippleContainer);
|
106
|
+
}
|
107
|
+
this.boundButtonBlurHandler = this.blurHandler.bind(this);
|
108
|
+
this.element_.addEventListener('mouseup', this.boundButtonBlurHandler);
|
109
|
+
this.element_.addEventListener('mouseleave', this.boundButtonBlurHandler);
|
110
|
+
}
|
111
|
+
};
|
112
|
+
|
113
|
+
/**
|
114
|
+
* Downgrade the element.
|
115
|
+
*/
|
116
|
+
MaterialButton.prototype.mdlDowngrade_ = function() {
|
117
|
+
'use strict';
|
118
|
+
if (this.rippleElement_) {
|
119
|
+
this.rippleElement_.removeEventListener('mouseup', this.boundRippleBlurHandler);
|
120
|
+
}
|
121
|
+
this.element_.removeEventListener('mouseup', this.boundButtonBlurHandler);
|
122
|
+
this.element_.removeEventListener('mouseleave', this.boundButtonBlurHandler);
|
123
|
+
};
|
124
|
+
|
125
|
+
// The component registers itself. It can assume componentHandler is available
|
126
|
+
// in the global scope.
|
127
|
+
componentHandler.register({
|
128
|
+
constructor: MaterialButton,
|
129
|
+
classAsString: 'MaterialButton',
|
130
|
+
cssClass: 'mdl-js-button',
|
131
|
+
widget: true
|
132
|
+
});
|
@@ -0,0 +1,265 @@
|
|
1
|
+
/**
|
2
|
+
* @license
|
3
|
+
* Copyright 2015 Google Inc. All Rights Reserved.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*/
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Class constructor for Checkbox MDL component.
|
20
|
+
* Implements MDL component design pattern defined at:
|
21
|
+
* https://github.com/jasonmayes/mdl-component-design-pattern
|
22
|
+
* @param {HTMLElement} element The element that will be upgraded.
|
23
|
+
*/
|
24
|
+
function MaterialCheckbox(element) {
|
25
|
+
'use strict';
|
26
|
+
|
27
|
+
this.element_ = element;
|
28
|
+
|
29
|
+
// Initialize instance.
|
30
|
+
this.init();
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Store constants in one place so they can be updated easily.
|
35
|
+
* @enum {string | number}
|
36
|
+
* @private
|
37
|
+
*/
|
38
|
+
MaterialCheckbox.prototype.Constant_ = {
|
39
|
+
TINY_TIMEOUT: 0.001
|
40
|
+
};
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Store strings for class names defined by this component that are used in
|
44
|
+
* JavaScript. This allows us to simply change it in one place should we
|
45
|
+
* decide to modify at a later date.
|
46
|
+
* @enum {string}
|
47
|
+
* @private
|
48
|
+
*/
|
49
|
+
MaterialCheckbox.prototype.CssClasses_ = {
|
50
|
+
INPUT: 'mdl-checkbox__input',
|
51
|
+
BOX_OUTLINE: 'mdl-checkbox__box-outline',
|
52
|
+
FOCUS_HELPER: 'mdl-checkbox__focus-helper',
|
53
|
+
TICK_OUTLINE: 'mdl-checkbox__tick-outline',
|
54
|
+
RIPPLE_EFFECT: 'mdl-js-ripple-effect',
|
55
|
+
RIPPLE_IGNORE_EVENTS: 'mdl-js-ripple-effect--ignore-events',
|
56
|
+
RIPPLE_CONTAINER: 'mdl-checkbox__ripple-container',
|
57
|
+
RIPPLE_CENTER: 'mdl-ripple--center',
|
58
|
+
RIPPLE: 'mdl-ripple',
|
59
|
+
IS_FOCUSED: 'is-focused',
|
60
|
+
IS_DISABLED: 'is-disabled',
|
61
|
+
IS_CHECKED: 'is-checked',
|
62
|
+
IS_UPGRADED: 'is-upgraded'
|
63
|
+
};
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Handle change of state.
|
67
|
+
* @param {Event} event The event that fired.
|
68
|
+
* @private
|
69
|
+
*/
|
70
|
+
MaterialCheckbox.prototype.onChange_ = function(event) {
|
71
|
+
'use strict';
|
72
|
+
|
73
|
+
this.updateClasses_();
|
74
|
+
};
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Handle focus of element.
|
78
|
+
* @param {Event} event The event that fired.
|
79
|
+
* @private
|
80
|
+
*/
|
81
|
+
MaterialCheckbox.prototype.onFocus_ = function(event) {
|
82
|
+
'use strict';
|
83
|
+
|
84
|
+
this.element_.classList.add(this.CssClasses_.IS_FOCUSED);
|
85
|
+
};
|
86
|
+
|
87
|
+
/**
|
88
|
+
* Handle lost focus of element.
|
89
|
+
* @param {Event} event The event that fired.
|
90
|
+
* @private
|
91
|
+
*/
|
92
|
+
MaterialCheckbox.prototype.onBlur_ = function(event) {
|
93
|
+
'use strict';
|
94
|
+
|
95
|
+
this.element_.classList.remove(this.CssClasses_.IS_FOCUSED);
|
96
|
+
};
|
97
|
+
|
98
|
+
/**
|
99
|
+
* Handle mouseup.
|
100
|
+
* @param {Event} event The event that fired.
|
101
|
+
* @private
|
102
|
+
*/
|
103
|
+
MaterialCheckbox.prototype.onMouseUp_ = function(event) {
|
104
|
+
'use strict';
|
105
|
+
|
106
|
+
this.blur_();
|
107
|
+
};
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Handle class updates.
|
111
|
+
* @param {HTMLElement} button The button whose classes we should update.
|
112
|
+
* @param {HTMLElement} label The label whose classes we should update.
|
113
|
+
* @private
|
114
|
+
*/
|
115
|
+
MaterialCheckbox.prototype.updateClasses_ = function() {
|
116
|
+
'use strict';
|
117
|
+
|
118
|
+
if (this.inputElement_.disabled) {
|
119
|
+
this.element_.classList.add(this.CssClasses_.IS_DISABLED);
|
120
|
+
} else {
|
121
|
+
this.element_.classList.remove(this.CssClasses_.IS_DISABLED);
|
122
|
+
}
|
123
|
+
|
124
|
+
if (this.inputElement_.checked) {
|
125
|
+
this.element_.classList.add(this.CssClasses_.IS_CHECKED);
|
126
|
+
} else {
|
127
|
+
this.element_.classList.remove(this.CssClasses_.IS_CHECKED);
|
128
|
+
}
|
129
|
+
};
|
130
|
+
|
131
|
+
/**
|
132
|
+
* Add blur.
|
133
|
+
* @private
|
134
|
+
*/
|
135
|
+
MaterialCheckbox.prototype.blur_ = function(event) {
|
136
|
+
'use strict';
|
137
|
+
|
138
|
+
// TODO: figure out why there's a focus event being fired after our blur,
|
139
|
+
// so that we can avoid this hack.
|
140
|
+
window.setTimeout(function() {
|
141
|
+
this.inputElement_.blur();
|
142
|
+
}.bind(this), this.Constant_.TINY_TIMEOUT);
|
143
|
+
};
|
144
|
+
|
145
|
+
// Public methods.
|
146
|
+
|
147
|
+
/**
|
148
|
+
* Disable checkbox.
|
149
|
+
* @public
|
150
|
+
*/
|
151
|
+
MaterialCheckbox.prototype.disable = function() {
|
152
|
+
'use strict';
|
153
|
+
|
154
|
+
this.inputElement_.disabled = true;
|
155
|
+
this.updateClasses_();
|
156
|
+
};
|
157
|
+
|
158
|
+
/**
|
159
|
+
* Enable checkbox.
|
160
|
+
* @public
|
161
|
+
*/
|
162
|
+
MaterialCheckbox.prototype.enable = function() {
|
163
|
+
'use strict';
|
164
|
+
|
165
|
+
this.inputElement_.disabled = false;
|
166
|
+
this.updateClasses_();
|
167
|
+
};
|
168
|
+
|
169
|
+
/**
|
170
|
+
* Check checkbox.
|
171
|
+
* @public
|
172
|
+
*/
|
173
|
+
MaterialCheckbox.prototype.check = function() {
|
174
|
+
'use strict';
|
175
|
+
|
176
|
+
this.inputElement_.checked = true;
|
177
|
+
this.updateClasses_();
|
178
|
+
};
|
179
|
+
|
180
|
+
/**
|
181
|
+
* Uncheck checkbox.
|
182
|
+
* @public
|
183
|
+
*/
|
184
|
+
MaterialCheckbox.prototype.uncheck = function() {
|
185
|
+
'use strict';
|
186
|
+
|
187
|
+
this.inputElement_.checked = false;
|
188
|
+
this.updateClasses_();
|
189
|
+
};
|
190
|
+
|
191
|
+
/**
|
192
|
+
* Initialize element.
|
193
|
+
*/
|
194
|
+
MaterialCheckbox.prototype.init = function() {
|
195
|
+
'use strict';
|
196
|
+
|
197
|
+
if (this.element_) {
|
198
|
+
this.inputElement_ = this.element_.querySelector('.' +
|
199
|
+
this.CssClasses_.INPUT);
|
200
|
+
|
201
|
+
var boxOutline = document.createElement('span');
|
202
|
+
boxOutline.classList.add(this.CssClasses_.BOX_OUTLINE);
|
203
|
+
|
204
|
+
var tickContainer = document.createElement('span');
|
205
|
+
tickContainer.classList.add(this.CssClasses_.FOCUS_HELPER);
|
206
|
+
|
207
|
+
var tickOutline = document.createElement('span');
|
208
|
+
tickOutline.classList.add(this.CssClasses_.TICK_OUTLINE);
|
209
|
+
|
210
|
+
boxOutline.appendChild(tickOutline);
|
211
|
+
|
212
|
+
this.element_.appendChild(tickContainer);
|
213
|
+
this.element_.appendChild(boxOutline);
|
214
|
+
|
215
|
+
if (this.element_.classList.contains(this.CssClasses_.RIPPLE_EFFECT)) {
|
216
|
+
this.element_.classList.add(this.CssClasses_.RIPPLE_IGNORE_EVENTS);
|
217
|
+
this.rippleContainerElement_ = document.createElement('span');
|
218
|
+
this.rippleContainerElement_.classList.add(this.CssClasses_.RIPPLE_CONTAINER);
|
219
|
+
this.rippleContainerElement_.classList.add(this.CssClasses_.RIPPLE_EFFECT);
|
220
|
+
this.rippleContainerElement_.classList.add(this.CssClasses_.RIPPLE_CENTER);
|
221
|
+
this.boundRippleMouseUp = this.onMouseUp_.bind(this);
|
222
|
+
this.rippleContainerElement_.addEventListener('mouseup', this.boundRippleMouseUp);
|
223
|
+
|
224
|
+
var ripple = document.createElement('span');
|
225
|
+
ripple.classList.add(this.CssClasses_.RIPPLE);
|
226
|
+
|
227
|
+
this.rippleContainerElement_.appendChild(ripple);
|
228
|
+
this.element_.appendChild(this.rippleContainerElement_);
|
229
|
+
}
|
230
|
+
this.boundInputOnChange = this.onChange_.bind(this);
|
231
|
+
this.boundInputOnFocus = this.onFocus_.bind(this);
|
232
|
+
this.boundInputOnBlur = this.onBlur_.bind(this);
|
233
|
+
this.boundElementMouseUp = this.onMouseUp_.bind(this);
|
234
|
+
this.inputElement_.addEventListener('change', this.boundInputOnChange);
|
235
|
+
this.inputElement_.addEventListener('focus', this.boundInputOnFocus);
|
236
|
+
this.inputElement_.addEventListener('blur', this.boundInputOnBlur);
|
237
|
+
this.element_.addEventListener('mouseup', this.boundElementMouseUp);
|
238
|
+
|
239
|
+
this.updateClasses_();
|
240
|
+
this.element_.classList.add(this.CssClasses_.IS_UPGRADED);
|
241
|
+
}
|
242
|
+
};
|
243
|
+
|
244
|
+
/*
|
245
|
+
* Downgrade the component.
|
246
|
+
*/
|
247
|
+
MaterialCheckbox.prototype.mdlDowngrade_ = function() {
|
248
|
+
'use strict';
|
249
|
+
if (this.rippleContainerElement_) {
|
250
|
+
this.rippleContainerElement_.removeEventListener('mouseup', this.boundRippleMouseUp);
|
251
|
+
}
|
252
|
+
this.inputElement_.removeEventListener('change', this.boundInputOnChange);
|
253
|
+
this.inputElement_.removeEventListener('focus', this.boundInputOnFocus);
|
254
|
+
this.inputElement_.removeEventListener('blur', this.boundInputOnBlur);
|
255
|
+
this.element_.removeEventListener('mouseup', this.boundElementMouseUp);
|
256
|
+
};
|
257
|
+
|
258
|
+
// The component registers itself. It can assume componentHandler is available
|
259
|
+
// in the global scope.
|
260
|
+
componentHandler.register({
|
261
|
+
constructor: MaterialCheckbox,
|
262
|
+
classAsString: 'MaterialCheckbox',
|
263
|
+
cssClass: 'mdl-js-checkbox',
|
264
|
+
widget: true
|
265
|
+
});
|
@@ -0,0 +1,149 @@
|
|
1
|
+
/**
|
2
|
+
* @license
|
3
|
+
* Copyright 2015 Google Inc. All Rights Reserved.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*/
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Class constructor for Data Table Card MDL component.
|
20
|
+
* Implements MDL component design pattern defined at:
|
21
|
+
* https://github.com/jasonmayes/mdl-component-design-pattern
|
22
|
+
* @param {HTMLElement} element The element that will be upgraded.
|
23
|
+
*/
|
24
|
+
function MaterialDataTable(element) {
|
25
|
+
'use strict';
|
26
|
+
|
27
|
+
this.element_ = element;
|
28
|
+
|
29
|
+
// Initialize instance.
|
30
|
+
this.init();
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Store constants in one place so they can be updated easily.
|
35
|
+
* @enum {string | number}
|
36
|
+
* @private
|
37
|
+
*/
|
38
|
+
MaterialDataTable.prototype.Constant_ = {
|
39
|
+
// None at the moment.
|
40
|
+
};
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Store strings for class names defined by this component that are used in
|
44
|
+
* JavaScript. This allows us to simply change it in one place should we
|
45
|
+
* decide to modify at a later date.
|
46
|
+
* @enum {string}
|
47
|
+
* @private
|
48
|
+
*/
|
49
|
+
MaterialDataTable.prototype.CssClasses_ = {
|
50
|
+
DATA_TABLE: 'mdl-data-table',
|
51
|
+
SELECTABLE: 'mdl-data-table--selectable',
|
52
|
+
IS_SELECTED: 'is-selected',
|
53
|
+
IS_UPGRADED: 'is-upgraded'
|
54
|
+
};
|
55
|
+
|
56
|
+
MaterialDataTable.prototype.selectRow_ = function(checkbox, row, rows) {
|
57
|
+
'use strict';
|
58
|
+
|
59
|
+
if (row) {
|
60
|
+
return function() {
|
61
|
+
if (checkbox.checked) {
|
62
|
+
row.classList.add(this.CssClasses_.IS_SELECTED);
|
63
|
+
} else {
|
64
|
+
row.classList.remove(this.CssClasses_.IS_SELECTED);
|
65
|
+
}
|
66
|
+
}.bind(this);
|
67
|
+
}
|
68
|
+
|
69
|
+
if (rows) {
|
70
|
+
return function() {
|
71
|
+
var i;
|
72
|
+
var el;
|
73
|
+
if (checkbox.checked) {
|
74
|
+
for (i = 0; i < rows.length; i++) {
|
75
|
+
el = rows[i].querySelector('td').querySelector('.mdl-checkbox');
|
76
|
+
el.MaterialCheckbox.check();
|
77
|
+
rows[i].classList.add(this.CssClasses_.IS_SELECTED);
|
78
|
+
}
|
79
|
+
} else {
|
80
|
+
for (i = 0; i < rows.length; i++) {
|
81
|
+
el = rows[i].querySelector('td').querySelector('.mdl-checkbox');
|
82
|
+
el.MaterialCheckbox.uncheck();
|
83
|
+
rows[i].classList.remove(this.CssClasses_.IS_SELECTED);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}.bind(this);
|
87
|
+
}
|
88
|
+
};
|
89
|
+
|
90
|
+
MaterialDataTable.prototype.createCheckbox_ = function(row, rows) {
|
91
|
+
'use strict';
|
92
|
+
|
93
|
+
var label = document.createElement('label');
|
94
|
+
label.classList.add('mdl-checkbox');
|
95
|
+
label.classList.add('mdl-js-checkbox');
|
96
|
+
label.classList.add('mdl-js-ripple-effect');
|
97
|
+
label.classList.add('mdl-data-table__select');
|
98
|
+
var checkbox = document.createElement('input');
|
99
|
+
checkbox.type = 'checkbox';
|
100
|
+
checkbox.classList.add('mdl-checkbox__input');
|
101
|
+
if (row) {
|
102
|
+
checkbox.addEventListener('change', this.selectRow_(checkbox, row));
|
103
|
+
} else if (rows) {
|
104
|
+
checkbox.addEventListener('change', this.selectRow_(checkbox, null, rows));
|
105
|
+
}
|
106
|
+
label.appendChild(checkbox);
|
107
|
+
componentHandler.upgradeElement(label, 'MaterialCheckbox');
|
108
|
+
return label;
|
109
|
+
};
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Initialize element.
|
113
|
+
*/
|
114
|
+
MaterialDataTable.prototype.init = function() {
|
115
|
+
'use strict';
|
116
|
+
|
117
|
+
if (this.element_) {
|
118
|
+
|
119
|
+
var firstHeader = this.element_.querySelector('th');
|
120
|
+
var rows = this.element_.querySelector('tbody').querySelectorAll('tr');
|
121
|
+
|
122
|
+
if (this.element_.classList.contains(this.CssClasses_.SELECTABLE)) {
|
123
|
+
var th = document.createElement('th');
|
124
|
+
var headerCheckbox = this.createCheckbox_(null, rows);
|
125
|
+
th.appendChild(headerCheckbox);
|
126
|
+
firstHeader.parentElement.insertBefore(th, firstHeader);
|
127
|
+
|
128
|
+
for (var i = 0; i < rows.length; i++) {
|
129
|
+
var firstCell = rows[i].querySelector('td');
|
130
|
+
if (firstCell) {
|
131
|
+
var td = document.createElement('td');
|
132
|
+
var rowCheckbox = this.createCheckbox_(rows[i]);
|
133
|
+
td.appendChild(rowCheckbox);
|
134
|
+
rows[i].insertBefore(td, firstCell);
|
135
|
+
}
|
136
|
+
}
|
137
|
+
}
|
138
|
+
|
139
|
+
this.element_.classList.add(this.CssClasses_.IS_UPGRADED);
|
140
|
+
}
|
141
|
+
};
|
142
|
+
|
143
|
+
// The component registers itself. It can assume componentHandler is available
|
144
|
+
// in the global scope.
|
145
|
+
componentHandler.register({
|
146
|
+
constructor: MaterialDataTable,
|
147
|
+
classAsString: 'MaterialDataTable',
|
148
|
+
cssClass: 'mdl-js-data-table'
|
149
|
+
});
|