material 0.4.3 → 0.5.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/dist/tracks.svg +10 -0
- package/package.json +4 -4
- package/src/appbar.js +1 -2
- package/src/control/button.js +127 -44
- package/src/control/button.new.js +190 -0
- package/src/control/dialog.js +174 -0
- package/src/control/{upload.js → file.js} +33 -8
- package/src/control/link.js +61 -0
- package/src/control/list.js +77 -0
- package/src/control/loading.js +128 -0
- package/src/control/module/addclass.js +16 -0
- package/src/control/module/attributes.js +3 -1
- package/src/control/search.js +98 -0
- package/src/control/select.js +80 -22
- package/src/control/selecter.js +246 -0
- package/src/control/switch.js +272 -0
- package/src/control/switcher.js +245 -0
- package/src/control/text.js +18 -3
- package/src/control/textfield.js +89 -15
- package/src/field/image.js +9 -3
- package/src/form/build.js +28 -4
- package/src/form/cancel.js +7 -3
- package/src/form/controller.js +90 -0
- package/src/form/create.js +11 -7
- package/src/form/data.js +82 -0
- package/src/form/delete.js +2 -1
- package/src/form/fetch.js +5 -3
- package/src/form/render.js +11 -9
- package/src/form/set.js +27 -12
- package/src/form/submit.js +11 -37
- package/src/form/update.js +35 -16
- package/src/layout.js +25 -21
- package/src/list/add.js +34 -0
- package/src/list/build.js +96 -12
- package/src/list/click.js +10 -5
- package/src/list/collection.js +187 -0
- package/src/list/create.js +21 -11
- package/src/list/display.js +78 -0
- package/src/list/empty.js +4 -1
- package/src/list/filter.js +114 -0
- package/src/list/load.js +2 -2
- package/src/list/remove.js +17 -4
- package/src/list/render.js +32 -9
- package/src/list/request.js +182 -0
- package/src/list/search.js +118 -35
- package/src/list/select.js +151 -30
- package/src/list/status.js +10 -3
- package/src/list/update.js +49 -8
- package/src/list/virtual.js +195 -127
- package/src/map/build.js +103 -0
- package/src/map/countries.js +114 -0
- package/src/map/display.js +135 -0
- package/src/map/focus.js +39 -0
- package/src/map/init.js +24 -0
- package/src/map/label.js +0 -0
- package/src/map/mode.js +44 -0
- package/src/map/mouse.js +65 -0
- package/src/map/select.js +68 -0
- package/src/map/set.js +71 -0
- package/src/map/viewport.js +46 -0
- package/src/map.js +71 -0
- package/src/module/attach.js +9 -2
- package/src/module/mediator.js +56 -0
- package/src/module/object.js +17 -1
- package/src/module/observer.js +1 -1
- package/src/module/passive.js +17 -0
- package/src/module/remove.js +74 -0
- package/src/module/scrollbar.js +48 -0
- package/src/module/smoothscroll.js +20 -0
- package/src/module/viewport.js +20 -0
- package/src/selector.js +239 -0
- package/src/skin/material/base/body.sass +3 -0
- package/src/skin/material/button/file.sass +1 -1
- package/src/skin/material/container/container.sass +1 -1
- package/src/skin/material/container/dialog.sass +57 -1
- package/src/skin/material/container/drawer.sass +3 -3
- package/src/skin/material/control/button.sass +125 -0
- package/src/skin/material/control/dialog.sass +0 -0
- package/src/skin/material/control/progress.sass +136 -0
- package/src/skin/material/control/search.sass +40 -0
- package/src/skin/material/control/selecter.sass +131 -0
- package/src/skin/material/control/selector.sass +38 -0
- package/src/skin/material/control/slider.sass +2 -2
- package/src/skin/material/control/switch.sass +146 -3
- package/src/skin/material/control/switcher.sass +41 -0
- package/src/skin/material/control/textfield.sass +2 -1
- package/src/skin/material/icon/cancel.svg +1 -0
- package/src/skin/material/material.sass +3 -0
- package/src/skin/material/view/list.sass +81 -188
- package/src/skin/material/view/listview.sass +187 -96
- package/src/skin/material/view/tabview.sass +6 -4
- package/src/skin/material.bak/base/body.sass +52 -0
- package/src/skin/material.bak/base/elevation.sass +50 -0
- package/src/skin/material.bak/base/grid.sass +63 -0
- package/src/skin/material.bak/base/typo.sass +107 -0
- package/src/skin/material.bak/button/action.sass +89 -0
- package/src/skin/material.bak/button/button.sass +183 -0
- package/src/skin/material.bak/button/file.sass +24 -0
- package/src/skin/material.bak/button/floating.sass +113 -0
- package/src/skin/material.bak/button/raised.sass +101 -0
- package/src/skin/material.bak/button/stroked.sass +71 -0
- package/src/skin/material.bak/component/component.sass +7 -0
- package/src/skin/material.bak/component/divider.sass +17 -0
- package/src/skin/material.bak/component/image.sass +6 -0
- package/src/skin/material.bak/component/label.sass +2 -0
- package/src/skin/material.bak/component/progress.sass +138 -0
- package/src/skin/material.bak/component/subheader.sass +3 -0
- package/src/skin/material.bak/component/text.sass +85 -0
- package/src/skin/material.bak/container/appbar.sass +167 -0
- package/src/skin/material.bak/container/banner.sass +38 -0
- package/src/skin/material.bak/container/card.sass +18 -0
- package/src/skin/material.bak/container/container.sass +1 -0
- package/src/skin/material.bak/container/dialog.sass +184 -0
- package/src/skin/material.bak/container/drawer.sass +159 -0
- package/src/skin/material.bak/container/drawernew.sass +159 -0
- package/src/skin/material.bak/container/menu.sass +58 -0
- package/src/skin/material.bak/container/snackbar.sass +18 -0
- package/src/skin/material.bak/container/tabs.sass +75 -0
- package/src/skin/material.bak/container/toolbar.sass +161 -0
- package/src/skin/material.bak/control/button.sass +125 -0
- package/src/skin/material.bak/control/checkbox.sass +105 -0
- package/src/skin/material.bak/control/dialog.sass +0 -0
- package/src/skin/material.bak/control/search.sass +40 -0
- package/src/skin/material.bak/control/selecter.sass +128 -0
- package/src/skin/material.bak/control/slider.sass +181 -0
- package/src/skin/material.bak/control/switch.sass +284 -0
- package/src/skin/material.bak/control/switcher.sass +35 -0
- package/src/skin/material.bak/control/textfield.sass +126 -0
- package/src/skin/material.bak/control/tooltip.sass +36 -0
- package/src/skin/material.bak/icon/back.svg +5 -0
- package/src/skin/material.bak/icon/cancel.svg +1 -0
- package/src/skin/material.bak/icon/checkbox.svg +4 -0
- package/src/skin/material.bak/icon/forward.svg +5 -0
- package/src/skin/material.bak/icon/menu.svg +4 -0
- package/src/skin/material.bak/icon/pin.svg +4 -0
- package/src/skin/material.bak/layout/layout.sass +69 -0
- package/src/skin/material.bak/layout/resizer.sass +69 -0
- package/src/skin/material.bak/material.css +2042 -0
- package/src/skin/material.bak/material.css.map +7 -0
- package/src/skin/material.bak/material.sass +65 -0
- package/src/skin/material.bak/module/ripple.sass +9 -0
- package/src/skin/material.bak/theme/default.sass +50 -0
- package/src/skin/material.bak/theme/ocean.sass +29 -0
- package/src/skin/material.bak/theme/theme.sass +3 -0
- package/src/skin/material.bak/view/calendar.sass +193 -0
- package/src/skin/material.bak/view/form.sass +15 -0
- package/src/skin/material.bak/view/grid.sass +116 -0
- package/src/skin/material.bak/view/list.sass +89 -0
- package/src/skin/material.bak/view/listview.sass +195 -0
- package/src/skin/material.bak/view/map.sass +6 -0
- package/src/skin/material.bak/view/page.sass +4 -0
- package/src/skin/material.bak/view/tabview-bak.sass +40 -0
- package/src/skin/material.bak/view/tabview.sass +55 -0
- package/src/skin/material.bak/view/tree.sass +73 -0
- package/src/skin/material.bak/view/view.sass +7 -0
- package/src/switch.js +1 -1
- package/src/tabs/setup.js +0 -0
- package/src/tabview.js +64 -14
- package/src/tooltip.js +23 -5
- package/src/view/build.js +13 -1
- package/src/view/display.js +63 -2
- package/src/form/clean.js +0 -6
- package/src/form/controls.js +0 -56
- package/src/form/mode.js +0 -8
- package/src/form/setup.js +0 -5
- package/src/list/fetch.js +0 -66
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import emitter from '..//module/emitter'
|
|
2
|
+
import attach from '../module/attach'
|
|
3
|
+
import dataset from '../view/dataset'
|
|
4
|
+
import attributes from './module/attributes'
|
|
5
|
+
import addClass from './module/addclass'
|
|
6
|
+
|
|
7
|
+
// ui
|
|
8
|
+
import Layout from '../layout'
|
|
9
|
+
import Element from '../element'
|
|
10
|
+
import Button from './button'
|
|
11
|
+
|
|
12
|
+
const defaults = {
|
|
13
|
+
class: 'selecter',
|
|
14
|
+
first: null,
|
|
15
|
+
attributes: ['type', 'name', 'autocomplete', 'required'],
|
|
16
|
+
layout: [
|
|
17
|
+
[Element, 'label', { tag: 'label', class: 'label' }],
|
|
18
|
+
[Element, 'value', { tag: 'value', class: 'value' }],
|
|
19
|
+
[Element, 'input', { tag: 'input', type: 'text', class: 'input' }],
|
|
20
|
+
[Element, 'list', { class: 'list' },
|
|
21
|
+
[Element, 'head', { class: 'head' },
|
|
22
|
+
[Element, 'title', { class: 'title' }],
|
|
23
|
+
[Button, 'close', { class: 'close' }]
|
|
24
|
+
],
|
|
25
|
+
[Element, 'body', { class: 'body' }]
|
|
26
|
+
]
|
|
27
|
+
],
|
|
28
|
+
events: [
|
|
29
|
+
['ui.value.click', 'showList'],
|
|
30
|
+
['ui.list.click', 'select'],
|
|
31
|
+
['ui.close.click', 'hideList']
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
class Selecter {
|
|
36
|
+
/**
|
|
37
|
+
* Constructor
|
|
38
|
+
* @param {Object} options - Component options
|
|
39
|
+
* @return {Object} Class instance
|
|
40
|
+
*/
|
|
41
|
+
constructor (options) {
|
|
42
|
+
this.options = Object.assign({}, defaults, options || {})
|
|
43
|
+
Object.assign(this, emitter, attach, dataset)
|
|
44
|
+
|
|
45
|
+
this.build()
|
|
46
|
+
this.setup()
|
|
47
|
+
this.attach()
|
|
48
|
+
|
|
49
|
+
return this
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
setup () {
|
|
53
|
+
if (this.options.data) {
|
|
54
|
+
dataset(this.root, this.options.data)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// console.log('attribute', this.ui.input, this.options)
|
|
58
|
+
attributes(this.ui.input, this.options)
|
|
59
|
+
|
|
60
|
+
if (this.value) {
|
|
61
|
+
this.element.input.setAttribute('checked', 'checked')
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (this.options.tooltip) {
|
|
65
|
+
this.root.setAttribute('data-tooltip', this.options.tooltip)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (this.options.label) {
|
|
69
|
+
this.setLabel(this.options.label)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
this.ui.input.setAttribute('aria-label', this.options.name)
|
|
73
|
+
|
|
74
|
+
if (this.options.case) {
|
|
75
|
+
this.root.classList.add(this.options.case + '-case')
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* build method
|
|
80
|
+
* @return {Object} The class instance
|
|
81
|
+
*/
|
|
82
|
+
build () {
|
|
83
|
+
var tag = this.options.tag || 'span'
|
|
84
|
+
this.root = document.createElement(tag)
|
|
85
|
+
this.root.classList.add('selecter')
|
|
86
|
+
|
|
87
|
+
if (this.options.class !== 'selecter') {
|
|
88
|
+
addClass(this.root, this.options.class)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
this.layout = new Layout(this.options.layout, this.root)
|
|
92
|
+
this.ui = this.layout.component
|
|
93
|
+
|
|
94
|
+
// console.log('ui', this.ui)
|
|
95
|
+
|
|
96
|
+
this.styleAttributes()
|
|
97
|
+
|
|
98
|
+
this.buildIcon(this.options.icon)
|
|
99
|
+
this.setList(this.options.list)
|
|
100
|
+
|
|
101
|
+
if (this.options.container) {
|
|
102
|
+
this.options.container.appendChild(this.root)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
buildIcon (icon) {
|
|
107
|
+
if (!icon) return
|
|
108
|
+
|
|
109
|
+
this.ui.icon = document.createElement('i')
|
|
110
|
+
this.ui.icon.classList.add('icon')
|
|
111
|
+
this.ui.icon.innerHTML = this.options.icon
|
|
112
|
+
|
|
113
|
+
this.root.insertBefore(this.ui.icon, this.ui.input)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
buildInput () {
|
|
117
|
+
this.input = document.createElement('select')
|
|
118
|
+
this.input.classList.add('input')
|
|
119
|
+
this.root.appendChild(this.input)
|
|
120
|
+
|
|
121
|
+
this.input.addEventListener('change', () => {
|
|
122
|
+
// console.log('change', this.input[this.input.selectedIndex].value)
|
|
123
|
+
this.emit('change', this.input[this.input.selectedIndex].value)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
if (this.options.data) {
|
|
127
|
+
dataset(this.data, this.options.data)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
attributes(this.input, this.options)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
setList (list) {
|
|
134
|
+
// console.log('setList', list)
|
|
135
|
+
if (!list) return
|
|
136
|
+
|
|
137
|
+
this.values = {}
|
|
138
|
+
|
|
139
|
+
// console.log('list', list)
|
|
140
|
+
|
|
141
|
+
for (var i = 0; i < list.length; i++) {
|
|
142
|
+
// if (list.indexOf(list[i][0]) > -1) {
|
|
143
|
+
var item = document.createElement('div')
|
|
144
|
+
item.classList.add('item')
|
|
145
|
+
item.innerHTML = list[i][1]
|
|
146
|
+
item.dataset.value = list[i][0]
|
|
147
|
+
|
|
148
|
+
this.values[list[i][0]] = list[i][1]
|
|
149
|
+
|
|
150
|
+
this.ui.body.appendChild(item)
|
|
151
|
+
// }
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
styleAttributes () {
|
|
156
|
+
if (this.options.style) {
|
|
157
|
+
this.root.classList.add('style-' + this.options.style)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (this.options.size) {
|
|
161
|
+
this.root.classList.add(this.options.size + '-size')
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (this.options.color) {
|
|
165
|
+
this.root.classList.add('color-' + this.options.color)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (this.options.bold) {
|
|
169
|
+
this.root.classList.add('bold')
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
showList () {
|
|
173
|
+
// console.log('showList')
|
|
174
|
+
|
|
175
|
+
this.ui.list.classList.add('show')
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
hideList () {
|
|
179
|
+
// console.log('hideList')
|
|
180
|
+
|
|
181
|
+
this.ui.list.classList.remove('show')
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
select (e) {
|
|
185
|
+
// console.log('select', e.target)
|
|
186
|
+
|
|
187
|
+
e.preventDefault()
|
|
188
|
+
|
|
189
|
+
if (e && e.target && e.target.dataset.value) {
|
|
190
|
+
if (this.selected) {
|
|
191
|
+
this.selected.classList.remove('selected')
|
|
192
|
+
}
|
|
193
|
+
this.selected = e.target
|
|
194
|
+
this.selected.classList.add('selected')
|
|
195
|
+
|
|
196
|
+
this.value = e.target.dataset.value
|
|
197
|
+
// console.log('value', e.target.dataset.value)
|
|
198
|
+
this.ui.value.innerHTML = this.values[this.value]
|
|
199
|
+
this.emit('change', this.value)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (this.options.type !== 'listonly') {
|
|
203
|
+
this.hideList()
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
addOption (name, value) {
|
|
208
|
+
this.input.options[this.input.options.length] = new Option(name, value)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
set (value) {
|
|
212
|
+
// console.log('set', value, this.values)
|
|
213
|
+
|
|
214
|
+
this.ui.input.value = value
|
|
215
|
+
if (this.values) {
|
|
216
|
+
this.ui.value.innerHTML = this.values[value]
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
this.selected = this.root.querySelector('[data-value=' + value + ']')
|
|
220
|
+
|
|
221
|
+
// console.log('item', this.selected)
|
|
222
|
+
if (this.selected) {
|
|
223
|
+
this.selected.classList.add('selected')
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return this
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
setLabel (value) {
|
|
230
|
+
// console.log('setLabel', value)
|
|
231
|
+
if (this.ui.label) {
|
|
232
|
+
this.ui.label.innerHTML = value
|
|
233
|
+
this.ui.title.innerHTML = value
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
setText (value) {
|
|
238
|
+
this.setLabel(value)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
get () {
|
|
242
|
+
return this.value
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export default Selecter
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
// module
|
|
2
|
+
import dataset from '../view/dataset'
|
|
3
|
+
import attach from '../module/attach'
|
|
4
|
+
import emitter from '../module/emitter'
|
|
5
|
+
import attributes from './module/attributes'
|
|
6
|
+
import addClass from './module/addclass'
|
|
7
|
+
|
|
8
|
+
// ui
|
|
9
|
+
import Layout from '../layout'
|
|
10
|
+
import Element from '../element'
|
|
11
|
+
|
|
12
|
+
let defaults = {
|
|
13
|
+
class: 'switch',
|
|
14
|
+
attributes: ['type', 'name', 'required', 'checked'],
|
|
15
|
+
layout: [
|
|
16
|
+
[Element, 'input', { class: 'input', type: 'checkbox' }],
|
|
17
|
+
[Element, 'control', { class: 'control' },
|
|
18
|
+
[Element, 'track', { class: 'track' },
|
|
19
|
+
[Element, 'knob', { class: 'knob' }]
|
|
20
|
+
]
|
|
21
|
+
]
|
|
22
|
+
],
|
|
23
|
+
events: [
|
|
24
|
+
['ui.control.click', 'toggle'],
|
|
25
|
+
// ['ui.label.click', 'toggle'],
|
|
26
|
+
// for accessibility purpose
|
|
27
|
+
['ui.input.click', 'toggle'],
|
|
28
|
+
['ui.input.focus', 'focus'],
|
|
29
|
+
['ui.input.blur', 'blur']
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class Switch {
|
|
34
|
+
constructor (options) {
|
|
35
|
+
this.options = Object.assign({}, defaults, options || {})
|
|
36
|
+
Object.assign(this, emitter, attach, dataset)
|
|
37
|
+
|
|
38
|
+
this.value = this.options.value
|
|
39
|
+
|
|
40
|
+
this.build()
|
|
41
|
+
this.setup()
|
|
42
|
+
this.attach()
|
|
43
|
+
|
|
44
|
+
return this
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* build method
|
|
49
|
+
* @return {Object} The class instance
|
|
50
|
+
*/
|
|
51
|
+
build () {
|
|
52
|
+
var tag = this.options.tag || 'span'
|
|
53
|
+
this.root = document.createElement(tag)
|
|
54
|
+
this.root.classList.add('switch')
|
|
55
|
+
|
|
56
|
+
if (this.options.class !== 'switch') {
|
|
57
|
+
addClass(this.root, this.options.class)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this.layout = new Layout(this.options.layout, this.root)
|
|
61
|
+
this.ui = this.layout.component
|
|
62
|
+
|
|
63
|
+
// console.log('ui', this.ui)
|
|
64
|
+
|
|
65
|
+
this.styleAttributes()
|
|
66
|
+
|
|
67
|
+
this.buildIcon()
|
|
68
|
+
this.buildLabel()
|
|
69
|
+
|
|
70
|
+
if (this.options.container) {
|
|
71
|
+
this.options.container.appendChild(this.root)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
setup () {
|
|
76
|
+
if (this.options.data) {
|
|
77
|
+
dataset(this.root, this.options.data)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// console.log('attribute', this.ui.input, this.options)
|
|
81
|
+
attributes(this.ui.input, this.options)
|
|
82
|
+
|
|
83
|
+
if (this.options.checked) {
|
|
84
|
+
this.check(true)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (this.value) {
|
|
88
|
+
this.element.input.setAttribute('checked', 'checked')
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (this.options.tooltip) {
|
|
92
|
+
this.root.setAttribute('data-tooltip', this.options.tooltip)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
this.ui.input.setAttribute('aria-label', this.options.name)
|
|
96
|
+
|
|
97
|
+
if (this.options.case) {
|
|
98
|
+
this.root.classList.add(this.options.case + '-case')
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
buildLabel () {
|
|
103
|
+
// console.log('buildLabel', this.options.label)
|
|
104
|
+
if (!this.options.label) return
|
|
105
|
+
|
|
106
|
+
this.ui.label = document.createElement('label')
|
|
107
|
+
this.ui.label.classList.add('label')
|
|
108
|
+
this.ui.label.innerHTML = this.options.label
|
|
109
|
+
|
|
110
|
+
if (this.options.name) {
|
|
111
|
+
this.ui.label.setAttribute('for', this.options.name)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
this.root.insertBefore(this.ui.label, this.ui.input)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
buildIcon () {
|
|
118
|
+
if (!this.options.icon) return
|
|
119
|
+
|
|
120
|
+
this.ui.icon = document.createElement('i')
|
|
121
|
+
this.ui.icon.classList.add('icon')
|
|
122
|
+
this.ui.icon.innerHTML = this.options.icon
|
|
123
|
+
|
|
124
|
+
this.root.insertBefore(this.ui.icon, this.ui.input)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
styleAttributes () {
|
|
128
|
+
if (this.options.style) {
|
|
129
|
+
this.root.classList.add('style-' + this.options.style)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (this.options.size) {
|
|
133
|
+
this.root.classList.add(this.options.size + '-size')
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (this.options.color) {
|
|
137
|
+
this.root.classList.add('color-' + this.options.color)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (this.options.bold) {
|
|
141
|
+
this.root.classList.add('bold')
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Setter
|
|
147
|
+
* @param {string} prop
|
|
148
|
+
* @param {string} value
|
|
149
|
+
* @return {Object} The class instance
|
|
150
|
+
*/
|
|
151
|
+
set (prop, value, silent) {
|
|
152
|
+
switch (prop) {
|
|
153
|
+
case 'value':
|
|
154
|
+
this.setValue(value, silent)
|
|
155
|
+
break
|
|
156
|
+
case 'text':
|
|
157
|
+
this.setValue(value)
|
|
158
|
+
break
|
|
159
|
+
case 'disabled':
|
|
160
|
+
if (value === true) {
|
|
161
|
+
this.disable()
|
|
162
|
+
} else if (value === false) {
|
|
163
|
+
this.enable()
|
|
164
|
+
}
|
|
165
|
+
break
|
|
166
|
+
default:
|
|
167
|
+
this.setValue(prop, value)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return this
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
setLabel (value) {
|
|
174
|
+
// console.log('setLabel', value)
|
|
175
|
+
if (this.ui.label) {
|
|
176
|
+
this.ui.label.innerHTML = value
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
setText (value) {
|
|
181
|
+
this.setLabel(value)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
get () {
|
|
185
|
+
return this.value
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* set switch value
|
|
190
|
+
* @param {boolean} value [description]
|
|
191
|
+
*/
|
|
192
|
+
getValue () {
|
|
193
|
+
return this.value
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* set switch value
|
|
198
|
+
* @param {boolean} value [description]
|
|
199
|
+
*/
|
|
200
|
+
setValue (value, silent) {
|
|
201
|
+
// console.log('setValue', value, typeof silent, silent)
|
|
202
|
+
this.check(value, silent)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* [toggle description]
|
|
207
|
+
* @return {Object} The class instance
|
|
208
|
+
*/
|
|
209
|
+
toggle () {
|
|
210
|
+
// console.log('toggle')
|
|
211
|
+
if (this.disabled) return
|
|
212
|
+
|
|
213
|
+
this.focus()
|
|
214
|
+
|
|
215
|
+
if (this.checked) {
|
|
216
|
+
this.check(false)
|
|
217
|
+
} else {
|
|
218
|
+
this.check(true)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return this
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Set checkbox value
|
|
226
|
+
* @param {boolean} value [description]
|
|
227
|
+
*/
|
|
228
|
+
check (checked, silent) {
|
|
229
|
+
// console.log('check', checked, silent)
|
|
230
|
+
if (checked === true) {
|
|
231
|
+
this.root.classList.add('is-checked')
|
|
232
|
+
this.ui.input.checked = true
|
|
233
|
+
this.checked = true
|
|
234
|
+
this.value = true
|
|
235
|
+
if (!silent) {
|
|
236
|
+
this.emit('change', this.checked)
|
|
237
|
+
}
|
|
238
|
+
} else {
|
|
239
|
+
this.root.classList.remove('is-checked')
|
|
240
|
+
this.ui.input.checked = false
|
|
241
|
+
this.checked = false
|
|
242
|
+
this.value = false
|
|
243
|
+
if (!silent) {
|
|
244
|
+
this.emit('change', this.checked)
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return this
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* [_onInputFocus description]
|
|
252
|
+
* @return {?} [description]
|
|
253
|
+
*/
|
|
254
|
+
focus () {
|
|
255
|
+
if (this.disabled === true) return this
|
|
256
|
+
|
|
257
|
+
this.root.classList.add('is-focused')
|
|
258
|
+
if (this.ui.input !== document.activeElement) { this.ui.input.focus() }
|
|
259
|
+
return this
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* [_onInputBlur description]
|
|
264
|
+
* @return {?} [description]
|
|
265
|
+
*/
|
|
266
|
+
blur () {
|
|
267
|
+
this.root.classList.remove('is-focused')
|
|
268
|
+
return this
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export default Switch
|