material 0.6.2 → 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 +61 -51
- 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 +160 -161
- package/src/calendar.js +8 -10
- package/src/card.js +4 -6
- package/src/checkbox.js +8 -10
- package/src/component.js +4 -6
- package/src/container.js +4 -6
- package/src/datehour.js +38 -0
- package/src/dialog.js +106 -153
- package/src/divider.js +4 -6
- package/src/drawer.js +11 -13
- package/src/field/email.js +5 -5
- package/src/field/image.js +4 -4
- package/src/{control/file.js → file.js} +18 -48
- package/src/form/build.js +7 -7
- package/src/form/verify.js +2 -2
- package/src/form.js +6 -8
- package/src/icon.js +8 -10
- package/src/image.js +39 -106
- package/src/item.js +7 -9
- package/src/layout.js +10 -10
- package/src/link.js +50 -0
- package/src/list/add.js +1 -1
- package/src/list/build.js +9 -9
- package/src/list/collection.js +1 -1
- package/src/list/display.js +10 -10
- package/src/list/filter.js +2 -2
- package/src/list/request.js +1 -1
- package/src/list/search.js +7 -7
- package/src/list.js +29 -217
- package/src/loading.js +73 -0
- package/src/map/build.js +6 -6
- package/src/map/display.js +8 -8
- package/src/menu.js +60 -116
- package/src/{component → mixin}/control.js +10 -10
- package/src/{component → mixin}/create.js +1 -1
- package/src/{module → mixin}/display.js +9 -22
- package/src/{component → mixin}/events.js +2 -2
- package/src/{component → mixin}/focus.js +2 -3
- package/src/{component → mixin}/insert.js +3 -25
- package/src/{control/module → module}/attributes.js +2 -2
- package/src/module/build.js +11 -7
- package/src/{component → module}/classify.js +0 -13
- package/src/module/dom.js +1 -57
- package/src/module/events.js +4 -2
- package/src/{component → module}/ripple.js +15 -42
- package/src/navigation.js +19 -0
- package/src/progress.js +7 -9
- package/src/search.js +71 -0
- package/src/select.js +58 -273
- package/src/{control/selecter.js → selecter.js} +20 -20
- package/src/selector.js +32 -32
- package/src/skin/material/component/navigation.sass +1 -0
- package/src/skin/material/control/button.sass +10 -0
- package/src/slider.js +32 -34
- package/src/snackbar.js +72 -51
- package/src/switch.js +115 -107
- package/src/{control/switcher.js → switcher.js} +33 -36
- package/src/tabs.js +8 -8
- package/src/tabview.js +8 -8
- package/src/text.js +25 -74
- package/src/textfield.js +97 -234
- package/src/toolbar.js +28 -28
- package/src/tooltip.js +11 -11
- package/src/tree.js +12 -16
- package/src/view/build.js +6 -6
- package/src/view/display.js +16 -16
- package/src/view.js +5 -5
- package/src/banner.js +0 -231
- package/src/component/click.js +0 -17
- package/src/control/button.js +0 -267
- 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/link.js +0 -69
- 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 -89
- package/src/control/switch.js +0 -272
- package/src/control/text.js +0 -70
- package/src/control/textfield.js +0 -177
- /package/src/{component → mixin}/controller.js +0 -0
- /package/src/{component → mixin}/emitter.js +0 -0
- /package/src/{component → mixin}/icon.js +0 -0
- /package/src/{component → mixin}/init.js +0 -0
- /package/src/{component → mixin}/label.js +0 -0
- /package/src/{component → mixin}/settings.js +0 -0
- /package/src/{control/module → module}/addclass.js +0 -0
- /package/src/{tabs/setup.js → module/last.js} +0 -0
package/src/list.js
CHANGED
|
@@ -1,255 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import Item from './item'
|
|
4
|
-
import Divider from './divider'
|
|
5
|
-
|
|
6
|
-
// import init from './component/init'
|
|
7
|
-
import emitter from './module/emitter'
|
|
8
|
-
import insert from './element/insert'
|
|
9
|
-
import css from './module/css'
|
|
10
|
-
import attach from './module/attach'
|
|
1
|
+
import addClass from './module/addclass'
|
|
11
2
|
|
|
12
3
|
const defaults = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
functions: ['render', 'select'],
|
|
17
|
-
target: 'LI',
|
|
18
|
-
events: [
|
|
19
|
-
['root.click', 'handleSelect']
|
|
20
|
-
]
|
|
4
|
+
className: 'text',
|
|
5
|
+
tag: 'span',
|
|
6
|
+
seprator: ' | '
|
|
21
7
|
}
|
|
22
8
|
|
|
23
|
-
/**
|
|
24
|
-
* List view class
|
|
25
|
-
* @class
|
|
26
|
-
* @param {Object} options Default options for view
|
|
27
|
-
* @extends {View}
|
|
28
|
-
* @since 0.0.4
|
|
29
|
-
* @author Jerome Vial
|
|
30
|
-
*
|
|
31
|
-
* @type {prime}
|
|
32
|
-
*/
|
|
33
9
|
class List {
|
|
34
|
-
/**
|
|
35
|
-
* init
|
|
36
|
-
* @return {Object} The class options
|
|
37
|
-
*/
|
|
38
10
|
constructor (options) {
|
|
39
11
|
this.options = Object.assign({}, defaults, options || {})
|
|
40
12
|
|
|
41
|
-
|
|
42
|
-
this.build(this.options)
|
|
43
|
-
this.attach(this.options.events)
|
|
44
|
-
|
|
45
|
-
return this
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* [_initView description]
|
|
50
|
-
* @return Class instance
|
|
51
|
-
*/
|
|
52
|
-
init () {
|
|
53
|
-
this.filters = []
|
|
54
|
-
this.data = []
|
|
55
|
-
this.items = []
|
|
56
|
-
|
|
57
|
-
// assign modules
|
|
58
|
-
Object.assign(this, emitter, attach)
|
|
13
|
+
// console.log('options', this.options)
|
|
59
14
|
|
|
60
|
-
|
|
61
|
-
this._initFunction(this.options.functions)
|
|
15
|
+
this.build()
|
|
62
16
|
|
|
63
17
|
return this
|
|
64
18
|
}
|
|
65
19
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
* @return {?} [description]
|
|
70
|
-
*/
|
|
71
|
-
_initFunction (functions) {
|
|
72
|
-
for (var i = 0; i < functions.length; i++) {
|
|
73
|
-
var name = functions[i]
|
|
74
|
-
if (this.options[name]) {
|
|
75
|
-
this[name] = this.options[name]
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
20
|
+
build () {
|
|
21
|
+
this.root = document.createElement(this.options.tag)
|
|
22
|
+
addClass(this.root, this.options.class)
|
|
79
23
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
* @param {Object} options this class options
|
|
83
|
-
* @return {Object} The class instance
|
|
84
|
-
*/
|
|
85
|
-
build (options) {
|
|
86
|
-
// define main tag
|
|
87
|
-
var tag = this.options.tag || 'ul'
|
|
88
|
-
|
|
89
|
-
this.root = document.createElement(tag)
|
|
90
|
-
css.add(this.root, 'material-' + this.options.class)
|
|
91
|
-
|
|
92
|
-
if (options.name) {
|
|
93
|
-
css.add(this.root, options.class + '-' + options.name)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (options.type) {
|
|
97
|
-
css.add(this.root, 'type-' + options.type)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (options.layout) {
|
|
101
|
-
css.add(this.root, 'layout-' + options.layout)
|
|
24
|
+
if (this.options.class !== 'text') {
|
|
25
|
+
this.root.classList.add('text')
|
|
102
26
|
}
|
|
103
27
|
|
|
104
28
|
if (this.options.list) {
|
|
105
|
-
this.set(
|
|
29
|
+
this.set(this.options.list)
|
|
106
30
|
}
|
|
107
31
|
|
|
108
32
|
if (this.options.container) {
|
|
109
|
-
|
|
33
|
+
this.options.container.appendChild(this.root)
|
|
110
34
|
}
|
|
111
35
|
|
|
112
|
-
// this.root.addEventListener("click", function(e) {
|
|
113
|
-
// // console.log("list", this, e);
|
|
114
|
-
// // e.target was the clicked element
|
|
115
|
-
// });
|
|
116
|
-
|
|
117
36
|
return this
|
|
118
37
|
}
|
|
119
38
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
* @param {?} e [description]
|
|
123
|
-
* @return {?} [description]
|
|
124
|
-
*/
|
|
125
|
-
handleSelect (e) {
|
|
126
|
-
// console.log('handleSelect-', e.currentTarget, this.options.target)
|
|
127
|
-
e.stopPropagation()
|
|
128
|
-
|
|
129
|
-
if (e.target === e.currentTarget) {
|
|
130
|
-
return
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (e && e.target) {
|
|
134
|
-
var el = e.target
|
|
135
|
-
// console.log('el', el, el.matches(this.options.target))
|
|
136
|
-
while (el && !el.matches(this.options.target)) {
|
|
137
|
-
el = el.parentNode
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
css.remove(this.item, 'is-selected')
|
|
141
|
-
css.add(el, 'is-selected')
|
|
142
|
-
|
|
143
|
-
this.select(el, e, this.item)
|
|
144
|
-
this.item = el
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* select
|
|
150
|
-
* @param {Element} item [description]
|
|
151
|
-
* @param {event} event The caller event
|
|
152
|
-
* @return [description]
|
|
153
|
-
*/
|
|
154
|
-
select (item, e, selected) {
|
|
155
|
-
this.emit('select', item)
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* [render description]
|
|
160
|
-
* @param {?} info [description]
|
|
161
|
-
* @return {?} [description]
|
|
162
|
-
*/
|
|
163
|
-
render (info) {
|
|
164
|
-
var item
|
|
165
|
-
|
|
166
|
-
if (info.type === 'divider') {
|
|
167
|
-
item = new Divider()
|
|
168
|
-
} else {
|
|
169
|
-
item = new Item({
|
|
170
|
-
name: info.name,
|
|
171
|
-
text: info.text || info.name
|
|
172
|
-
})
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return item
|
|
176
|
-
}
|
|
39
|
+
set (list) {
|
|
40
|
+
var text = ''
|
|
177
41
|
|
|
178
|
-
/**
|
|
179
|
-
* Setter
|
|
180
|
-
* @param {string} prop
|
|
181
|
-
* @param {string} value
|
|
182
|
-
*/
|
|
183
|
-
set (prop, value, options) {
|
|
184
|
-
// console.log('set', prop, value)
|
|
185
|
-
switch (prop) {
|
|
186
|
-
case 'list':
|
|
187
|
-
this.setList(value, options)
|
|
188
|
-
break
|
|
189
|
-
default:
|
|
190
|
-
this.setList(prop, options)
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return this
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Set list
|
|
198
|
-
* @param {Array} list List of info object
|
|
199
|
-
* @return {Object} The class instance
|
|
200
|
-
*/
|
|
201
|
-
setList (list) {
|
|
202
42
|
for (var i = 0; i < list.length; i++) {
|
|
203
|
-
|
|
43
|
+
if (i < list.length - 1) {
|
|
44
|
+
text = text + list[i] + this.options.seprator
|
|
45
|
+
} else {
|
|
46
|
+
text = text + list[i]
|
|
47
|
+
}
|
|
204
48
|
}
|
|
205
49
|
|
|
206
|
-
|
|
207
|
-
|
|
50
|
+
// console.log('set', text)
|
|
51
|
+
if (text === undefined) return
|
|
208
52
|
|
|
209
|
-
|
|
210
|
-
this.root.scrollTop = this.root.scrollHeight - this.root.getBoundingClientRect().height
|
|
211
|
-
}
|
|
53
|
+
var label = this.options.label || ''
|
|
212
54
|
|
|
213
|
-
|
|
214
|
-
* [add description]
|
|
215
|
-
* @param {Object} item [description]
|
|
216
|
-
*/
|
|
217
|
-
addItem (item /*, index */) {
|
|
218
|
-
if (!item) {
|
|
219
|
-
return
|
|
220
|
-
}
|
|
55
|
+
this.root.innerHTML = label + text
|
|
221
56
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
insert(item.root, this.root, where)
|
|
225
|
-
} else {
|
|
226
|
-
insert(item, this.root, where)
|
|
57
|
+
if (this.options.spaceAfter) {
|
|
58
|
+
this.root.innerHTML = this.root.innerHTML + ' '
|
|
227
59
|
}
|
|
228
|
-
|
|
229
|
-
this.items.push(item)
|
|
230
|
-
|
|
231
|
-
return item
|
|
232
60
|
}
|
|
233
61
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
empty () {
|
|
239
|
-
this.root.innerHTML = ''
|
|
240
|
-
this.items = []
|
|
241
|
-
this.item = null
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Reverse the list order
|
|
246
|
-
* @return {Object} The class instance
|
|
247
|
-
*/
|
|
248
|
-
reverse () {
|
|
249
|
-
this.list.reverse()
|
|
250
|
-
this.update(this.list)
|
|
251
|
-
|
|
252
|
-
return this
|
|
62
|
+
setText (text) {
|
|
63
|
+
// console.log('setText', text)
|
|
64
|
+
this.root.innerHTML = text
|
|
253
65
|
}
|
|
254
66
|
}
|
|
255
67
|
|
package/src/loading.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import build from './module/build'
|
|
2
|
+
|
|
3
|
+
class Loading {
|
|
4
|
+
static isComponent () {
|
|
5
|
+
return true
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
static defaults = {
|
|
9
|
+
class: 'loading',
|
|
10
|
+
tag: 'div',
|
|
11
|
+
delay: 1000,
|
|
12
|
+
type: 'indeterminate',
|
|
13
|
+
circular: `<svg class="progress" width="65px" height="65px" viewBox="0 0 66 66" xmlns="http://www.w3.org/2000/svg">
|
|
14
|
+
<circle class="path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle>
|
|
15
|
+
</svg>`
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
constructor (options) {
|
|
19
|
+
this.init(options)
|
|
20
|
+
this.build()
|
|
21
|
+
this.buildLoading()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
init (options) {
|
|
25
|
+
this.options = Object.assign({}, Loading.defaults, options || {})
|
|
26
|
+
Object.assign(this, build)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
buildLoading (options) {
|
|
30
|
+
if (this.options.type === 'circular') {
|
|
31
|
+
this.element.innerHTML = this.options.circular
|
|
32
|
+
} if (this.options.type === 'indeterminate') {
|
|
33
|
+
this.bar = document.createElement(this.options.tag)
|
|
34
|
+
this.bar.classList.add('bar')
|
|
35
|
+
this.element.classList.add('type-indeterminate')
|
|
36
|
+
this.element.appendChild(this.bar)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
set (progress) {
|
|
41
|
+
this.bar.setAttribute('style', 'width: ' + progress)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
show (delay) {
|
|
45
|
+
delay = delay || this.options.delay
|
|
46
|
+
|
|
47
|
+
clearTimeout(this.showTimeout)
|
|
48
|
+
this.showTimeout = setTimeout(() => {
|
|
49
|
+
this.element.classList.add('show')
|
|
50
|
+
}, this.options.delay)
|
|
51
|
+
|
|
52
|
+
this.visible = true
|
|
53
|
+
|
|
54
|
+
return this
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
showNow () {
|
|
58
|
+
this.element.classList.add('show')
|
|
59
|
+
|
|
60
|
+
this.visible
|
|
61
|
+
|
|
62
|
+
return this
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
hide () {
|
|
66
|
+
clearTimeout(this.showTimeout)
|
|
67
|
+
this.element.classList.remove('show')
|
|
68
|
+
this.visible = false
|
|
69
|
+
return this
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export default Loading
|
package/src/map/build.js
CHANGED
|
@@ -13,11 +13,11 @@ export default {
|
|
|
13
13
|
* @return {void} This class instance
|
|
14
14
|
*/
|
|
15
15
|
build () {
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
16
|
+
this.element = document.createElement(this.options.tag)
|
|
17
|
+
this.element.classList.add(this.options.class)
|
|
18
18
|
|
|
19
19
|
if (this.options.container) {
|
|
20
|
-
this.options.container.appendChild(this.
|
|
20
|
+
this.options.container.appendChild(this.element)
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
this.label = document.createElement('div')
|
|
@@ -27,7 +27,7 @@ export default {
|
|
|
27
27
|
this.buildMap()
|
|
28
28
|
this.screenSize()
|
|
29
29
|
|
|
30
|
-
observer.insert(this.
|
|
30
|
+
observer.insert(this.element, () => {
|
|
31
31
|
// if (touch()) {
|
|
32
32
|
// // console.log('pinchzoom', this.options.pichZoom)
|
|
33
33
|
// this.draggable = new PinchZoom(this.slide, {
|
|
@@ -58,7 +58,7 @@ export default {
|
|
|
58
58
|
})
|
|
59
59
|
// }
|
|
60
60
|
|
|
61
|
-
this.rect = this.
|
|
61
|
+
this.rect = this.element.getBoundingClientRect()
|
|
62
62
|
|
|
63
63
|
this.screen = {
|
|
64
64
|
y: window.pageYOffset,
|
|
@@ -84,7 +84,7 @@ export default {
|
|
|
84
84
|
// console.log('buildmap')
|
|
85
85
|
this.slide = document.createElement('div')
|
|
86
86
|
this.slide.classList.add('slide')
|
|
87
|
-
this.
|
|
87
|
+
this.element.appendChild(this.slide)
|
|
88
88
|
|
|
89
89
|
this.map = document.createElement('div')
|
|
90
90
|
this.map.classList.add('map')
|
package/src/map/display.js
CHANGED
|
@@ -82,24 +82,24 @@ export default {
|
|
|
82
82
|
},
|
|
83
83
|
|
|
84
84
|
updateRoot () {
|
|
85
|
-
this.offsetX = this.screen.width - this.
|
|
86
|
-
this.offsetY = this.screen.height - this.
|
|
85
|
+
this.offsetX = this.screen.width - this.element.offsetWidth
|
|
86
|
+
this.offsetY = this.screen.height - this.element.offsetHeight
|
|
87
87
|
|
|
88
88
|
// console.log('--', this.offsetX / 2 + 'px')
|
|
89
89
|
|
|
90
|
-
this.
|
|
91
|
-
this.
|
|
90
|
+
this.element.style.left = (this.offsetX / 2) + 'px'
|
|
91
|
+
this.element.style.top = (this.offsetY / 2) + 'px'
|
|
92
92
|
|
|
93
93
|
// if (isTouchScreen()) {
|
|
94
|
-
// this.
|
|
94
|
+
// this.element.style.top = (this.offsetY / 2) + 70 + 'px'
|
|
95
95
|
// } else {
|
|
96
|
-
// this.
|
|
96
|
+
// this.element.style.top = -1200 + 'px'
|
|
97
97
|
// }
|
|
98
98
|
},
|
|
99
99
|
|
|
100
100
|
updateMap () {
|
|
101
|
-
var offsetX = this.
|
|
102
|
-
// var offsetY = this.
|
|
101
|
+
var offsetX = this.element.offsetWidth - this.map.offsetWidth
|
|
102
|
+
// var offsetY = this.element.height - this.map.offsetHeight
|
|
103
103
|
|
|
104
104
|
// console.log('--', this.offsetX / 2 + 'px')
|
|
105
105
|
|
package/src/menu.js
CHANGED
|
@@ -1,140 +1,84 @@
|
|
|
1
|
-
|
|
1
|
+
import EventEmitter from './mixin/emitter'
|
|
2
|
+
// menu related modules
|
|
3
|
+
import build from './module/build'
|
|
4
|
+
import bindEvents from './module/events'
|
|
5
|
+
import display from './mixin/display'
|
|
6
|
+
|
|
7
|
+
import Element from './element'
|
|
8
|
+
import Button from './button'
|
|
9
|
+
|
|
10
|
+
class Menu extends EventEmitter {
|
|
11
|
+
static defaults = {
|
|
12
|
+
class: 'menu',
|
|
13
|
+
transition: 200,
|
|
14
|
+
modal: false,
|
|
15
|
+
layout: [
|
|
16
|
+
[Element, 'surface', { class: 'surface' },
|
|
17
|
+
[Element, 'list', { tag: 'ul', class: 'items' }]
|
|
18
|
+
]
|
|
19
|
+
],
|
|
20
|
+
events: [
|
|
21
|
+
['element.click', 'close']
|
|
22
|
+
]
|
|
23
|
+
};
|
|
2
24
|
|
|
3
|
-
import classify from './component/classify'
|
|
4
|
-
import css from './module/css'
|
|
5
|
-
import events from './component/events'
|
|
6
|
-
import insert from './element/insert'
|
|
7
|
-
import offset from './element/offset'
|
|
8
|
-
|
|
9
|
-
import create from './element/create'
|
|
10
|
-
|
|
11
|
-
import attach from './module/attach'
|
|
12
|
-
import emitter from './module/emitter'
|
|
13
|
-
|
|
14
|
-
import List from './list'
|
|
15
|
-
import Item from './item'
|
|
16
|
-
import Divider from './divider'
|
|
17
|
-
|
|
18
|
-
const defaults = {
|
|
19
|
-
prefix: 'material',
|
|
20
|
-
class: 'menu',
|
|
21
|
-
tag: 'div',
|
|
22
|
-
events: [
|
|
23
|
-
['root.click', 'hide'],
|
|
24
|
-
['mask.click', 'hide']
|
|
25
|
-
]
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* This Class represents a menu.
|
|
30
|
-
*
|
|
31
|
-
* @return {parent} The class instance
|
|
32
|
-
* @example new Container({
|
|
33
|
-
* container: document.body
|
|
34
|
-
* });
|
|
35
|
-
*/
|
|
36
|
-
class Menu {
|
|
37
|
-
/**
|
|
38
|
-
* Constructor
|
|
39
|
-
* @param {Object} options - Component options
|
|
40
|
-
* @return {Object} Class instance
|
|
41
|
-
*/
|
|
42
25
|
constructor (options) {
|
|
26
|
+
super()
|
|
27
|
+
|
|
43
28
|
this.init(options)
|
|
44
|
-
this.build()
|
|
45
|
-
this.
|
|
29
|
+
this.build(this.constructor)
|
|
30
|
+
this.bindEvents()
|
|
46
31
|
|
|
47
|
-
this.
|
|
48
|
-
|
|
49
|
-
this.emit('ready')
|
|
50
|
-
|
|
51
|
-
return this
|
|
32
|
+
this.render(this.options.items)
|
|
52
33
|
}
|
|
53
34
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
*/
|
|
58
|
-
init (options) {
|
|
59
|
-
this.options = Object.assign({}, defaults, options || {})
|
|
60
|
-
|
|
61
|
-
Object.assign(this, emitter, events, attach, insert)
|
|
35
|
+
init(options) {
|
|
36
|
+
this.options = Object.assign({}, Menu.defaults, options || {})
|
|
37
|
+
Object.assign(this, build, bindEvents, display)
|
|
62
38
|
}
|
|
63
39
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this.root = create(this.options.tag, this.options.css)
|
|
70
|
-
this.mask = create(this.options.tag, this.options.class + '-mask')
|
|
71
|
-
|
|
72
|
-
if (this.options.position) {
|
|
73
|
-
this.root.style.position = this.options.position
|
|
40
|
+
render (items) {
|
|
41
|
+
if (items && Array.isArray(items)) {
|
|
42
|
+
for (var i = 0; i < items.length; i++) {
|
|
43
|
+
this.add(items[i])
|
|
44
|
+
}
|
|
74
45
|
}
|
|
75
46
|
|
|
76
|
-
classify(this.root, this.options)
|
|
77
|
-
|
|
78
|
-
if (this.options.list) {
|
|
79
|
-
this.list = new List({
|
|
80
|
-
// root: this.root,
|
|
81
|
-
list: this.options.list,
|
|
82
|
-
target: '.material-item',
|
|
83
|
-
height: 600,
|
|
84
|
-
label: 'Flat',
|
|
85
|
-
select: (item) => {
|
|
86
|
-
this.selected = item
|
|
87
|
-
this.hide()
|
|
88
|
-
}
|
|
89
|
-
}).insert(this.root)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
this.emit('built', this.root)
|
|
93
|
-
|
|
94
47
|
return this
|
|
95
48
|
}
|
|
96
49
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
show (e) {
|
|
112
|
-
css.add(this.mask, 'mask-show')
|
|
113
|
-
|
|
114
|
-
if (e) this.caller = e.target
|
|
50
|
+
add (obj) {
|
|
51
|
+
if (typeof obj !== 'object') return this;
|
|
52
|
+
let item;
|
|
53
|
+
if (obj.type === 'divider') {
|
|
54
|
+
item = new Element({ tag: 'li', class: 'divider' })
|
|
55
|
+
} else {
|
|
56
|
+
obj.container = this.ui.list
|
|
57
|
+
obj.class = 'item'
|
|
58
|
+
item = new Button(obj).on('click', (ev) => {
|
|
59
|
+
// console.log('select', ev.target.name)
|
|
60
|
+
this.emit('select', ev.target.name)
|
|
61
|
+
})
|
|
62
|
+
}
|
|
115
63
|
|
|
116
|
-
|
|
117
|
-
this.position(this.caller)
|
|
64
|
+
return this
|
|
118
65
|
}
|
|
119
66
|
|
|
120
|
-
position
|
|
121
|
-
if (!
|
|
122
|
-
var offs =
|
|
67
|
+
position(target) {
|
|
68
|
+
if (!target) return
|
|
69
|
+
var offs = target.getBoundingClientRect()
|
|
123
70
|
|
|
124
|
-
var offsw = this.offset =
|
|
71
|
+
var offsw = this.offset = this.ui.surface.getBoundingClientRect()
|
|
125
72
|
|
|
126
|
-
|
|
127
|
-
|
|
73
|
+
this.ui.surface.style.top = (offs.top - 4) + 'px'
|
|
74
|
+
this.ui.surface.style.left = offs.left - offsw.width + offs.width + 'px'
|
|
128
75
|
|
|
129
|
-
this
|
|
130
|
-
this.root.style.left = offs.left - offsw.width + offs.width + 'px'
|
|
131
|
-
// this.root.style.right = offs.right + offs.width + offsw.width + 'px'
|
|
76
|
+
return this
|
|
132
77
|
}
|
|
133
78
|
|
|
134
|
-
|
|
135
|
-
// console.log('
|
|
136
|
-
|
|
137
|
-
css.remove(this.mask, 'mask-show')
|
|
79
|
+
close() {
|
|
80
|
+
// console.log('close')
|
|
81
|
+
this.destroy()
|
|
138
82
|
}
|
|
139
83
|
}
|
|
140
84
|
|