-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_menu_observer.js
78 lines (69 loc) · 2.28 KB
/
user_menu_observer.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
function waitForElm(selector) {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
resolve(document.querySelector(selector));
observer.disconnect();
}
});
/*observer.observe($('#notifications').get(0), {
childList: true,
subtree: true
});*/
});
}
let debounce;
// temp force close navi-menu if user menu is opened
waitForElm('#user-menu').then((elm) => {
let observer2 = new MutationObserver(mutations => {
//let clicked = false;
mutations.forEach(function(mutation) {
if (mutation.target.className.includes('header-menu--opened')) {
var expanded = ($('.app-navigation-toggle-wrapper button').attr( "aria-expanded") === 'true');
if (expanded) {
//if (!clicked) {
//clicked = true;
// to prevent multiple clicking
clearTimeout(debounce);
debounce = setTimeout(function() {
$('.app-navigation-toggle-wrapper button').click();
$(elm).children("button:first").click();
}, 100);
//}
}
}
});
});
observer2.observe(elm, {
attributes: true,
attributeFilter: ['class']
});
})
waitForElm('#body-user').then((elm) => {
//console.log($(elm));
let observer3 = new MutationObserver(mutations => {
//let clicked = false;
mutations.forEach(function(mutation) {
//console.log($(mutation.target));
if ((mutation.target.className.includes('modal-in-enter-to')) || (mutation.target.className.includes('modal-in-leave-to'))) {
//if (!clicked) {
//clicked = true;
// to prevent multiple clicking
clearTimeout(debounce);
debounce = setTimeout(function() {
$('.app-navigation-toggle-wrapper button').click();
}, 300);
//}
}
});
});
observer3.observe(elm, {
attributes: true,
//childList: true,
subtree: true,
attributeFilter: ['class']
});
})