-
Notifications
You must be signed in to change notification settings - Fork 0
/
embed.js
80 lines (71 loc) · 2.14 KB
/
embed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const ddeJS = (function() {
const debug = true;
const implementations = {
'0.1' : [
"lib/aria/ariaResolver.js",
"lib/aria/click.js",
"lib/aria/actionnable.js",
"lib/aria/toggableStates.js",
"lib/aria/simpleNavigation.js",
"lib/aria/nestedNavigation.js",
"lib/aria/main.js",
"lib/zonesStates/zonesStates.js",
],
}
var ddeVersion = document.documentElement.getAttribute('dde');
if(ddeVersion.indexOf('native') !== -1) {
console.log('DDE version already natively supported. Aborted.');
return;
}
ddeVersion = ddeVersion.split(' ');
ddeVersion = {
mode : ddeVersion[0],
number : ddeVersion[1]
};
const libs = implementations[ddeVersion.number];
function currentDirectory() {
// Obtenez tous les scripts sur la page
var scripts = document.getElementsByTagName('script');
// Obtenez le dernier script chargé (supposant que c'est le script actuel)
var currentScript = scripts[scripts.length - 1];
// Obtenez l'URL du dossier du script
var scriptUrl = currentScript.src;
var scriptFolderUrl = scriptUrl.substring(0, scriptUrl.lastIndexOf('/'));
return scriptFolderUrl+'/';
}
if(libs) {
const root = currentDirectory();
var scriptCounter = 0;
var stopFirstDOMContentLoaded = true;
window.addEventListener("DOMContentLoaded", (event) => {
if(stopFirstDOMContentLoaded) {
event.stopImmediatePropagation();
stopFirstDOMContentLoaded = false;
if(debug)
console.log("DOMContentLoaded 1* stopped propagation");
}
else
if(debug)
console.log("DOMContentLoaded 2* restore propagation");
},true);
for(l of libs) {
let s = document.createElement('script');
s.src = root+l
s.onload = function() {
scriptCounter++;
if(!debug)
this.remove();
else {
console.log('[DDE] ' + scriptCounter + ' / ' + libs.length + ' => ' + s.src +' loaded.')
}
if(libs.length === scriptCounter) {
window.dispatchEvent(new Event("DOMContentLoaded", {"bubbles": true}));
}
};
(document.head || document.documentElement).prepend(s);
}
}
else
console.error('requested DDE version not supported by this script. Aborted.');
return ddeVersion
})();