material 0.7.0 → 0.7.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.
- package/form.js +27 -0
- package/index.js +59 -58
- package/list.js +35 -0
- package/package.json +5 -1
- package/src/appbar.js +7 -204
- package/src/badge.js +27 -0
- package/src/button.js +155 -155
- package/src/calendar.js +0 -2
- package/src/card.js +0 -2
- package/src/checkbox.js +0 -2
- package/src/component.js +0 -2
- package/src/container.js +0 -2
- package/src/datehour.js +38 -0
- package/src/dialog.js +105 -152
- package/src/divider.js +0 -2
- package/src/drawer.js +0 -2
- package/src/{control/file.js → file.js} +15 -45
- package/src/form/verify.js +2 -2
- package/src/form.js +0 -2
- package/src/icon.js +0 -2
- package/src/image.js +39 -106
- package/src/item.js +0 -2
- package/src/{control/link.js → link.js} +13 -32
- package/src/list/build.js +2 -2
- package/src/list/collection.js +1 -1
- package/src/list/filter.js +2 -2
- package/src/list/request.js +1 -1
- package/src/list/search.js +5 -5
- package/src/list.js +29 -217
- package/src/loading.js +73 -0
- package/src/menu.js +60 -116
- package/src/mixin/display.js +0 -1
- package/src/mixin/insert.js +2 -24
- package/src/{control/module → module}/attributes.js +2 -2
- package/src/module/build.js +8 -5
- package/src/navigation.js +19 -0
- package/src/progress.js +0 -2
- package/src/search.js +71 -0
- package/src/select.js +57 -272
- package/src/{control/selecter.js → selecter.js} +5 -5
- package/src/skin/material/component/navigation.sass +1 -0
- package/src/skin/material/control/button.sass +10 -0
- package/src/slider.js +0 -2
- package/src/snackbar.js +72 -51
- package/src/switch.js +111 -103
- package/src/{control/switcher.js → switcher.js} +17 -20
- package/src/text.js +25 -74
- package/src/textfield.js +96 -233
- package/src/banner.js +0 -231
- package/src/control/button.js +0 -239
- package/src/control/button.new.js +0 -190
- package/src/control/datehour.js +0 -65
- package/src/control/dialog.js +0 -175
- package/src/control/image.js +0 -92
- package/src/control/list.js +0 -67
- package/src/control/loading.js +0 -128
- package/src/control/menu.js +0 -85
- package/src/control/search.js +0 -98
- package/src/control/select.js +0 -130
- package/src/control/snackbar.js +0 -91
- package/src/control/switch.js +0 -272
- package/src/control/text.js +0 -70
- package/src/control/textfield.js +0 -177
- package/src/tabs/setup.js +0 -0
- /package/src/{control/module → module}/addclass.js +0 -0
package/src/snackbar.js
CHANGED
|
@@ -1,69 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
//
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
// base class
|
|
2
|
+
import EventEmitter from './mixin/emitter'
|
|
3
|
+
// related modules
|
|
4
|
+
import build from './module/build'
|
|
5
|
+
import bindEvents from './module/events'
|
|
6
|
+
import display from './mixin/display'
|
|
7
|
+
// ui element
|
|
8
|
+
import Text from './text'
|
|
9
|
+
import Button from './button'
|
|
10
|
+
|
|
11
|
+
class Snackbar extends EventEmitter {
|
|
12
|
+
static defaults = {
|
|
13
|
+
class: 'snackbar',
|
|
14
|
+
transition: 225,
|
|
15
|
+
duration: 4000,
|
|
16
|
+
close: false,
|
|
17
|
+
layout: [
|
|
18
|
+
[Text, 'text', { tag: 'span', class: 'text' }],
|
|
19
|
+
[Button, 'action', { class: 'action', type: 'link' }],
|
|
20
|
+
[Button, 'close', { class: 'close', type: 'action' }]
|
|
21
|
+
],
|
|
22
|
+
events: [
|
|
23
|
+
['ui.action.click', 'action'],
|
|
24
|
+
['ui.close.click', 'destroy']
|
|
25
|
+
]
|
|
26
|
+
};
|
|
17
27
|
|
|
18
|
-
class Snackbar {
|
|
19
|
-
/**
|
|
20
|
-
* Constructor
|
|
21
|
-
* @param {Object} options - Component options
|
|
22
|
-
* @return {Object} Class instance
|
|
23
|
-
*/
|
|
24
28
|
constructor (options) {
|
|
25
|
-
|
|
29
|
+
super()
|
|
26
30
|
|
|
27
|
-
this.init()
|
|
28
|
-
this.build()
|
|
31
|
+
this.init(options)
|
|
32
|
+
this.build(this.constructor)
|
|
33
|
+
this.render()
|
|
34
|
+
this.bindEvents()
|
|
29
35
|
this.show()
|
|
36
|
+
|
|
37
|
+
if (this.options.duration)
|
|
38
|
+
setTimeout(()=>{
|
|
39
|
+
this.destroy()
|
|
40
|
+
}, this.options.duration)
|
|
30
41
|
}
|
|
31
42
|
|
|
32
|
-
init
|
|
33
|
-
Object.assign(
|
|
43
|
+
init(options) {
|
|
44
|
+
this.options = Object.assign({}, Snackbar.defaults, options || {})
|
|
45
|
+
Object.assign(this, build, bindEvents, display)
|
|
46
|
+
|
|
47
|
+
this.buildSnackbarContainer(this.options.container)
|
|
34
48
|
}
|
|
35
49
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
build () {
|
|
41
|
-
var tag = this.options.tag || 'div'
|
|
50
|
+
buildSnackbarContainer (container = document.body) {
|
|
51
|
+
// console.log('buildSnackbarContainer', container)
|
|
52
|
+
|
|
53
|
+
let snackbarContainer = container.querySelector('.snackbars')
|
|
42
54
|
|
|
43
|
-
|
|
44
|
-
classify(this.element, this.options)
|
|
55
|
+
// console.log('snackbarContainer', snackbarContainer)
|
|
45
56
|
|
|
46
|
-
|
|
57
|
+
if (!snackbarContainer) {
|
|
58
|
+
this.options.container = document.createElement('div')
|
|
59
|
+
this.options.container.classList.add('snackbars')
|
|
60
|
+
container.appendChild(this.options.container)
|
|
61
|
+
} else {
|
|
62
|
+
this.options.container = snackbarContainer
|
|
63
|
+
}
|
|
47
64
|
}
|
|
48
65
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this.element.classList.add('show')
|
|
56
|
-
}, 10)
|
|
57
|
-
|
|
58
|
-
if (this.options.delay) {
|
|
59
|
-
setTimeout(() => {
|
|
60
|
-
this.hide()
|
|
61
|
-
}, this.options.delay)
|
|
66
|
+
render () {
|
|
67
|
+
this.ui.text.set(this.options.text)
|
|
68
|
+
|
|
69
|
+
if (this.options.action) {
|
|
70
|
+
this.ui.action.set(this.options.action)
|
|
71
|
+
this.ui.action.element.classList.add('show')
|
|
62
72
|
}
|
|
73
|
+
|
|
74
|
+
if (this.options.close) this.ui.close.element.classList.add('show')
|
|
75
|
+
|
|
76
|
+
return this
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
action () {
|
|
80
|
+
// console.log('action')
|
|
81
|
+
this.emit('action')
|
|
82
|
+
this.destroy()
|
|
63
83
|
}
|
|
64
84
|
|
|
65
|
-
|
|
66
|
-
|
|
85
|
+
close() {
|
|
86
|
+
// console.log('close')
|
|
87
|
+
this.destroy()
|
|
67
88
|
}
|
|
68
89
|
}
|
|
69
90
|
|
package/src/switch.js
CHANGED
|
@@ -1,106 +1,125 @@
|
|
|
1
|
-
|
|
1
|
+
import EventEmitter from './mixin/emitter'
|
|
2
2
|
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import emitter from './module/emitter'
|
|
7
|
-
import insert from './mixin/insert'
|
|
3
|
+
// module
|
|
4
|
+
import build from './module/build'
|
|
5
|
+
import dataset from './module/dataset'
|
|
8
6
|
import attach from './module/attach'
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
7
|
+
import attributes from './module/attributes'
|
|
8
|
+
|
|
9
|
+
// ui
|
|
10
|
+
import Layout from './layout'
|
|
11
|
+
import Element from './element'
|
|
12
|
+
|
|
13
|
+
class Switch extends EventEmitter {
|
|
14
|
+
static defaults = {
|
|
15
|
+
class: 'switch',
|
|
16
|
+
attributes: ['type', 'name', 'required', 'checked'],
|
|
17
|
+
layout: [
|
|
18
|
+
[Element, 'input', { class: 'input', type: 'checkbox' }],
|
|
19
|
+
[Element, 'control', { class: 'control' },
|
|
20
|
+
[Element, 'track', { class: 'track' },
|
|
21
|
+
[Element, 'knob', { class: 'knob' }]
|
|
22
|
+
]
|
|
25
23
|
]
|
|
26
24
|
],
|
|
27
|
-
[
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// ['element.input.keydown', 'keydown']
|
|
37
|
-
]
|
|
38
|
-
}
|
|
25
|
+
events: [
|
|
26
|
+
['ui.control.click', 'toggle'],
|
|
27
|
+
// ['ui.label.click', 'toggle'],
|
|
28
|
+
// for accessibility purpose
|
|
29
|
+
['ui.input.click', 'toggle'],
|
|
30
|
+
['ui.input.focus', 'focus'],
|
|
31
|
+
['ui.input.blur', 'blur']
|
|
32
|
+
]
|
|
33
|
+
}
|
|
39
34
|
|
|
40
|
-
/**
|
|
41
|
-
* Switch class
|
|
42
|
-
* @class
|
|
43
|
-
* @extends Control
|
|
44
|
-
*/
|
|
45
|
-
class Switch {
|
|
46
|
-
/**
|
|
47
|
-
* Constructor
|
|
48
|
-
* @param {Object} options
|
|
49
|
-
- Component options
|
|
50
|
-
* @return {Object} Class instance
|
|
51
|
-
*/
|
|
52
35
|
constructor (options) {
|
|
36
|
+
super()
|
|
37
|
+
|
|
53
38
|
this.init(options)
|
|
54
39
|
this.build()
|
|
40
|
+
this.setup()
|
|
55
41
|
this.attach()
|
|
56
|
-
|
|
57
|
-
return this
|
|
58
42
|
}
|
|
59
43
|
|
|
60
|
-
/**
|
|
61
|
-
* Constructor
|
|
62
|
-
* @param {Object} options The class options
|
|
63
|
-
* @return {Object} This class instance
|
|
64
|
-
*/
|
|
65
44
|
init (options) {
|
|
66
|
-
this.options = Object.assign({}, defaults, options || {})
|
|
67
|
-
Object.assign(this,
|
|
45
|
+
this.options = Object.assign({}, Switch.defaults, options || {})
|
|
46
|
+
Object.assign(this, build, attach, dataset)
|
|
68
47
|
|
|
69
48
|
this.value = this.options.value
|
|
70
|
-
|
|
71
|
-
return this
|
|
72
49
|
}
|
|
73
50
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
* @return {Object} The class instance
|
|
77
|
-
*/
|
|
78
|
-
build () {
|
|
79
|
-
this.element = build(this.options.build)
|
|
80
|
-
this.element = this.element.root
|
|
51
|
+
setup () {
|
|
52
|
+
this.styleAttributes()
|
|
81
53
|
|
|
82
|
-
|
|
54
|
+
this.buildIcon()
|
|
55
|
+
this.buildLabel()
|
|
83
56
|
|
|
84
|
-
if (this.options.
|
|
85
|
-
this.
|
|
57
|
+
if (this.options.data) {
|
|
58
|
+
dataset(this.root, this.options.data)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// console.log('attribute', this.ui.input, this.options)
|
|
62
|
+
attributes(this.ui.input, this.options)
|
|
63
|
+
|
|
64
|
+
if (this.options.checked) {
|
|
65
|
+
this.check(true)
|
|
86
66
|
}
|
|
87
67
|
|
|
88
68
|
if (this.value) {
|
|
89
69
|
this.element.input.setAttribute('checked', 'checked')
|
|
90
70
|
}
|
|
91
71
|
|
|
92
|
-
|
|
72
|
+
if (this.options.tooltip) {
|
|
73
|
+
this.element.setAttribute('data-tooltip', this.options.tooltip)
|
|
74
|
+
}
|
|
93
75
|
|
|
94
|
-
|
|
76
|
+
this.ui.input.setAttribute('aria-label', this.options.name)
|
|
95
77
|
|
|
96
|
-
this.
|
|
97
|
-
|
|
98
|
-
if (this.options.checked) {
|
|
99
|
-
this.check(true)
|
|
78
|
+
if (this.options.case) {
|
|
79
|
+
this.element.classList.add(this.options.case + '-case')
|
|
100
80
|
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
buildLabel () {
|
|
84
|
+
// console.log('buildLabel', this.options.label)
|
|
85
|
+
if (!this.options.label) return
|
|
101
86
|
|
|
102
|
-
|
|
103
|
-
|
|
87
|
+
this.ui.label = document.createElement('label')
|
|
88
|
+
this.ui.label.classList.add('label')
|
|
89
|
+
this.ui.label.innerHTML = this.options.label
|
|
90
|
+
|
|
91
|
+
if (this.options.name) {
|
|
92
|
+
this.ui.label.setAttribute('for', this.options.name)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
this.element.insertBefore(this.ui.label, this.ui.input)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
buildIcon () {
|
|
99
|
+
if (!this.options.icon) return
|
|
100
|
+
|
|
101
|
+
this.ui.icon = document.createElement('i')
|
|
102
|
+
this.ui.icon.classList.add('icon')
|
|
103
|
+
this.ui.icon.innerHTML = this.options.icon
|
|
104
|
+
|
|
105
|
+
this.element.insertBefore(this.ui.icon, this.ui.input)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
styleAttributes () {
|
|
109
|
+
if (this.options.style) {
|
|
110
|
+
this.element.classList.add('style-' + this.options.style)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (this.options.size) {
|
|
114
|
+
this.element.classList.add(this.options.size + '-size')
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (this.options.color) {
|
|
118
|
+
this.element.classList.add('color-' + this.options.color)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (this.options.bold) {
|
|
122
|
+
this.element.classList.add('bold')
|
|
104
123
|
}
|
|
105
124
|
}
|
|
106
125
|
|
|
@@ -115,6 +134,9 @@ class Switch {
|
|
|
115
134
|
case 'value':
|
|
116
135
|
this.setValue(value, silent)
|
|
117
136
|
break
|
|
137
|
+
case 'text':
|
|
138
|
+
this.setValue(value)
|
|
139
|
+
break
|
|
118
140
|
case 'disabled':
|
|
119
141
|
if (value === true) {
|
|
120
142
|
this.disable()
|
|
@@ -129,31 +151,29 @@ class Switch {
|
|
|
129
151
|
return this
|
|
130
152
|
}
|
|
131
153
|
|
|
154
|
+
setLabel (value) {
|
|
155
|
+
// console.log('setLabel', value)
|
|
156
|
+
if (this.ui.label) {
|
|
157
|
+
this.ui.label.innerHTML = value
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
setText (value) {
|
|
162
|
+
this.setLabel(value)
|
|
163
|
+
}
|
|
164
|
+
|
|
132
165
|
get () {
|
|
133
166
|
return this.value
|
|
134
167
|
}
|
|
135
168
|
|
|
136
|
-
/**
|
|
137
|
-
* set switch value
|
|
138
|
-
* @param {boolean} value [description]
|
|
139
|
-
*/
|
|
140
169
|
getValue () {
|
|
141
170
|
return this.value
|
|
142
171
|
}
|
|
143
172
|
|
|
144
|
-
/**
|
|
145
|
-
* set switch value
|
|
146
|
-
* @param {boolean} value [description]
|
|
147
|
-
*/
|
|
148
173
|
setValue (value, silent) {
|
|
149
|
-
// console.log('setValue', value)
|
|
150
174
|
this.check(value, silent)
|
|
151
175
|
}
|
|
152
176
|
|
|
153
|
-
/**
|
|
154
|
-
* [toggle description]
|
|
155
|
-
* @return {Object} The class instance
|
|
156
|
-
*/
|
|
157
177
|
toggle () {
|
|
158
178
|
if (this.disabled) return
|
|
159
179
|
|
|
@@ -168,15 +188,11 @@ class Switch {
|
|
|
168
188
|
return this
|
|
169
189
|
}
|
|
170
190
|
|
|
171
|
-
/**
|
|
172
|
-
* Set checkbox value
|
|
173
|
-
* @param {boolean} value [description]
|
|
174
|
-
*/
|
|
175
191
|
check (checked, silent) {
|
|
176
192
|
// console.log('check', checked, silent)
|
|
177
193
|
if (checked === true) {
|
|
178
194
|
this.element.classList.add('is-checked')
|
|
179
|
-
this.
|
|
195
|
+
this.ui.input.checked = true
|
|
180
196
|
this.checked = true
|
|
181
197
|
this.value = true
|
|
182
198
|
if (!silent) {
|
|
@@ -184,7 +200,7 @@ class Switch {
|
|
|
184
200
|
}
|
|
185
201
|
} else {
|
|
186
202
|
this.element.classList.remove('is-checked')
|
|
187
|
-
this.
|
|
203
|
+
this.ui.input.checked = false
|
|
188
204
|
this.checked = false
|
|
189
205
|
this.value = false
|
|
190
206
|
if (!silent) {
|
|
@@ -194,22 +210,14 @@ class Switch {
|
|
|
194
210
|
return this
|
|
195
211
|
}
|
|
196
212
|
|
|
197
|
-
/**
|
|
198
|
-
* [_onInputFocus description]
|
|
199
|
-
* @return {?} [description]
|
|
200
|
-
*/
|
|
201
213
|
focus () {
|
|
202
214
|
if (this.disabled === true) return this
|
|
203
215
|
|
|
204
216
|
this.element.classList.add('is-focused')
|
|
205
|
-
if (this.
|
|
217
|
+
if (this.ui.input !== document.activeElement) { this.ui.input.focus() }
|
|
206
218
|
return this
|
|
207
219
|
}
|
|
208
220
|
|
|
209
|
-
/**
|
|
210
|
-
* [_onInputBlur description]
|
|
211
|
-
* @return {?} [description]
|
|
212
|
-
*/
|
|
213
221
|
blur () {
|
|
214
222
|
this.element.classList.remove('is-focused')
|
|
215
223
|
return this
|
|
@@ -1,32 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Constructor
|
|
15
|
-
* @param {Object} options - Component options
|
|
16
|
-
* @return {Object} Class instance
|
|
17
|
-
*/
|
|
1
|
+
import EventEmitter from './mixin/emitter'
|
|
2
|
+
|
|
3
|
+
class Switcher extends EventEmitter{
|
|
4
|
+
static defaults = {
|
|
5
|
+
class: 'switcher',
|
|
6
|
+
tag: 'div',
|
|
7
|
+
list: [],
|
|
8
|
+
first: false,
|
|
9
|
+
mode: 'unique',
|
|
10
|
+
allowEmpty: false
|
|
11
|
+
}
|
|
12
|
+
|
|
18
13
|
constructor (options) {
|
|
19
|
-
|
|
20
|
-
Object.assign(this, emitter)
|
|
14
|
+
super()
|
|
21
15
|
|
|
16
|
+
this.init(options)
|
|
22
17
|
this.build()
|
|
23
18
|
this.attach()
|
|
24
19
|
|
|
25
20
|
if (this.options.default) {
|
|
26
21
|
this.selectByName(this.options.default, true)
|
|
27
22
|
}
|
|
23
|
+
}
|
|
28
24
|
|
|
29
|
-
|
|
25
|
+
init(options) {
|
|
26
|
+
this.options = Object.assign({}, Switcher.defaults, options || {})
|
|
30
27
|
}
|
|
31
28
|
|
|
32
29
|
build () {
|
package/src/text.js
CHANGED
|
@@ -1,96 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
import build from './module/build'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
prefix: 'material',
|
|
8
|
-
class: 'text',
|
|
9
|
-
type: 'default',
|
|
10
|
-
types: {
|
|
11
|
-
default: 'span',
|
|
12
|
-
display4: 'h1',
|
|
13
|
-
display3: 'h1',
|
|
14
|
-
display2: 'h1',
|
|
15
|
-
display1: 'h1',
|
|
16
|
-
headline: 'h1',
|
|
17
|
-
title: 'h2',
|
|
18
|
-
subheading2: 'h3',
|
|
19
|
-
subheading1: 'h4',
|
|
20
|
-
body: 'p',
|
|
21
|
-
body2: 'aside',
|
|
22
|
-
caption: 'span'
|
|
3
|
+
class Text {
|
|
4
|
+
static defaults = {
|
|
5
|
+
class: 'text',
|
|
6
|
+
tag: 'span'
|
|
23
7
|
}
|
|
24
|
-
}
|
|
25
8
|
|
|
26
|
-
/**
|
|
27
|
-
* this class creates a text component
|
|
28
|
-
*
|
|
29
|
-
* @since 0.0.6
|
|
30
|
-
* @category Element
|
|
31
|
-
* @param {HTMLElement} element Related element
|
|
32
|
-
* @param {String} className the className to add
|
|
33
|
-
* grouped values.
|
|
34
|
-
* @returns {HTMLElement} The modified element
|
|
35
|
-
* @example
|
|
36
|
-
*
|
|
37
|
-
* var text = new Text({
|
|
38
|
-
* text: 'hello',
|
|
39
|
-
* type: 'title'
|
|
40
|
-
* }).insert(document.body);
|
|
41
|
-
*
|
|
42
|
-
* // => Hello
|
|
43
|
-
*/
|
|
44
|
-
class Text {
|
|
45
|
-
/**
|
|
46
|
-
* init
|
|
47
|
-
* @return {Object} The class options
|
|
48
|
-
*/
|
|
49
9
|
constructor (options) {
|
|
50
10
|
this.init(options)
|
|
51
11
|
this.build()
|
|
52
|
-
|
|
53
|
-
return this
|
|
12
|
+
this.setup()
|
|
54
13
|
}
|
|
55
14
|
|
|
56
15
|
init (options) {
|
|
57
|
-
this.options = Object.assign({}, defaults, options || {})
|
|
58
|
-
|
|
59
|
-
Object.assign(this, insert)
|
|
16
|
+
this.options = Object.assign({}, Text.defaults, options || {})
|
|
17
|
+
Object.assign(this, build)
|
|
60
18
|
}
|
|
61
19
|
|
|
62
|
-
|
|
63
|
-
* Build function for item
|
|
64
|
-
* @return {Object} This class instance
|
|
65
|
-
*/
|
|
66
|
-
build () {
|
|
67
|
-
this.options.tag = this.options.types[this.options.type]
|
|
68
|
-
|
|
69
|
-
this.element = create(this.options)
|
|
70
|
-
|
|
20
|
+
setup () {
|
|
71
21
|
if (this.options.text) {
|
|
72
22
|
this.set(this.options.text)
|
|
73
23
|
}
|
|
74
|
-
|
|
75
|
-
if (this.options.container) {
|
|
76
|
-
this.insert(this.options.container)
|
|
77
|
-
}
|
|
78
|
-
return this
|
|
79
24
|
}
|
|
80
25
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
this.element.
|
|
26
|
+
set (text) {
|
|
27
|
+
// console.log('set', text)
|
|
28
|
+
if (text === undefined) return
|
|
29
|
+
|
|
30
|
+
var label = this.options.label || ''
|
|
31
|
+
|
|
32
|
+
if (this.options.textFirst) {
|
|
33
|
+
this.element.innerHTML = text + label
|
|
89
34
|
} else {
|
|
90
|
-
this.element.
|
|
35
|
+
this.element.innerHTML = label + text
|
|
91
36
|
}
|
|
92
37
|
|
|
93
|
-
|
|
38
|
+
if (this.options.spaceAfter) {
|
|
39
|
+
this.element.innerHTML = this.element.innerHTML + ' '
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
setText (text) {
|
|
44
|
+
this.element.innerHTML = text
|
|
94
45
|
}
|
|
95
46
|
}
|
|
96
47
|
|