material 0.8.4 → 0.8.5
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/package.json +1 -1
- package/src/module/device.js +2 -16
- package/src/module/events.js +36 -26
- package/src/switcher.js +2 -2
package/package.json
CHANGED
package/src/module/device.js
CHANGED
|
@@ -6,6 +6,8 @@ const previousDevice = window.device
|
|
|
6
6
|
const device = {}
|
|
7
7
|
const os = ['ios', 'iphone', 'ipad', 'ipod', 'android', 'blackberry', 'macos', 'windows', 'fxos', 'meego', 'television']
|
|
8
8
|
const type = ['mobile', 'tablet', 'desktop']
|
|
9
|
+
const television = ['googletv', 'viera', 'smarttv', 'internet.tv', 'netcast', 'nettv', 'appletv', 'boxee', 'kylo', 'roku', 'dlnadoc', 'pov_tv', 'hbbtv', 'ce-html']
|
|
10
|
+
|
|
9
11
|
const changeOrientationList = []
|
|
10
12
|
|
|
11
13
|
// Add device as a global object.
|
|
@@ -19,22 +21,6 @@ const documentElement = window.document.documentElement
|
|
|
19
21
|
let userAgent = window.navigator.userAgent.toLowerCase()
|
|
20
22
|
|
|
21
23
|
// Detectable television devices.
|
|
22
|
-
const television = [
|
|
23
|
-
'googletv',
|
|
24
|
-
'viera',
|
|
25
|
-
'smarttv',
|
|
26
|
-
'internet.tv',
|
|
27
|
-
'netcast',
|
|
28
|
-
'nettv',
|
|
29
|
-
'appletv',
|
|
30
|
-
'boxee',
|
|
31
|
-
'kylo',
|
|
32
|
-
'roku',
|
|
33
|
-
'dlnadoc',
|
|
34
|
-
'pov_tv',
|
|
35
|
-
'hbbtv',
|
|
36
|
-
'ce-html'
|
|
37
|
-
]
|
|
38
24
|
|
|
39
25
|
// Main functions
|
|
40
26
|
// --------------
|
package/src/module/events.js
CHANGED
|
@@ -2,11 +2,17 @@ import extract from './extract'
|
|
|
2
2
|
import last from './last'
|
|
3
3
|
|
|
4
4
|
const events = {
|
|
5
|
-
eventHandlers:
|
|
5
|
+
eventHandlers: {}, // Utiliser un tableau pour stocker les événements et les gestionnaires
|
|
6
6
|
|
|
7
7
|
attach (eventsArray, context) {
|
|
8
8
|
if (!eventsArray) return
|
|
9
9
|
|
|
10
|
+
// Ensure each context has a unique UID
|
|
11
|
+
const uid = context._uid || (context._uid = context.options.class + Math.random().toString(36).substr(2, 9))
|
|
12
|
+
|
|
13
|
+
// Initialize storage for this context if it doesn't already exist
|
|
14
|
+
this.eventHandlers[uid] = this.eventHandlers[uid] || {}
|
|
15
|
+
|
|
10
16
|
eventsArray.forEach(([eventDef, funcDef, option]) => {
|
|
11
17
|
const e = extract.e(context, eventDef)
|
|
12
18
|
const isFunction = typeof funcDef === 'function'
|
|
@@ -20,7 +26,6 @@ const events = {
|
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
const bound = last(keys.join('.'), context)
|
|
23
|
-
|
|
24
29
|
let handler = null
|
|
25
30
|
|
|
26
31
|
if (isFunction) {
|
|
@@ -28,18 +33,17 @@ const events = {
|
|
|
28
33
|
} else if (f && bound) {
|
|
29
34
|
handler = f.bind(bound)
|
|
30
35
|
} else {
|
|
31
|
-
//
|
|
32
|
-
return
|
|
36
|
+
return // Cannot bind function for eventDef
|
|
33
37
|
}
|
|
34
38
|
|
|
35
|
-
if (
|
|
36
|
-
e.element
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
e.element
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
if (!this.eventHandlers[uid][eventDef]) {
|
|
40
|
+
if (handler && e && e.element?.addEventListener) {
|
|
41
|
+
e.element.addEventListener(e.name, handler, option)
|
|
42
|
+
this.eventHandlers[uid][eventDef] = handler
|
|
43
|
+
} else if (e && e.element?.on && handler) {
|
|
44
|
+
e.element.on(e.name, handler)
|
|
45
|
+
this.eventHandlers[uid][eventDef] = handler
|
|
46
|
+
}
|
|
43
47
|
}
|
|
44
48
|
})
|
|
45
49
|
|
|
@@ -47,20 +51,26 @@ const events = {
|
|
|
47
51
|
},
|
|
48
52
|
|
|
49
53
|
detach (eventsArray, context) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
54
|
+
const uid = context._uid
|
|
55
|
+
if (!this.eventHandlers[uid]) return
|
|
56
|
+
|
|
57
|
+
eventsArray.forEach(([eventDef, funcDef, option]) => {
|
|
58
|
+
const e = extract.e(context, eventDef)
|
|
59
|
+
const handler = this.eventHandlers[uid][eventDef]
|
|
60
|
+
if (handler) {
|
|
61
|
+
e.element.removeEventListener(e.name, handler)
|
|
62
|
+
} else if (e.element.off) {
|
|
63
|
+
e.element.off(e.name, handler)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
delete this.eventHandlers[uid][eventDef]
|
|
67
|
+
}
|
|
68
|
+
)
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
list (context) {
|
|
72
|
+
const uid = context?._uid
|
|
73
|
+
return uid ? this.eventHandlers[uid] || {} : this.eventHandlers
|
|
64
74
|
}
|
|
65
75
|
}
|
|
66
76
|
|
package/src/switcher.js
CHANGED
|
@@ -66,7 +66,7 @@ class Switcher extends EventEmitter {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
setup () {
|
|
69
|
-
console.log('events.attach', this.options.events)
|
|
69
|
+
// console.log('events.attach', this.options.events)
|
|
70
70
|
events.attach(this.options.events, this)
|
|
71
71
|
|
|
72
72
|
if (this.options.default) {
|
|
@@ -75,7 +75,7 @@ class Switcher extends EventEmitter {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
click (event) {
|
|
78
|
-
console.log('click', event)
|
|
78
|
+
// console.log('click', event)
|
|
79
79
|
if (!event.target.dataset.switcher) return
|
|
80
80
|
this.select(event.target)
|
|
81
81
|
}
|