-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_menu_observer.js
111 lines (98 loc) · 3.27 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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() {
// to not open navi menu when upload file
if ($('.app-navigation-toggle-wrapper button').attr('aria-expanded') === "true") {
$('.app-navigation-toggle-wrapper button').click();
}
}, 300);
//}
}
});
});
observer3.observe(elm, {
attributes: true,
//childList: true,
subtree: true,
attributeFilter: ['class']
});
})
waitForElm('#content-vue > div').then((elm) => {
var block_navi_hide = false;
$(window).resize(function() {
// block if window is not narrow
if ($(this).width() > 1024) {
block_navi_hide = true;
}
else {
block_navi_hide = false;
}
})
var object_under_cursor = "";
document.addEventListener('mousemove', function(e) {
object_under_cursor = $(document.elementFromPoint(e.pageX, e.pageY));
})
$(elm).on("focusout", function() {
//console.log('Navi lost focus!');
if (!block_navi_hide) {
if ($(object_under_cursor.closest('.app-navigation')).length<1) {
if ($('.app-navigation-toggle-wrapper button').attr('aria-expanded') === "true") {
$('.app-navigation-toggle-wrapper button').click();
}
}
}
});
})