-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathscript.js
98 lines (86 loc) · 3 KB
/
script.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
const editControls = document.querySelector(".input-toolbar-icons");
editControls.addEventListener("click", function (event) {
const command =
event.target !== undefined &&
event.target.getAttribute("data-command") !== null
? event.target.getAttribute("data-command")
: null;
if (command === null) return;
console.log("Selected command: " + command);
if (document.getSelection().toString().length === 0) {
alert("Please select some text before editing the content.");
return;
}
let range = window.getSelection().getRangeAt(0);
const oldConent = document.createTextNode(range.toString());
const newElement = document.createElement(command);
newElement.append(oldConent);
range.deleteContents();
range.insertNode(newElement);
});
const closeSideBar = document.getElementById("close");
const sideBarWrapper = document.getElementById("sidebar-wrapper");
const sideBar = document.getElementById("user-sidebar");
const user = document.getElementById("user");
const info = document.getElementById("info");
const rightSidebarWrapper = document.getElementById("right-sidebar-wrapper");
const channelRightSidebar = document.getElementById("channel-right-sidebar");
const closeRightSidebar = document.getElementById("close-right-sidebar");
// sidebar
if (user) {
user.addEventListener("click", () => {
if (sideBarWrapper) {
sideBarWrapper.classList.add("sidebar-wrapper-display");
}
if (sideBar) {
sideBar.classList.add("user-sidebar-display");
}
});
}
if (closeSideBar) {
closeSideBar.addEventListener("click", () => {
sideBar.classList.remove("sidebar-display");
sideBarWrapper.classList.remove("sidebar-wrapper-display");
});
}
// Right sidebar displaying channel info
const enableInfoButton = (breaker) => {
if (breaker.matches) {
info.disabled = false;
info.classList.remove("disabled");
} else {
info.disabled = true;
info.classList.add("disabled");
}
};
if (matchMedia) {
const sidebarBreak = window.matchMedia("(max-width: 1250px)");
sidebarBreak.addEventListener("change", enableInfoButton);
enableInfoButton(sidebarBreak);
}
if (info) {
info.addEventListener("click", () => {
if (rightSidebarWrapper) {
rightSidebarWrapper.classList.add("sidebar-wrapper-display");
}
if (channelRightSidebar) {
channelRightSidebar.classList.add("channel-sidebar-display");
}
});
}
if (closeRightSidebar) {
closeRightSidebar.addEventListener("click", () => {
channelRightSidebar.classList.remove("channel-sidebar-display");
rightSidebarWrapper.classList.remove("sidebar-wrapper-display");
});
}
// click anywhere in the browser to close modals
window.onclick = (e) => {
if (e.target == sideBarWrapper) {
sideBar.classList.remove("sidebar-display");
sideBarWrapper.classList.remove("sidebar-wrapper-display");
} else if (e.target == rightSidebarWrapper) {
channelRightSidebar.classList.remove("channel-sidebar-display");
rightSidebarWrapper.classList.remove("sidebar-wrapper-display");
}
};