mui-sass 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,1259 +1,3 @@
1
- (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2
- /**
3
- * MUI config module
4
- * @module config
5
- */
6
-
7
- /** Define module API */
8
- module.exports = {
9
- /** Use debug mode */
10
- debug: true
11
- };
12
-
13
- },{}],2:[function(require,module,exports){
14
- /**
15
- * MUI CSS/JS dropdown module
16
- * @module dropdowns
17
- */
18
-
19
- 'use strict';
20
-
21
-
22
- var jqLite = require('./lib/jqLite.js'),
23
- util = require('./lib/util.js'),
24
- attrKey = 'data-mui-toggle',
25
- attrSelector = '[data-mui-toggle="dropdown"]',
26
- openClass = 'mui--is-open',
27
- menuClass = 'mui-dropdown__menu';
28
-
29
-
30
- /**
31
- * Initialize toggle element.
32
- * @param {Element} toggleEl - The toggle element.
33
- */
34
- function initialize(toggleEl) {
35
- // check flag
36
- if (toggleEl._muiDropdown === true) return;
37
- else toggleEl._muiDropdown = true;
38
-
39
- // attach click handler
40
- jqLite.on(toggleEl, 'click', clickHandler);
41
- }
42
-
43
-
44
- /**
45
- * Handle click events on dropdown toggle element.
46
- * @param {Event} ev - The DOM event
47
- */
48
- function clickHandler(ev) {
49
- // only left clicks
50
- if (ev.button !== 0) return;
51
-
52
- var toggleEl = this;
53
-
54
- // exit if toggle button is disabled
55
- if (toggleEl.getAttribute('disabled') !== null) return;
56
-
57
- // prevent form submission
58
- ev.preventDefault();
59
- ev.stopPropagation();
60
-
61
- // toggle dropdown
62
- toggleDropdown(toggleEl);
63
- }
64
-
65
-
66
- /**
67
- * Toggle the dropdown.
68
- * @param {Element} toggleEl - The dropdown toggle element.
69
- */
70
- function toggleDropdown(toggleEl) {
71
- var wrapperEl = toggleEl.parentNode,
72
- menuEl = toggleEl.nextElementSibling,
73
- doc = wrapperEl.ownerDocument;
74
-
75
- // exit if no menu element
76
- if (!menuEl || !jqLite.hasClass(menuEl, menuClass)) {
77
- return util.raiseError('Dropdown menu element not found');
78
- }
79
-
80
- // method to close dropdown
81
- function closeDropdownFn() {
82
- jqLite.removeClass(menuEl, openClass);
83
-
84
- // remove event handlers
85
- jqLite.off(doc, 'click', closeDropdownFn);
86
- }
87
-
88
- // method to open dropdown
89
- function openDropdownFn() {
90
- // position menu element below toggle button
91
- var wrapperRect = wrapperEl.getBoundingClientRect(),
92
- toggleRect = toggleEl.getBoundingClientRect();
93
-
94
- var top = toggleRect.top - wrapperRect.top + toggleRect.height;
95
- jqLite.css(menuEl, 'top', top + 'px');
96
-
97
- // add open class to wrapper
98
- jqLite.addClass(menuEl, openClass);
99
-
100
- // close dropdown when user clicks outside of menu
101
- jqLite.on(doc, 'click', closeDropdownFn);
102
- }
103
-
104
- // toggle dropdown
105
- if (jqLite.hasClass(menuEl, openClass)) closeDropdownFn();
106
- else openDropdownFn();
107
- }
108
-
109
-
110
- /** Define module API */
111
- module.exports = {
112
- /** Initialize module listeners */
113
- initListeners: function() {
114
- var doc = document;
115
-
116
- // markup elements available when method is called
117
- var elList = doc.querySelectorAll(attrSelector);
118
- for (var i=elList.length - 1; i >= 0; i--) initialize(elList[i]);
119
-
120
- // listen for new elements
121
- util.onNodeInserted(function(el) {
122
- if (el.getAttribute(attrKey) === 'dropdown') initialize(el);
123
- });
124
- }
125
- };
126
-
127
- },{"./lib/jqLite.js":5,"./lib/util.js":6}],3:[function(require,module,exports){
128
- /**
129
- * MUI CSS/JS select module
130
- * @module forms/select
131
- */
132
-
133
- 'use strict';
134
-
135
-
136
- var jqLite = require('../lib/jqLite.js'),
137
- util = require('../lib/util.js'),
138
- wrapperClass = 'mui-select',
139
- cssSelector = '.mui-select > select',
140
- menuClass = 'mui-select__menu',
141
- wrapperPadding = 15, // from CSS
142
- inputHeight = 32, // from CSS
143
- optionHeight = 42, // from CSS
144
- menuPadding = 8, // from CSS
145
- doc = document,
146
- win = window;
147
-
148
-
149
- /**
150
- * Initialize select element.
151
- * @param {Element} selectEl - The select element.
152
- */
153
- function initialize(selectEl) {
154
- // check flag
155
- if (selectEl._muiSelect === true) return;
156
- else selectEl._muiSelect = true;
157
-
158
- // use default behavior on touch devices
159
- if ('ontouchstart' in doc.documentElement) return;
160
-
161
- // initialize element
162
- new Select(selectEl);
163
- }
164
-
165
-
166
- /**
167
- * Creates a new Select object
168
- * @class
169
- */
170
- function Select(selectEl) {
171
- // instance variables
172
- this.selectEl = selectEl;
173
- this.wrapperEl = selectEl.parentNode;
174
- this.useDefault = false; // currently unused but let's keep just in case
175
-
176
- // attach event handlers
177
- jqLite.on(selectEl, 'mousedown', util.callback(this, 'mousedownHandler'));
178
- jqLite.on(selectEl, 'focus', util.callback(this, 'focusHandler'));
179
- jqLite.on(selectEl, 'click', util.callback(this, 'clickHandler'));
180
-
181
- // make wrapper focusable and fix firefox bug
182
- this.wrapperEl.tabIndex = -1;
183
- var callbackFn = util.callback(this, 'wrapperFocusHandler');
184
- jqLite.on(this.wrapperEl, 'focus', callbackFn);
185
- }
186
-
187
-
188
- /**
189
- * Disable default dropdown on mousedown.
190
- * @param {Event} ev - The DOM event
191
- */
192
- Select.prototype.mousedownHandler = function(ev) {
193
- if (ev.button !== 0 || this.useDefault === true) return;
194
- ev.preventDefault();
195
- }
196
-
197
-
198
- /**
199
- * Handle focus event on select element.
200
- * @param {Event} ev - The DOM event
201
- */
202
- Select.prototype.focusHandler = function(ev) {
203
- // check flag
204
- if (this.useDefault === true) return;
205
-
206
- var selectEl = this.selectEl,
207
- wrapperEl = this.wrapperEl,
208
- origIndex = selectEl.tabIndex,
209
- keydownFn = util.callback(this, 'keydownHandler');
210
-
211
- // attach keydown handler
212
- jqLite.on(doc, 'keydown', keydownFn);
213
-
214
- // disable tabfocus once
215
- selectEl.tabIndex = -1;
216
- jqLite.one(wrapperEl, 'blur', function() {
217
- selectEl.tabIndex = origIndex;
218
- jqLite.off(doc, 'keydown', keydownFn);
219
- });
220
-
221
- // defer focus to parent
222
- wrapperEl.focus();
223
- }
224
-
225
-
226
- /**
227
- * Handle keydown events on doc
228
- **/
229
- Select.prototype.keydownHandler = function(ev) {
230
- // spacebar, down, up
231
- if (ev.keyCode === 32 || ev.keyCode === 38 || ev.keyCode === 40) {
232
- // prevent win scroll
233
- ev.preventDefault();
234
-
235
- if (this.selectEl.disabled !== true) this.renderMenu();
236
- }
237
- }
238
-
239
-
240
- /**
241
- * Handle focus event on wrapper element.
242
- */
243
- Select.prototype.wrapperFocusHandler = function() {
244
- // firefox bugfix
245
- if (this.selectEl.disabled) return this.wrapperEl.blur();
246
- }
247
-
248
-
249
- /**
250
- * Handle click events on select element.
251
- * @param {Event} ev - The DOM event
252
- */
253
- Select.prototype.clickHandler = function(ev) {
254
- // only left clicks
255
- if (ev.button !== 0) return;
256
- this.renderMenu();
257
- }
258
-
259
-
260
- /**
261
- * Render options dropdown.
262
- */
263
- Select.prototype.renderMenu = function() {
264
- // check and reset flag
265
- if (this.useDefault === true) return this.useDefault = false;
266
-
267
- new Menu(this.wrapperEl, this.selectEl);
268
- }
269
-
270
-
271
- /**
272
- * Creates a new Menu
273
- * @class
274
- */
275
- function Menu(wrapperEl, selectEl) {
276
- // add scroll lock
277
- util.enableScrollLock();
278
-
279
- // instance variables
280
- this.origIndex = null;
281
- this.currentIndex = null;
282
- this.selectEl = selectEl;
283
- this.menuEl = this._createMenuEl(wrapperEl, selectEl);
284
- this.clickCallbackFn = util.callback(this, 'clickHandler');
285
- this.keydownCallbackFn = util.callback(this, 'keydownHandler');
286
- this.destroyCallbackFn = util.callback(this, 'destroy');
287
-
288
- // add to DOM
289
- wrapperEl.appendChild(this.menuEl);
290
- jqLite.scrollTop(this.menuEl, this.menuEl._muiScrollTop);
291
-
292
- // blur active element
293
- setTimeout(function() {
294
- // ie10 bugfix
295
- if (doc.activeElement.nodeName.toLowerCase() !== "body") {
296
- doc.activeElement.blur();
297
- }
298
- }, 0);
299
-
300
- // attach event handlers
301
- jqLite.on(this.menuEl, 'click', this.clickCallbackFn);
302
- jqLite.on(doc, 'keydown', this.keydownCallbackFn);
303
- jqLite.on(win, 'resize', this.destroyCallbackFn);
304
-
305
- // attach event handler after current event loop exits
306
- var fn = this.destroyCallbackFn;
307
- setTimeout(function() {jqLite.on(doc, 'click', fn);}, 0);
308
- }
309
-
310
-
311
- /**
312
- * Create menu element
313
- * @param {Element} selectEl - The select element
314
- */
315
- Menu.prototype._createMenuEl = function(wrapperEl, selectEl) {
316
- var optionEl, itemEl, i, minTop, maxTop, top;
317
-
318
- var menuEl = doc.createElement('div'),
319
- optionList = selectEl.children,
320
- m = optionList.length,
321
- selectedPos = 0,
322
- initTop = (menuPadding + optionHeight) - (wrapperPadding + inputHeight);
323
-
324
- // create element
325
- menuEl.className = menuClass;
326
-
327
- // add options
328
- for (i=0; i < m; i++) {
329
- optionEl = optionList[i];
330
-
331
- itemEl = doc.createElement('div');
332
- itemEl.textContent = optionEl.textContent;
333
- itemEl._muiPos = i;
334
-
335
- if (optionEl.selected) selectedPos = i;
336
-
337
- menuEl.appendChild(itemEl);
338
- }
339
-
340
- // add selected attribute
341
- menuEl.children[selectedPos].setAttribute('selected', true);
342
-
343
- // save indices
344
- this.origIndex = selectedPos;
345
- this.currentIndex = selectedPos;
346
-
347
- var viewHeight = doc.documentElement.clientHeight;
348
-
349
- // set height (use viewport as maximum height)
350
- var height = m * optionHeight + 2 * menuPadding,
351
- isOverflow = height > viewHeight;
352
-
353
- height = Math.min(height, viewHeight);
354
- jqLite.css(menuEl, 'height', height + 'px');
355
-
356
- // ideal position
357
- initTop -= selectedPos * optionHeight;
358
-
359
- // minimum position
360
- minTop = -1 * wrapperEl.getBoundingClientRect().top;
361
-
362
- // maximium position
363
- maxTop = (viewHeight - height) + minTop;
364
-
365
- // prevent overflow-y
366
- top = Math.max(initTop, minTop);
367
- top = Math.min(top, maxTop);
368
-
369
- jqLite.css(menuEl, 'top', top + 'px');
370
-
371
- // set menu scroll position
372
- if (isOverflow) {
373
- var scrollIdeal, scrollMax;
374
-
375
- scrollIdeal = (menuPadding + (selectedPos + 1) * optionHeight) -
376
- (-1 * top + wrapperPadding + inputHeight);
377
-
378
- scrollMax = m * optionHeight + 2 * menuPadding - height;
379
-
380
- menuEl._muiHasOverflow = true;
381
- menuEl._muiScrollTop = Math.min(scrollIdeal, scrollMax);
382
- } else {
383
- menuEl._muiHasOverflow = false;
384
- menuEl._muiScrollTop = 0;
385
- }
386
-
387
- return menuEl;
388
- }
389
-
390
-
391
- /**
392
- * Handle keydown events on doc element.
393
- * @param {Event} ev - The DOM event
394
- */
395
- Menu.prototype.keydownHandler = function(ev) {
396
- var keyCode = ev.keyCode;
397
-
398
- // tab
399
- if (keyCode === 9) return this.destroy();
400
-
401
- // escape | up | down | enter
402
- if (keyCode === 27 || keyCode === 40 || keyCode === 38 || keyCode === 13) {
403
- ev.preventDefault();
404
- }
405
-
406
- if (keyCode === 27) {
407
- this.destroy();
408
- } else if (keyCode === 40) {
409
- this.increment();
410
- } else if (keyCode === 38) {
411
- this.decrement();
412
- } else if (keyCode === 13) {
413
- this.selectCurrent();
414
- this.destroy();
415
- }
416
- }
417
-
418
-
419
- /**
420
- * Handle click events on menu element.
421
- * @param {Event} ev - The DOM event
422
- */
423
- Menu.prototype.clickHandler = function(ev) {
424
- // don't allow events to bubble
425
- ev.stopPropagation();
426
-
427
- var pos = ev.target._muiPos;
428
-
429
- // ignore clicks on non-items
430
- if (pos === undefined) return;
431
-
432
- // select option
433
- this.currentIndex = pos;
434
- this.selectCurrent();
435
-
436
- // destroy menu
437
- this.destroy();
438
- }
439
-
440
-
441
- /**
442
- * Increment selected item
443
- */
444
- Menu.prototype.increment = function() {
445
- if (this.currentIndex === this.menuEl.children.length - 1) return;
446
-
447
- this.menuEl.children[this.currentIndex].removeAttribute('selected');
448
- this.currentIndex += 1;
449
- this.menuEl.children[this.currentIndex].setAttribute('selected', true);
450
- }
451
-
452
-
453
- /**
454
- * Decrement selected item
455
- */
456
- Menu.prototype.decrement = function() {
457
- if (this.currentIndex === 0) return;
458
-
459
- this.menuEl.children[this.currentIndex].removeAttribute('selected');
460
- this.currentIndex -= 1;
461
- this.menuEl.children[this.currentIndex].setAttribute('selected', true);
462
- }
463
-
464
-
465
- /**
466
- * Select current item
467
- */
468
- Menu.prototype.selectCurrent = function() {
469
- if (this.currentIndex !== this.origIndex) {
470
- this.selectEl.children[this.origIndex].selected = false;
471
- this.selectEl.children[this.currentIndex].selected = true;
472
-
473
- // trigger change event
474
- util.dispatchEvent(this.selectEl, 'change');
475
- }
476
- }
477
-
478
-
479
- /**
480
- * Destroy menu and detach event handlers
481
- */
482
- Menu.prototype.destroy = function() {
483
- // remove element and focus element
484
- this.menuEl.parentNode.removeChild(this.menuEl);
485
- this.selectEl.focus();
486
-
487
- // remove scroll lock
488
- util.disableScrollLock();
489
-
490
- // remove event handlers
491
- jqLite.off(this.menuEl, 'click', this.clickCallbackFn);
492
- jqLite.off(doc, 'keydown', this.keydownCallbackFn);
493
- jqLite.off(doc, 'click', this.destroyCallbackFn);
494
- jqLite.off(win, 'resize', this.destroyCallbackFn);
495
- }
496
-
497
-
498
- /** Define module API */
499
- module.exports = {
500
- /** Initialize module listeners */
501
- initListeners: function() {
502
- // markup elements available when method is called
503
- var elList = doc.querySelectorAll(cssSelector);
504
- for (var i=elList.length - 1; i >= 0; i--) initialize(elList[i]);
505
-
506
- // listen for new elements
507
- util.onNodeInserted(function(el) {
508
- if (el.tagName === 'SELECT' &&
509
- jqLite.hasClass(el.parentNode, wrapperClass)) {
510
- initialize(el);
511
- }
512
- });
513
- }
514
- };
515
-
516
- },{"../lib/jqLite.js":5,"../lib/util.js":6}],4:[function(require,module,exports){
517
- /**
518
- * MUI CSS/JS form-control module
519
- * @module forms/form-control
520
- */
521
-
522
- 'use strict';
523
-
524
-
525
- var jqLite = require('../lib/jqLite.js'),
526
- util = require('../lib/util.js'),
527
- cssSelector = '.mui-textfield > input, .mui-textfield > textarea',
528
- emptyClass = 'mui--is-empty',
529
- notEmptyClass = 'mui--is-not-empty',
530
- dirtyClass = 'mui--is-dirty',
531
- floatingLabelClass = 'mui-textfield--float-label';
532
-
533
-
534
- /**
535
- * Initialize input element.
536
- * @param {Element} inputEl - The input element.
537
- */
538
- function initialize(inputEl) {
539
- // check flag
540
- if (inputEl._muiTextfield === true) return;
541
- else inputEl._muiTextfield = true;
542
-
543
- if (inputEl.value.length) jqLite.addClass(inputEl, notEmptyClass);
544
- else jqLite.addClass(inputEl, emptyClass);
545
-
546
- jqLite.on(inputEl, 'input', inputHandler);
547
-
548
- // add dirty class on focus
549
- jqLite.on(inputEl, 'focus', function(){jqLite.addClass(this, dirtyClass);});
550
- }
551
-
552
-
553
- /**
554
- * Handle input events.
555
- */
556
- function inputHandler() {
557
- var inputEl = this;
558
-
559
- if (inputEl.value.length) {
560
- jqLite.removeClass(inputEl, emptyClass);
561
- jqLite.addClass(inputEl, notEmptyClass);
562
- } else {
563
- jqLite.removeClass(inputEl, notEmptyClass);
564
- jqLite.addClass(inputEl, emptyClass)
565
- }
566
-
567
- jqLite.addClass(inputEl, dirtyClass);
568
- }
569
-
570
-
571
- /** Define module API */
572
- module.exports = {
573
- /** Initialize input elements */
574
- initialize: initialize,
575
-
576
- /** Initialize module listeners */
577
- initListeners: function() {
578
- var doc = document;
579
-
580
- // markup elements available when method is called
581
- var elList = doc.querySelectorAll(cssSelector);
582
- for (var i=elList.length - 1; i >= 0; i--) initialize(elList[i]);
583
-
584
- // listen for new elements
585
- util.onNodeInserted(function(el) {
586
- if (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA') initialize(el);
587
- });
588
-
589
- // add transition css for floating labels
590
- setTimeout(function() {
591
- var css = '.mui-textfield.mui-textfield--float-label > label {' + [
592
- '-webkit-transition',
593
- '-moz-transition',
594
- '-o-transition',
595
- 'transition',
596
- ''
597
- ].join(':all .15s ease-out;') + '}';
598
-
599
- util.loadStyle(css);
600
- }, 150);
601
-
602
- // pointer-events shim for floating labels
603
- if (util.supportsPointerEvents() === false) {
604
- jqLite.on(document, 'click', function(ev) {
605
- var targetEl = ev.target;
606
-
607
- if (targetEl.tagName === 'LABEL' &&
608
- jqLite.hasClass(targetEl.parentNode, floatingLabelClass)) {
609
- var inputEl = targetEl.previousElementSibling;
610
- if (inputEl) inputEl.focus();
611
- }
612
- });
613
- }
614
- }
615
- };
616
-
617
- },{"../lib/jqLite.js":5,"../lib/util.js":6}],5:[function(require,module,exports){
618
- /**
619
- * MUI CSS/JS jqLite module
620
- * @module lib/jqLite
621
- */
622
-
623
- 'use strict';
624
-
625
- // Global vars
626
- var gDoc = document,
627
- gDocEl = gDoc.documentElement,
628
- gWin = window;
629
-
630
-
631
- /**
632
- * Add a class to an element.
633
- * @param {Element} element - The DOM element.
634
- * @param {string} cssClasses - Space separated list of class names.
635
- */
636
- function jqLiteAddClass(element, cssClasses) {
637
- if (!cssClasses || !element.setAttribute) return;
638
-
639
- var existingClasses = _getExistingClasses(element),
640
- splitClasses = cssClasses.split(' '),
641
- cssClass;
642
-
643
- for (var i=0; i < splitClasses.length; i++) {
644
- cssClass = splitClasses[i].trim();
645
- if (existingClasses.indexOf(' ' + cssClass + ' ') === -1) {
646
- existingClasses += cssClass + ' ';
647
- }
648
- }
649
-
650
- element.setAttribute('class', existingClasses.trim());
651
- }
652
-
653
-
654
- /**
655
- * Get or set CSS properties.
656
- * @param {Element} element - The DOM element.
657
- * @param {string} [name] - The property name.
658
- * @param {string} [value] - The property value.
659
- */
660
- function jqLiteCss(element, name, value) {
661
- // Return full style object
662
- if (name === undefined) {
663
- return getComputedStyle(element);
664
- }
665
-
666
- var nameType = jqLiteType(name);
667
-
668
- // Set multiple values
669
- if (nameType === 'object') {
670
- for (var key in name) element.style[_camelCase(key)] = name[key];
671
- return;
672
- }
673
-
674
- // Set a single value
675
- if (nameType === 'string' && value !== undefined) {
676
- element.style[_camelCase(name)] = value;
677
- }
678
-
679
- var styleObj = getComputedStyle(element),
680
- isArray = (jqLiteType(name) === 'array');
681
-
682
- // Read single value
683
- if (!isArray) return _getCurrCssProp(element, name, styleObj);
684
-
685
- // Read multiple values
686
- var outObj = {},
687
- key;
688
-
689
- for (var i=0; i < name.length; i++) {
690
- key = name[i];
691
- outObj[key] = _getCurrCssProp(element, key, styleObj);
692
- }
693
-
694
- return outObj;
695
- }
696
-
697
-
698
- /**
699
- * Check if element has class.
700
- * @param {Element} element - The DOM element.
701
- * @param {string} cls - The class name string.
702
- */
703
- function jqLiteHasClass(element, cls) {
704
- if (!cls || !element.getAttribute) return false;
705
- return (_getExistingClasses(element).indexOf(' ' + cls + ' ') > -1);
706
- }
707
-
708
-
709
- /**
710
- * Return the type of a variable.
711
- * @param {} somevar - The JavaScript variable.
712
- */
713
- function jqLiteType(somevar) {
714
- // handle undefined
715
- if (somevar === undefined) return 'undefined';
716
-
717
- // handle others (of type [object <Type>])
718
- var typeStr = Object.prototype.toString.call(somevar);
719
- if (typeStr.indexOf('[object ') === 0) {
720
- return typeStr.slice(8, -1).toLowerCase();
721
- } else {
722
- throw new Error("MUI: Could not understand type: " + typeStr);
723
- }
724
- }
725
-
726
-
727
- /**
728
- * Attach an event handler to a DOM element
729
- * @param {Element} element - The DOM element.
730
- * @param {string} type - The event type name.
731
- * @param {Function} callback - The callback function.
732
- * @param {Boolean} useCapture - Use capture flag.
733
- */
734
- function jqLiteOn(element, type, callback, useCapture) {
735
- useCapture = (useCapture === undefined) ? false : useCapture;
736
-
737
- // add to DOM
738
- element.addEventListener(type, callback, useCapture);
739
-
740
- // add to cache
741
- var cache = element._muiEventCache = element._muiEventCache || {};
742
- cache[type] = cache[type] || [];
743
- cache[type].push([callback, useCapture]);
744
- }
745
-
746
-
747
- /**
748
- * Remove an event handler from a DOM element
749
- * @param {Element} element - The DOM element.
750
- * @param {string} type - The event type name.
751
- * @param {Function} callback - The callback function.
752
- * @param {Boolean} useCapture - Use capture flag.
753
- */
754
- function jqLiteOff(element, type, callback, useCapture) {
755
- useCapture = (useCapture === undefined) ? false : useCapture;
756
-
757
- // remove from cache
758
- var cache = element._muiEventCache = element._muiEventCache || {},
759
- argsList = cache[type] || [],
760
- args,
761
- i;
762
-
763
- i = argsList.length;
764
- while (i--) {
765
- args = argsList[i];
766
-
767
- // remove all events if callback is undefined
768
- if (callback === undefined ||
769
- (args[0] === callback && args[1] === useCapture)) {
770
-
771
- // remove from cache
772
- argsList.splice(i, 1);
773
-
774
- // remove from DOM
775
- element.removeEventListener(type, args[0], args[1]);
776
- }
777
- }
778
- }
779
-
780
-
781
- /**
782
- * Attach an event hander which will only execute once
783
- * @param {Element} element - The DOM element.
784
- * @param {string} type - The event type name.
785
- * @param {Function} callback - The callback function.
786
- * @param {Boolean} useCapture - Use capture flag.
787
- */
788
- function jqLiteOne(element, type, callback, useCapture) {
789
- jqLiteOn(element, type, function onFn(ev) {
790
- // execute callback
791
- if (callback) callback.apply(this, arguments);
792
-
793
- // remove wrapper
794
- jqLiteOff(element, type, onFn);
795
- }, useCapture);
796
- }
797
-
798
-
799
- /**
800
- * Get or set horizontal scroll position
801
- * @param {Element} element - The DOM element
802
- * @param {number} [value] - The scroll position
803
- */
804
- function jqLiteScrollLeft(element, value) {
805
- // get
806
- if (value === undefined) {
807
- if (element === gWin) {
808
- var t = (gWin.pageXOffset || gDocEl.scrollLeft)
809
- return t - (gDocEl.clientLeft || 0);
810
- } else {
811
- return element.scrollLeft;
812
- }
813
- }
814
-
815
- // set
816
- if (element === gWin) gWin.scrollTo(value, jqLiteScrollTop(gWin));
817
- else element.scrollLeft = value;
818
- }
819
-
820
-
821
- /**
822
- * Get or set vertical scroll position
823
- * @param {Element} element - The DOM element
824
- * @param {number} value - The scroll position
825
- */
826
- function jqLiteScrollTop(element, value) {
827
- //return _scrollPos(element, 'top', value);
828
-
829
- // get
830
- if (value === undefined) {
831
- if (element === gWin) {
832
- return (gWin.pageYOffset || gDocEl.scrollTop) - (gDocEl.clientTop || 0);
833
- } else {
834
- return element.scrollTop;
835
- }
836
- }
837
-
838
- // set
839
- if (element === gWin) gWin.scrollTo(jqLiteScrollLeft(gWin), value);
840
- else element.scrollTop = value;
841
- }
842
-
843
-
844
- /**
845
- * Return object representing top/left offset and element height/width.
846
- * @param {Element} element - The DOM element.
847
- */
848
- function jqLiteOffset(element) {
849
- var rect = element.getBoundingClientRect(),
850
- scrollTop = jqLiteScrollTop(gWin),
851
- scrollLeft = jqLiteScrollLeft(gWin);
852
-
853
- return {
854
- top: rect.top + scrollTop,
855
- left: rect.left + scrollLeft,
856
- height: rect.height,
857
- width: rect.width
858
- };
859
- }
860
-
861
-
862
- /**
863
- * Attach a callback to the DOM ready event listener
864
- * @param {Function} fn - The callback function.
865
- */
866
- function jqLiteReady(fn) {
867
- var done = false,
868
- top = true,
869
- doc = document,
870
- win = doc.defaultView,
871
- root = doc.documentElement,
872
- add = doc.addEventListener ? 'addEventListener' : 'attachEvent',
873
- rem = doc.addEventListener ? 'removeEventListener' : 'detachEvent',
874
- pre = doc.addEventListener ? '' : 'on';
875
-
876
- var init = function(e) {
877
- if (e.type == 'readystatechange' && doc.readyState != 'complete') {
878
- return;
879
- }
880
-
881
- (e.type == 'load' ? win : doc)[rem](pre + e.type, init, false);
882
- if (!done && (done = true)) fn.call(win, e.type || e);
883
- };
884
-
885
- var poll = function() {
886
- try { root.doScroll('left'); } catch(e) { setTimeout(poll, 50); return; }
887
- init('poll');
888
- };
889
-
890
- if (doc.readyState == 'complete') {
891
- fn.call(win, 'lazy');
892
- } else {
893
- if (doc.createEventObject && root.doScroll) {
894
- try { top = !win.frameElement; } catch(e) { }
895
- if (top) poll();
896
- }
897
- doc[add](pre + 'DOMContentLoaded', init, false);
898
- doc[add](pre + 'readystatechange', init, false);
899
- win[add](pre + 'load', init, false);
900
- }
901
- }
902
-
903
-
904
- /**
905
- * Remove classes from a DOM element
906
- * @param {Element} element - The DOM element.
907
- * @param {string} cssClasses - Space separated list of class names.
908
- */
909
- function jqLiteRemoveClass(element, cssClasses) {
910
- if (!cssClasses || !element.setAttribute) return;
911
-
912
- var existingClasses = _getExistingClasses(element),
913
- splitClasses = cssClasses.split(' '),
914
- cssClass;
915
-
916
- for (var i=0; i < splitClasses.length; i++) {
917
- cssClass = splitClasses[i].trim();
918
- while (existingClasses.indexOf(' ' + cssClass + ' ') >= 0) {
919
- existingClasses = existingClasses.replace(' ' + cssClass + ' ', ' ');
920
- }
921
- }
922
-
923
- element.setAttribute('class', existingClasses.trim());
924
- }
925
-
926
-
927
- // ------------------------------
928
- // Utilities
929
- // ------------------------------
930
- var SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g,
931
- MOZ_HACK_REGEXP = /^moz([A-Z])/,
932
- ESCAPE_REGEXP = /([.*+?^=!:${}()|\[\]\/\\])/g,
933
- BOOLEAN_ATTRS;
934
-
935
-
936
- BOOLEAN_ATTRS = {
937
- multiple: true,
938
- selected: true,
939
- checked: true,
940
- disabled: true,
941
- readonly: true,
942
- required: true,
943
- open: true
944
- }
945
-
946
-
947
- function _getExistingClasses(element) {
948
- var classes = (element.getAttribute('class') || '').replace(/[\n\t]/g, '');
949
- return ' ' + classes + ' ';
950
- }
951
-
952
-
953
- function _camelCase(name) {
954
- return name.
955
- replace(SPECIAL_CHARS_REGEXP, function(_, separator, letter, offset) {
956
- return offset ? letter.toUpperCase() : letter;
957
- }).
958
- replace(MOZ_HACK_REGEXP, 'Moz$1');
959
- }
960
-
961
-
962
- function _escapeRegExp(string) {
963
- return string.replace(ESCAPE_REGEXP, "\\$1");
964
- }
965
-
966
-
967
- function _getCurrCssProp(elem, name, computed) {
968
- var ret;
969
-
970
- // try computed style
971
- ret = computed.getPropertyValue(name);
972
-
973
- // try style attribute (if element is not attached to document)
974
- if (ret === '' && !elem.ownerDocument) ret = elem.style[_camelCase(name)];
975
-
976
- return ret;
977
- }
978
-
979
-
980
- /**
981
- * Module API
982
- */
983
- module.exports = {
984
- /** Add classes */
985
- addClass: jqLiteAddClass,
986
-
987
- /** Get or set CSS properties */
988
- css: jqLiteCss,
989
-
990
- /** Check for class */
991
- hasClass: jqLiteHasClass,
992
-
993
- /** Remove event handlers */
994
- off: jqLiteOff,
995
-
996
- /** Return offset values */
997
- offset: jqLiteOffset,
998
-
999
- /** Add event handlers */
1000
- on: jqLiteOn,
1001
-
1002
- /** Add an execute-once event handler */
1003
- one: jqLiteOne,
1004
-
1005
- /** DOM ready event handler */
1006
- ready: jqLiteReady,
1007
-
1008
- /** Remove classes */
1009
- removeClass: jqLiteRemoveClass,
1010
-
1011
- /** Check JavaScript variable instance type */
1012
- type: jqLiteType,
1013
-
1014
- /** Get or set horizontal scroll position */
1015
- scrollLeft: jqLiteScrollLeft,
1016
-
1017
- /** Get or set vertical scroll position */
1018
- scrollTop: jqLiteScrollTop
1019
- };
1020
-
1021
- },{}],6:[function(require,module,exports){
1022
- /**
1023
- * MUI CSS/JS utilities module
1024
- * @module lib/util
1025
- */
1026
-
1027
- 'use strict';
1028
-
1029
-
1030
- var config = require('../config.js'),
1031
- jqLite = require('./jqLite.js'),
1032
- win = window,
1033
- doc = document,
1034
- nodeInsertedCallbacks = [],
1035
- scrollLock = 0,
1036
- scrollLockPos,
1037
- scrollLockEl,
1038
- head,
1039
- _supportsPointerEvents;
1040
-
1041
- head = doc.head || doc.getElementsByTagName('head')[0] || doc.documentElement;
1042
-
1043
-
1044
- /**
1045
- * Logging function
1046
- */
1047
- function logFn() {
1048
- if (config.debug && typeof win.console !== "undefined") {
1049
- try {
1050
- win.console.log.apply(win.console, arguments);
1051
- } catch (a) {
1052
- var e = Array.prototype.slice.call(arguments);
1053
- win.console.log(e.join("\n"));
1054
- }
1055
- }
1056
- }
1057
-
1058
-
1059
- /**
1060
- * Load CSS text in new stylesheet
1061
- * @param {string} cssText - The css text.
1062
- */
1063
- function loadStyleFn(cssText) {
1064
- var e = doc.createElement('style');
1065
- e.type = 'text/css';
1066
-
1067
- if (e.styleSheet) e.styleSheet.cssText = cssText;
1068
- else e.appendChild(doc.createTextNode(cssText));
1069
-
1070
- // add to document
1071
- head.insertBefore(e, head.firstChild);
1072
-
1073
- return e;
1074
- }
1075
-
1076
-
1077
- /**
1078
- * Raise an error
1079
- * @param {string} msg - The error message.
1080
- */
1081
- function raiseErrorFn(msg) {
1082
- throw new Error("MUI: " + msg);
1083
- }
1084
-
1085
-
1086
- /**
1087
- * Register callbacks on muiNodeInserted event
1088
- * @param {function} callbackFn - The callback function.
1089
- */
1090
- function onNodeInsertedFn(callbackFn) {
1091
- nodeInsertedCallbacks.push(callbackFn);
1092
-
1093
- // initalize listeners
1094
- if (nodeInsertedCallbacks._initialized === undefined) {
1095
- jqLite.on(doc, 'animationstart', animationHandlerFn);
1096
- jqLite.on(doc, 'mozAnimationStart', animationHandlerFn);
1097
- jqLite.on(doc, 'webkitAnimationStart', animationHandlerFn);
1098
-
1099
- nodeInsertedCallbacks._initialized = true;
1100
- }
1101
- }
1102
-
1103
-
1104
- /**
1105
- * Execute muiNodeInserted callbacks
1106
- * @param {Event} ev - The DOM event.
1107
- */
1108
- function animationHandlerFn(ev) {
1109
- // check animation name
1110
- if (ev.animationName !== 'mui-node-inserted') return;
1111
-
1112
- var el = ev.target;
1113
-
1114
- // iterate through callbacks
1115
- for (var i=nodeInsertedCallbacks.length - 1; i >= 0; i--) {
1116
- nodeInsertedCallbacks[i](el);
1117
- }
1118
- }
1119
-
1120
-
1121
- /**
1122
- * Convert Classname object, with class as key and true/false as value, to an
1123
- * class string.
1124
- * @param {Object} classes The classes
1125
- * @return {String} class string
1126
- */
1127
- function classNamesFn(classes) {
1128
- var cs = '';
1129
- for (var i in classes) {
1130
- cs += (classes[i]) ? i + ' ' : '';
1131
- }
1132
- return cs.trim();
1133
- }
1134
-
1135
-
1136
- /**
1137
- * Check if client supports pointer events.
1138
- */
1139
- function supportsPointerEventsFn() {
1140
- // check cache
1141
- if (_supportsPointerEvents !== undefined) return _supportsPointerEvents;
1142
-
1143
- var element = document.createElement('x');
1144
- element.style.cssText = 'pointer-events:auto';
1145
- _supportsPointerEvents = (element.style.pointerEvents === 'auto');
1146
- return _supportsPointerEvents;
1147
- }
1148
-
1149
-
1150
- /**
1151
- * Create callback closure.
1152
- * @param {Object} instance - The object instance.
1153
- * @param {String} funcName - The name of the callback function.
1154
- */
1155
- function callbackFn(instance, funcName) {
1156
- return function() {instance[funcName].apply(instance, arguments);};
1157
- }
1158
-
1159
-
1160
- /**
1161
- * Dispatch event.
1162
- * @param {Element} element - The DOM element.
1163
- * @param {String} eventType - The event type.
1164
- * @param {Boolean} bubbles=true - If true, event bubbles.
1165
- * @param {Boolean} cancelable=true = If true, event is cancelable
1166
- * @param {Object} [data] - Data to add to event object
1167
- */
1168
- function dispatchEventFn(element, eventType, bubbles, cancelable, data) {
1169
- var ev = document.createEvent('HTMLEvents'),
1170
- bubbles = (bubbles !== undefined) ? bubbles : true,
1171
- cancelable = (cancelable !== undefined) ? cancelable : true,
1172
- k;
1173
-
1174
- ev.initEvent(eventType, bubbles, cancelable);
1175
-
1176
- // add data to event object
1177
- if (data) for (k in data) ev[k] = data[k];
1178
-
1179
- // dispatch
1180
- if (element) element.dispatchEvent(ev);
1181
-
1182
- return ev;
1183
- }
1184
-
1185
-
1186
- /**
1187
- * Turn on window scroll lock.
1188
- */
1189
- function enableScrollLockFn() {
1190
- // increment counter
1191
- scrollLock += 1
1192
-
1193
- // add lock
1194
- if (scrollLock === 1) {
1195
- scrollLockPos = {left: jqLite.scrollLeft(win), top: jqLite.scrollTop(win)};
1196
- scrollLockEl = loadStyleFn('body{overflow:hidden!important;}');
1197
- win.scrollTo(scrollLockPos.left, scrollLockPos.top);
1198
- }
1199
- }
1200
-
1201
-
1202
- /**
1203
- * Turn off window scroll lock.
1204
- */
1205
- function disableScrollLockFn() {
1206
- // ignore
1207
- if (scrollLock === 0) return;
1208
-
1209
- // decrement counter
1210
- scrollLock -= 1
1211
-
1212
- // remove lock
1213
- if (scrollLock === 0) {
1214
- scrollLockEl.parentNode.removeChild(scrollLockEl);
1215
- win.scrollTo(scrollLockPos.left, scrollLockPos.top);
1216
- scrollLockEl = null;
1217
- }
1218
- }
1219
-
1220
-
1221
- /**
1222
- * Define the module API
1223
- */
1224
- module.exports = {
1225
- /** Create callback closures */
1226
- callback: callbackFn,
1227
-
1228
- /** Classnames object to string */
1229
- classNames: classNamesFn,
1230
-
1231
- /** Disable scroll lock */
1232
- disableScrollLock: disableScrollLockFn,
1233
-
1234
- /** Dispatch event */
1235
- dispatchEvent: dispatchEventFn,
1236
-
1237
- /** Enable scroll lock */
1238
- enableScrollLock: enableScrollLockFn,
1239
-
1240
- /** Log messages to the console when debug is turned on */
1241
- log: logFn,
1242
-
1243
- /** Load CSS text as new stylesheet */
1244
- loadStyle: loadStyleFn,
1245
-
1246
- /** Register muiNodeInserted handler */
1247
- onNodeInserted: onNodeInsertedFn,
1248
-
1249
- /** Raise MUI error */
1250
- raiseError: raiseErrorFn,
1251
-
1252
- /** Support Pointer Events check */
1253
- supportsPointerEvents: supportsPointerEventsFn
1254
- };
1255
-
1256
- },{"../config.js":1,"./jqLite.js":5}],7:[function(require,module,exports){
1257
1
  /**
1258
2
  * MUI CSS/JS main module
1259
3
  * @module main
@@ -1291,463 +35,3 @@ module.exports = {
1291
35
  tabs.initListeners();
1292
36
  });
1293
37
  })(window);
1294
-
1295
- },{"./dropdowns.js":2,"./forms/select.js":3,"./forms/textfield.js":4,"./lib/jqLite.js":5,"./lib/util.js":6,"./overlay.js":8,"./ripple.js":9,"./tabs.js":10}],8:[function(require,module,exports){
1296
- /**
1297
- * MUI CSS/JS overlay module
1298
- * @module overlay
1299
- */
1300
-
1301
- 'use strict';
1302
-
1303
-
1304
- var util = require('./lib/util.js'),
1305
- jqLite = require('./lib/jqLite.js'),
1306
- overlayId = 'mui-overlay',
1307
- bodyClass = 'mui--overflow-hidden',
1308
- iosRegex = /(iPad|iPhone|iPod)/g;
1309
-
1310
-
1311
- /**
1312
- * Turn overlay on/off.
1313
- * @param {string} action - Turn overlay "on"/"off".
1314
- * @param {object} [options]
1315
- * @config {boolean} [keyboard] - If true, close when escape key is pressed.
1316
- * @config {boolean} [static] - If false, close when backdrop is clicked.
1317
- * @config {Function} [onclose] - Callback function to execute on close
1318
- * @param {Element} [childElement] - Child element to add to overlay.
1319
- */
1320
- function overlayFn(action) {
1321
- var overlayEl;
1322
-
1323
- if (action === 'on') {
1324
- // extract arguments
1325
- var arg, options, childElement;
1326
-
1327
- // pull options and childElement from arguments
1328
- for (var i=arguments.length - 1; i > 0; i--) {
1329
- arg = arguments[i];
1330
-
1331
- if (jqLite.type(arg) === 'object') options = arg;
1332
- if (arg instanceof Element && arg.nodeType === 1) childElement = arg;
1333
- }
1334
-
1335
- // option defaults
1336
- options = options || {};
1337
- if (options.keyboard === undefined) options.keyboard = true;
1338
- if (options.static === undefined) options.static = false;
1339
-
1340
- // execute method
1341
- overlayEl = overlayOn(options, childElement);
1342
-
1343
- } else if (action === 'off') {
1344
- overlayEl = overlayOff();
1345
-
1346
- } else {
1347
- // raise error
1348
- util.raiseError("Expecting 'on' or 'off'");
1349
- }
1350
-
1351
- return overlayEl;
1352
- }
1353
-
1354
-
1355
- /**
1356
- * Turn on overlay.
1357
- * @param {object} options - Overlay options.
1358
- * @param {Element} childElement - The child element.
1359
- */
1360
- function overlayOn(options, childElement) {
1361
- var bodyEl = document.body,
1362
- overlayEl = document.getElementById(overlayId);
1363
-
1364
- // add overlay
1365
- util.enableScrollLock();
1366
- //jqLite.addClass(bodyEl, bodyClass);
1367
-
1368
- if (!overlayEl) {
1369
- // create overlayEl
1370
- overlayEl = document.createElement('div');
1371
- overlayEl.setAttribute('id', overlayId);
1372
-
1373
- // add child element
1374
- if (childElement) overlayEl.appendChild(childElement);
1375
-
1376
- bodyEl.appendChild(overlayEl);
1377
-
1378
- } else {
1379
- // remove existing children
1380
- while (overlayEl.firstChild) overlayEl.removeChild(overlayEl.firstChild);
1381
-
1382
- // add child element
1383
- if (childElement) overlayEl.appendChild(childElement);
1384
- }
1385
-
1386
- // iOS bugfix
1387
- if (iosRegex.test(navigator.userAgent)) {
1388
- jqLite.css(overlayEl, 'cursor', 'pointer');
1389
- }
1390
-
1391
- // handle options
1392
- if (options.keyboard) addKeyupHandler();
1393
- else removeKeyupHandler();
1394
-
1395
- if (options.static) removeClickHandler(overlayEl);
1396
- else addClickHandler(overlayEl);
1397
-
1398
- // attach options
1399
- overlayEl.muiOptions = options;
1400
-
1401
- return overlayEl;
1402
- }
1403
-
1404
-
1405
- /**
1406
- * Turn off overlay.
1407
- */
1408
- function overlayOff() {
1409
- var overlayEl = document.getElementById(overlayId),
1410
- callbackFn;
1411
-
1412
- if (overlayEl) {
1413
- // remove children
1414
- while (overlayEl.firstChild) overlayEl.removeChild(overlayEl.firstChild);
1415
-
1416
- // remove overlay element
1417
- overlayEl.parentNode.removeChild(overlayEl);
1418
-
1419
- // callback reference
1420
- callbackFn = overlayEl.muiOptions.onclose;
1421
- }
1422
-
1423
- util.disableScrollLock();
1424
-
1425
- // remove option handlers
1426
- removeKeyupHandler();
1427
- removeClickHandler(overlayEl);
1428
-
1429
- // execute callback
1430
- if (callbackFn) callbackFn();
1431
-
1432
- return overlayEl;
1433
- }
1434
-
1435
-
1436
- /**
1437
- * Add keyup handler.
1438
- */
1439
- function addKeyupHandler() {
1440
- jqLite.on(document, 'keyup', onKeyup);
1441
- }
1442
-
1443
-
1444
- /**
1445
- * Remove keyup handler.
1446
- */
1447
- function removeKeyupHandler() {
1448
- jqLite.off(document, 'keyup', onKeyup);
1449
- }
1450
-
1451
-
1452
- /**
1453
- * Teardown overlay when escape key is pressed.
1454
- */
1455
- function onKeyup(ev) {
1456
- if (ev.keyCode === 27) overlayOff();
1457
- }
1458
-
1459
-
1460
- /**
1461
- * Add click handler.
1462
- */
1463
- function addClickHandler(overlayEl) {
1464
- jqLite.on(overlayEl, 'click', onClick);
1465
- }
1466
-
1467
-
1468
- /**
1469
- * Remove click handler.
1470
- */
1471
- function removeClickHandler(overlayEl) {
1472
- jqLite.off(overlayEl, 'click', onClick);
1473
- }
1474
-
1475
-
1476
- /**
1477
- * Teardown overlay when backdrop is clicked.
1478
- */
1479
- function onClick(ev) {
1480
- if (ev.target.id === overlayId) overlayOff();
1481
- }
1482
-
1483
-
1484
- /** Define module API */
1485
- module.exports = overlayFn;
1486
-
1487
- },{"./lib/jqLite.js":5,"./lib/util.js":6}],9:[function(require,module,exports){
1488
- /**
1489
- * MUI CSS/JS ripple module
1490
- * @module ripple
1491
- */
1492
-
1493
- 'use strict';
1494
-
1495
-
1496
- var jqLite = require('./lib/jqLite.js'),
1497
- util = require('./lib/util.js'),
1498
- btnClass = 'mui-btn',
1499
- btnFABClass = 'mui-btn--fab',
1500
- rippleClass = 'mui-ripple-effect',
1501
- animationName = 'mui-btn-inserted';
1502
-
1503
-
1504
- /**
1505
- * Add ripple effects to button element.
1506
- * @param {Element} buttonEl - The button element.
1507
- */
1508
- function initialize(buttonEl) {
1509
- // check flag
1510
- if (buttonEl._muiRipple === true) return;
1511
- else buttonEl._muiRipple = true;
1512
-
1513
- // exit if element is INPUT (doesn't support absolute positioned children)
1514
- if (buttonEl.tagName === 'INPUT') return;
1515
-
1516
- // attach event handler
1517
- jqLite.on(buttonEl, 'touchstart', eventHandler);
1518
- jqLite.on(buttonEl, 'mousedown', eventHandler);
1519
- }
1520
-
1521
-
1522
- /**
1523
- * Event handler
1524
- * @param {Event} ev - The DOM event
1525
- */
1526
- function eventHandler(ev) {
1527
- // only left clicks
1528
- if (ev.button !== 0) return;
1529
-
1530
- var buttonEl = this;
1531
-
1532
- // exit if button is disabled
1533
- if (buttonEl.disabled === true) return;
1534
-
1535
- // de-dupe touchstart and mousedown with 100msec flag
1536
- if (buttonEl.touchFlag === true) {
1537
- return;
1538
- } else {
1539
- buttonEl.touchFlag = true;
1540
- setTimeout(function() {
1541
- buttonEl.touchFlag = false;
1542
- }, 100);
1543
- }
1544
-
1545
- var rippleEl = document.createElement('div');
1546
- rippleEl.className = rippleClass;
1547
-
1548
- var offset = jqLite.offset(buttonEl),
1549
- xPos = ev.pageX - offset.left,
1550
- yPos = ev.pageY - offset.top,
1551
- diameter,
1552
- radius;
1553
-
1554
- // get height
1555
- if (jqLite.hasClass(buttonEl, btnFABClass)) diameter = offset.height / 2;
1556
- else diameter = offset.height;
1557
-
1558
- radius = diameter / 2;
1559
-
1560
- jqLite.css(rippleEl, {
1561
- height: diameter + 'px',
1562
- width: diameter + 'px',
1563
- top: yPos - radius + 'px',
1564
- left: xPos - radius + 'px'
1565
- });
1566
-
1567
- buttonEl.appendChild(rippleEl);
1568
-
1569
- window.setTimeout(function() {
1570
- buttonEl.removeChild(rippleEl);
1571
- }, 2000);
1572
- }
1573
-
1574
-
1575
- /** Define module API */
1576
- module.exports = {
1577
- /** Initialize module listeners */
1578
- initListeners: function() {
1579
- var doc = document;
1580
-
1581
- // markup elements available when method is called
1582
- var elList = doc.getElementsByClassName(btnClass);
1583
- for (var i=elList.length - 1; i >= 0; i--) initialize(elList[i]);
1584
-
1585
- // listen for new elements
1586
- util.onNodeInserted(function(el) {
1587
- if (jqLite.hasClass(el, btnClass)) initialize(el);
1588
- });
1589
- }
1590
- };
1591
-
1592
- },{"./lib/jqLite.js":5,"./lib/util.js":6}],10:[function(require,module,exports){
1593
- /**
1594
- * MUI CSS/JS tabs module
1595
- * @module tabs
1596
- */
1597
-
1598
- 'use strict';
1599
-
1600
-
1601
- var jqLite = require('./lib/jqLite.js'),
1602
- util = require('./lib/util.js'),
1603
- attrKey = 'data-mui-toggle',
1604
- attrSelector = '[' + attrKey + '="tab"]',
1605
- controlsAttrKey = 'data-mui-controls',
1606
- activeClass = 'mui--is-active',
1607
- showstartKey = 'mui.tabs.showstart',
1608
- showendKey = 'mui.tabs.showend',
1609
- hidestartKey = 'mui.tabs.hidestart',
1610
- hideendKey = 'mui.tabs.hideend';
1611
-
1612
-
1613
- /**
1614
- * Initialize the toggle element
1615
- * @param {Element} toggleEl - The toggle element.
1616
- */
1617
- function initialize(toggleEl) {
1618
- // check flag
1619
- if (toggleEl._muiTabs === true) return;
1620
- else toggleEl._muiTabs = true;
1621
-
1622
- // attach click handler
1623
- jqLite.on(toggleEl, 'click', clickHandler);
1624
- }
1625
-
1626
-
1627
- /**
1628
- * Handle clicks on the toggle element.
1629
- * @param {Event} ev - The DOM event.
1630
- */
1631
- function clickHandler(ev) {
1632
- // only left clicks
1633
- if (ev.button !== 0) return;
1634
-
1635
- var toggleEl = this;
1636
-
1637
- // exit if toggle element is disabled
1638
- if (toggleEl.getAttribute('disabled') !== null) return;
1639
-
1640
- activateTab(toggleEl);
1641
- }
1642
-
1643
-
1644
- /**
1645
- * Activate the tab controlled by the toggle element.
1646
- * @param {Element} toggleEl - The toggle element.
1647
- */
1648
- function activateTab(currToggleEl) {
1649
- var currTabEl = currToggleEl.parentNode,
1650
- currPaneId = currToggleEl.getAttribute(controlsAttrKey),
1651
- currPaneEl = document.getElementById(currPaneId),
1652
- prevTabEl,
1653
- prevPaneEl,
1654
- prevPaneId,
1655
- prevToggleEl,
1656
- currData,
1657
- prevData,
1658
- ev1,
1659
- ev2,
1660
- cssSelector;
1661
-
1662
- // exit if already active
1663
- if (jqLite.hasClass(currTabEl, activeClass)) return;
1664
-
1665
- // raise error if pane doesn't exist
1666
- if (!currPaneEl) util.raiseError('Tab pane "' + currPaneId + '" not found');
1667
-
1668
- // get previous pane
1669
- prevPaneEl = getActiveSibling(currPaneEl);
1670
- prevPaneId = prevPaneEl.id;
1671
-
1672
- // get previous toggle and tab elements
1673
- cssSelector = '[' + controlsAttrKey + '="' + prevPaneId + '"]';
1674
- prevToggleEl = document.querySelectorAll(cssSelector)[0];
1675
- prevTabEl = prevToggleEl.parentNode;
1676
-
1677
- // define event data
1678
- currData = {paneId: currPaneId, relatedPaneId: prevPaneId};
1679
- prevData = {paneId: prevPaneId, relatedPaneId: currPaneId};
1680
-
1681
- // dispatch 'hidestart', 'showstart' events
1682
- ev1 = util.dispatchEvent(prevToggleEl, hidestartKey, true, true, prevData);
1683
- ev2 = util.dispatchEvent(currToggleEl, showstartKey, true, true, currData);
1684
-
1685
- // let events bubble
1686
- setTimeout(function() {
1687
- // exit if either event was canceled
1688
- if (ev1.defaultPrevented || ev2.defaultPrevented) return;
1689
-
1690
- // de-activate previous
1691
- if (prevTabEl) jqLite.removeClass(prevTabEl, activeClass);
1692
- if (prevPaneEl) jqLite.removeClass(prevPaneEl, activeClass);
1693
-
1694
- // activate current
1695
- jqLite.addClass(currTabEl, activeClass);
1696
- jqLite.addClass(currPaneEl, activeClass);
1697
-
1698
- // dispatch 'hideend', 'showend' events
1699
- util.dispatchEvent(prevToggleEl, hideendKey, true, false, prevData);
1700
- util.dispatchEvent(currToggleEl, showendKey, true, false, currData);
1701
- }, 0);
1702
- }
1703
-
1704
-
1705
- /**
1706
- * Get previous active sibling.
1707
- * @param {Element} el - The anchor element.
1708
- */
1709
- function getActiveSibling(el) {
1710
- var elList = el.parentNode.children,
1711
- q = elList.length,
1712
- activeEl = null,
1713
- tmpEl;
1714
-
1715
- while (q-- && !activeEl) {
1716
- tmpEl = elList[q];
1717
- if (tmpEl !== el && jqLite.hasClass(tmpEl, activeClass)) activeEl = tmpEl
1718
- }
1719
-
1720
- return activeEl;
1721
- }
1722
-
1723
-
1724
- /** Define module API */
1725
- module.exports = {
1726
- /** Initialize module listeners */
1727
- initListeners: function() {
1728
- // markup elements available when method is called
1729
- var elList = document.querySelectorAll(attrSelector);
1730
- for (var i=elList.length - 1; i >= 0; i--) initialize(elList[i]);
1731
-
1732
- // TODO: listen for new elements
1733
- util.onNodeInserted(function(el) {
1734
- if (el.getAttribute(attrKey) === 'tab') initialize(el);
1735
- });
1736
- },
1737
-
1738
- /** External API */
1739
- api: {
1740
- activate: function(paneId) {
1741
- var cssSelector = '[' + controlsAttrKey + '=' + paneId + ']',
1742
- toggleEl = document.querySelectorAll(cssSelector);
1743
-
1744
- if (!toggleEl.length) {
1745
- util.raiseError('Tab control for pane "' + paneId + '" not found');
1746
- }
1747
-
1748
- activateTab(toggleEl[0]);
1749
- }
1750
- }
1751
- };
1752
-
1753
- },{"./lib/jqLite.js":5,"./lib/util.js":6}]},{},[7]);