material 0.8.9 → 0.9.0
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/index.js +2 -1
- package/package.json +1 -1
- package/src/menu.js +76 -17
- package/src/mixin/position.js +20 -9
package/index.js
CHANGED
|
@@ -35,6 +35,7 @@ import build from './src/module/build'
|
|
|
35
35
|
import dataset from './src/module/dataset'
|
|
36
36
|
import device from './src/module/device'
|
|
37
37
|
import display from './src/mixin/display'
|
|
38
|
+
import request from './src/module/request'
|
|
38
39
|
import events from './src/module/events'
|
|
39
40
|
import emitter from './src/module/emitter'
|
|
40
41
|
import jsonToHTML from './src/module/jsontohtml'
|
|
@@ -47,5 +48,5 @@ export {
|
|
|
47
48
|
File, Form, Image, Layout, List, Loading, Menu, Navigation, Progress, Select,
|
|
48
49
|
Selecter, Slider, Snackbar, Switch, Switcher, Tabs, TabView, Text, Textfield, Toolbar, Tooltip,
|
|
49
50
|
View, attributes, build, dataset, device, display, events, emitter, jsonToHTML, mediator,
|
|
50
|
-
observer, smoothscroll
|
|
51
|
+
observer, request, smoothscroll
|
|
51
52
|
}
|
package/package.json
CHANGED
package/src/menu.js
CHANGED
|
@@ -6,7 +6,6 @@ import display from './mixin/display'
|
|
|
6
6
|
import position from './mixin/position'
|
|
7
7
|
|
|
8
8
|
import Element from './element'
|
|
9
|
-
import Button from './button'
|
|
10
9
|
|
|
11
10
|
class Menu extends EventEmitter {
|
|
12
11
|
static defaults = {
|
|
@@ -23,10 +22,8 @@ class Menu extends EventEmitter {
|
|
|
23
22
|
],
|
|
24
23
|
events: [
|
|
25
24
|
['element.click', 'onClick'],
|
|
26
|
-
['
|
|
27
|
-
['
|
|
28
|
-
['element.mouseleave', 'close'],
|
|
29
|
-
['options.target.mouseleave', 'close']
|
|
25
|
+
['select', 'destroy'],
|
|
26
|
+
['underlay.click', 'close']
|
|
30
27
|
]
|
|
31
28
|
}
|
|
32
29
|
|
|
@@ -35,6 +32,7 @@ class Menu extends EventEmitter {
|
|
|
35
32
|
|
|
36
33
|
this.init(options)
|
|
37
34
|
this.build(this.constructor)
|
|
35
|
+
this.buildUnderlay()
|
|
38
36
|
this.setup()
|
|
39
37
|
|
|
40
38
|
this.render(this.options.items)
|
|
@@ -45,11 +43,25 @@ class Menu extends EventEmitter {
|
|
|
45
43
|
init (options) {
|
|
46
44
|
this.options = Object.assign({}, Menu.defaults, options || {})
|
|
47
45
|
Object.assign(this, build, display, position)
|
|
46
|
+
|
|
47
|
+
this.menus = []
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
buildUnderlay () {
|
|
51
|
+
if (!this.options.parentName) {
|
|
52
|
+
this.underlay = new Element({
|
|
53
|
+
class: 'menu-underlay'
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
this.options.container.appendChild(this.underlay)
|
|
57
|
+
}
|
|
48
58
|
}
|
|
49
59
|
|
|
50
60
|
setup () {
|
|
51
61
|
events.attach(this.options.events, this)
|
|
52
62
|
this.closeTimeout = null
|
|
63
|
+
|
|
64
|
+
document.addEventListener('click', this.handleDocumentClick)
|
|
53
65
|
}
|
|
54
66
|
|
|
55
67
|
render (items) {
|
|
@@ -64,34 +76,81 @@ class Menu extends EventEmitter {
|
|
|
64
76
|
|
|
65
77
|
add (obj) {
|
|
66
78
|
if (typeof obj !== 'object') return this
|
|
79
|
+
|
|
67
80
|
let item
|
|
81
|
+
|
|
68
82
|
if (obj.type === 'divider') {
|
|
69
83
|
item = new Element({ tag: 'li', class: 'divider' })
|
|
70
84
|
} else {
|
|
71
|
-
obj.
|
|
72
|
-
|
|
85
|
+
obj.tag = 'li'
|
|
86
|
+
obj.class = obj.class ? obj.class + ' item' : 'item'
|
|
87
|
+
item = new Element(obj)
|
|
88
|
+
|
|
89
|
+
item.addEventListener('mouseenter', () => {
|
|
90
|
+
if (this.menu) {
|
|
91
|
+
this.menu.destroy()
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
if (obj.items && Array.isArray(obj.items)) {
|
|
96
|
+
item.classList.add('sub')
|
|
97
|
+
|
|
98
|
+
item.addEventListener('mouseenter', () => {
|
|
99
|
+
this.menu = new Menu({
|
|
100
|
+
class: 'floating',
|
|
101
|
+
target: item,
|
|
102
|
+
container: this.options.container,
|
|
103
|
+
parentName: obj.name,
|
|
104
|
+
items: obj.items
|
|
105
|
+
}).position(item, {
|
|
106
|
+
align: 'left',
|
|
107
|
+
vAlign: 'inline',
|
|
108
|
+
offsetX: 8,
|
|
109
|
+
offsetY: 8
|
|
110
|
+
}).show()
|
|
111
|
+
|
|
112
|
+
this.menu.on('select', (name) => {
|
|
113
|
+
this.emit('select', `${obj.name}:${name}`)
|
|
114
|
+
}).on('destroy', () => {
|
|
115
|
+
this.menu = null
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
this.menus.push(this.menu)
|
|
119
|
+
})
|
|
120
|
+
}
|
|
73
121
|
}
|
|
74
|
-
|
|
122
|
+
this.ui.list.appendChild(item)
|
|
75
123
|
return this
|
|
76
124
|
}
|
|
77
125
|
|
|
78
|
-
onMouseEnter () {
|
|
79
|
-
clearTimeout(this.closeTimeout)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
126
|
onClick (ev) {
|
|
83
|
-
|
|
127
|
+
if (ev.target.classList.contains('sub')) return
|
|
84
128
|
const name = ev.target.getAttribute('name')
|
|
85
129
|
if (name) {
|
|
86
130
|
this.emit('select', name)
|
|
87
131
|
}
|
|
88
|
-
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
destroyMenu (menu) {
|
|
135
|
+
// Trouver l'index de menuToDestroy dans this.menus
|
|
136
|
+
const index = this.menus.indexOf(menu)
|
|
137
|
+
|
|
138
|
+
// Si trouvé, supprimer le menu du tableau
|
|
139
|
+
if (index > -1) {
|
|
140
|
+
this.menus.splice(index, 1)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Appeler la méthode destroy sur le menuToDestroy
|
|
144
|
+
menu.destroy()
|
|
89
145
|
}
|
|
90
146
|
|
|
91
147
|
close () {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
148
|
+
// console.log('')
|
|
149
|
+
this.menus.forEach(menu => {
|
|
150
|
+
menu.destroy()
|
|
151
|
+
})
|
|
152
|
+
this.menus = []
|
|
153
|
+
this.destroy()
|
|
95
154
|
}
|
|
96
155
|
}
|
|
97
156
|
|
package/src/mixin/position.js
CHANGED
|
@@ -8,8 +8,10 @@ export default {
|
|
|
8
8
|
|
|
9
9
|
if (!target) return
|
|
10
10
|
|
|
11
|
+
// console.log('container', this.options.container)
|
|
12
|
+
|
|
11
13
|
const caller = target.getBoundingClientRect()
|
|
12
|
-
const screen = this.
|
|
14
|
+
const screen = this.options.container.getBoundingClientRect()
|
|
13
15
|
const element = this.element.getBoundingClientRect()
|
|
14
16
|
|
|
15
17
|
let left, top
|
|
@@ -21,7 +23,6 @@ export default {
|
|
|
21
23
|
case 'right':
|
|
22
24
|
left = caller.left
|
|
23
25
|
if (left + element.width + offsetX > screen.width) {
|
|
24
|
-
console.log('out boundaries')
|
|
25
26
|
left = caller.left - element.width + caller.width
|
|
26
27
|
}
|
|
27
28
|
break
|
|
@@ -34,10 +35,16 @@ export default {
|
|
|
34
35
|
|
|
35
36
|
// ensure that the element remains within the limits of its container
|
|
36
37
|
|
|
38
|
+
// if (left < 0) left = offsetX
|
|
39
|
+
|
|
40
|
+
// if (left + element.width + offsetX > screen.width) {
|
|
41
|
+
// left = screen.width - element.width - offsetX
|
|
42
|
+
// }
|
|
43
|
+
|
|
37
44
|
if (left < 0) left = offsetX
|
|
38
45
|
|
|
39
|
-
if (left + element.width
|
|
40
|
-
left =
|
|
46
|
+
if (left + element.width > screen.width) {
|
|
47
|
+
left = caller.left - element.width
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
// console.log('left', left)
|
|
@@ -46,15 +53,13 @@ export default {
|
|
|
46
53
|
|
|
47
54
|
const scrollY = window.scrollY
|
|
48
55
|
|
|
49
|
-
// console.log('class', name)
|
|
50
|
-
// console.log('scrollY', scrollY)
|
|
51
|
-
// console.log('vAlign', vAlign)
|
|
52
|
-
// console.log('target top', caller.top)
|
|
53
|
-
|
|
54
56
|
switch (vAlign) {
|
|
55
57
|
case 'top':
|
|
56
58
|
top = caller.top + scrollY - element.height
|
|
57
59
|
break
|
|
60
|
+
case 'inline':
|
|
61
|
+
top = caller.top + scrollY
|
|
62
|
+
break
|
|
58
63
|
case 'bottom':
|
|
59
64
|
top = caller.top + caller.height + scrollY
|
|
60
65
|
break
|
|
@@ -71,6 +76,12 @@ export default {
|
|
|
71
76
|
top = caller.top + scrollY + (caller.height / 2) - (element.height / 2)
|
|
72
77
|
}
|
|
73
78
|
|
|
79
|
+
// console.log('screen height', screen.height, element.height, offsetX)
|
|
80
|
+
|
|
81
|
+
if (top + element.height + offsetY > screen.height) {
|
|
82
|
+
top = screen.height - element.height - offsetX
|
|
83
|
+
}
|
|
84
|
+
|
|
74
85
|
this.element.style.left = `${left}px`
|
|
75
86
|
this.element.style.top = `${top}px`
|
|
76
87
|
|