-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage.js
More file actions
57 lines (51 loc) · 2.04 KB
/
Copy pathmessage.js
File metadata and controls
57 lines (51 loc) · 2.04 KB
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
// ==================== Closable message plugin ====================
const messageCloseButtonClass = "ff-message-close-button";
// Makes each selected message element closable by adding a close button to it.
function closableMessage() {
return this.forEach(message => {
if (message.querySelector("." + messageCloseButtonClass)) return; // Already added
// Add close button
let closeButton = F("<a>");
closeButton.classList.add(messageCloseButtonClass);
closeButton.setAttribute("href", "#");
closeButton.draggable = false;
// Workaround for Firefox bug https://bugzilla.mozilla.org/show_bug.cgi?id=1763858
closeButton.F.on("dragstart", event => event.preventDefault());
closeButton.appendTo(message);
message.classList.add("closable");
closeButton.on("click", event => {
event.preventDefault();
if (event.button === 0) {
message.F.closableMessage.close();
}
});
});
}
// Closes each selected message and removes it from the document.
function closeMessage() {
return this.forEach(message => {
// TODO / https://stackoverflow.com/q/72000598
//// Determine the effective occupied height caused by the message
//let height = message.parentElement.offsetHeight;
//console.log("parent height before: ", message.parentElement.offsetHeight);
//let originalDisplay = message.style.display;
//message.style.display = "none";
//height -= message.parentElement.offsetHeight;
//console.log("parent height after: ", message.parentElement.offsetHeight);
//message.style.display = originalDisplay;
//F.forceReflow();
//
//console.log("msg height: ", message.offsetHeight);
//console.log("diff height: ", height);
// Start the closing animation
message.classList.add("ff-closed");
//message.style.marginBottom = (-height + parseFloat(message.F.computedStyle.marginBottom)) + "px";
message.F.afterTransition(() => message.remove());
});
}
F.registerPlugin("closableMessage", closableMessage, {
methods: {
close: closeMessage
},
selectors: [".message.closable"]
});