material 0.8.3 → 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/index.js +3 -3
- package/package.json +1 -1
- package/src/module/device.js +8 -34
- package/src/module/events.js +36 -26
- package/src/switcher.js +2 -2
package/index.js
CHANGED
|
@@ -30,12 +30,12 @@ import Textfield from './src/textfield'
|
|
|
30
30
|
import Toolbar from './src/toolbar'
|
|
31
31
|
import Tooltip from './src/tooltip'
|
|
32
32
|
import View from './src/view'
|
|
33
|
-
import events from './src/module/events'
|
|
34
33
|
import attributes from './src/module/attributes'
|
|
35
34
|
import build from './src/module/build'
|
|
36
35
|
import dataset from './src/module/dataset'
|
|
36
|
+
import device from './src/module/device'
|
|
37
37
|
import display from './src/mixin/display'
|
|
38
|
-
import events from './src/module/
|
|
38
|
+
import events from './src/module/events'
|
|
39
39
|
import emitter from './src/module/emitter'
|
|
40
40
|
import jsonToHTML from './src/module/jsontohtml'
|
|
41
41
|
import mediator from './src/module/mediator'
|
|
@@ -46,6 +46,6 @@ export {
|
|
|
46
46
|
AppBar, Button, Card, Checkbox, Component, DateHour, Dialog, Drawer, Element,
|
|
47
47
|
File, Form, Image, Layout, List, Loading, Menu, Navigation, Progress, Select,
|
|
48
48
|
Selecter, Slider, Snackbar, Switch, Switcher, Tabs, TabView, Text, Textfield, Toolbar, Tooltip,
|
|
49
|
-
View,
|
|
49
|
+
View, attributes, build, dataset, device, display, events, emitter, jsonToHTML, mediator,
|
|
50
50
|
observer, smoothscroll
|
|
51
51
|
}
|
package/package.json
CHANGED
package/src/module/device.js
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
const previousDevice = window.device
|
|
5
5
|
|
|
6
6
|
const device = {}
|
|
7
|
+
const os = ['ios', 'iphone', 'ipad', 'ipod', 'android', 'blackberry', 'macos', 'windows', 'fxos', 'meego', 'television']
|
|
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']
|
|
7
10
|
|
|
8
11
|
const changeOrientationList = []
|
|
9
12
|
|
|
@@ -18,22 +21,6 @@ const documentElement = window.document.documentElement
|
|
|
18
21
|
let userAgent = window.navigator.userAgent.toLowerCase()
|
|
19
22
|
|
|
20
23
|
// Detectable television devices.
|
|
21
|
-
const television = [
|
|
22
|
-
'googletv',
|
|
23
|
-
'viera',
|
|
24
|
-
'smarttv',
|
|
25
|
-
'internet.tv',
|
|
26
|
-
'netcast',
|
|
27
|
-
'nettv',
|
|
28
|
-
'appletv',
|
|
29
|
-
'boxee',
|
|
30
|
-
'kylo',
|
|
31
|
-
'roku',
|
|
32
|
-
'dlnadoc',
|
|
33
|
-
'pov_tv',
|
|
34
|
-
'hbbtv',
|
|
35
|
-
'ce-html'
|
|
36
|
-
]
|
|
37
24
|
|
|
38
25
|
// Main functions
|
|
39
26
|
// --------------
|
|
@@ -237,7 +224,7 @@ function removeClass (className) {
|
|
|
237
224
|
}
|
|
238
225
|
|
|
239
226
|
function cleanClasses () {
|
|
240
|
-
const classes = [
|
|
227
|
+
const classes = [...os, ...type]
|
|
241
228
|
for (let i = 0; i < classes.length; i++) {
|
|
242
229
|
removeClass(classes[i])
|
|
243
230
|
}
|
|
@@ -362,20 +349,8 @@ function findMatch (arr) {
|
|
|
362
349
|
return 'unknown'
|
|
363
350
|
}
|
|
364
351
|
|
|
365
|
-
device.type = findMatch(
|
|
366
|
-
device.os = findMatch(
|
|
367
|
-
'ios',
|
|
368
|
-
'iphone',
|
|
369
|
-
'ipad',
|
|
370
|
-
'ipod',
|
|
371
|
-
'android',
|
|
372
|
-
'blackberry',
|
|
373
|
-
'macos',
|
|
374
|
-
'windows',
|
|
375
|
-
'fxos',
|
|
376
|
-
'meego',
|
|
377
|
-
'television'
|
|
378
|
-
])
|
|
352
|
+
device.type = findMatch(type)
|
|
353
|
+
device.os = findMatch(os)
|
|
379
354
|
|
|
380
355
|
function setOrientationCache () {
|
|
381
356
|
device.orientation = findMatch(['portrait', 'landscape'])
|
|
@@ -388,9 +363,8 @@ device.onDeviceChange = null
|
|
|
388
363
|
|
|
389
364
|
function updateDeviceDetection () {
|
|
390
365
|
userAgent = window.navigator.userAgent.toLowerCase()
|
|
391
|
-
|
|
392
|
-
device.
|
|
393
|
-
device.os = findMatch(['ios', 'iphone', 'ipad', 'ipod', 'android', 'blackberry', 'macos', 'windows', 'fxos', 'meego', 'television'])
|
|
366
|
+
device.type = findMatch(type)
|
|
367
|
+
device.os = findMatch(os)
|
|
394
368
|
setOrientationCache()
|
|
395
369
|
applyClass()
|
|
396
370
|
checkAndHandleDeviceChange()
|
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
|
}
|