forked from muicss/mui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuttons.js
More file actions
89 lines (66 loc) · 1.72 KB
/
buttons.js
File metadata and controls
89 lines (66 loc) · 1.72 KB
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
/**
* MUI WebComponents buttons module
* @module webcomponents/buttons
*/
'use strict';
var config = require('../js/config'),
jqLite = require('../js/lib/jqLite'),
btnClass = 'mui-btn',
btnTagName = btnClass,
btnAttrs = {style: 1, color: 1, size: 1};
/**
* Class representing a button.
* @class
*/
var BtnProto = Object.create(HTMLElement.prototype);
/** Button createdCallback */
BtnProto.createdCallback = function() {
var root = this.createShadowRoot(),
innerEl = document.createElement('button'),
cls = btnClass,
k,
v;
// populate innerEl
for (var i=0; i < this.childNodes.length; i++) {
innerEl.appendChild(this.childNodes[i]);
}
// style|color|size
for (k in btnAttrs) {
v = this.getAttribute(k);
if (v !== 'default') cls += ' ' + btnClass + '--' + v;
}
jqLite.addClass(innerEl, cls);
// disabled
if (this.getAttribute('disabled') !== null) {
innerEl.setAttribute('disabled', 'disabled');
}
root.appendChild(_getStyleEl().cloneNode(true));
root.appendChild(innerEl);
};
// ============================================================================
// UTILITIES
// ============================================================================
var styleEl;
/**
* Get or create a style element.
* @function
*/
function _getStyleEl() {
if (styleEl === undefined) {
styleEl = document.createElement('style');
styleEl.innerHTML = require('mui.min.css');
}
return styleEl;
}
/** Define module API */
module.exports = {
/** Register module elements */
registerElements: function() {
var BtnElement = document.registerElement(btnTagName, {
prototype: BtnProto
});
return {
BtnElement: BtnElement
}
}
};