-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathscript.js
More file actions
42 lines (36 loc) · 1.62 KB
/
script.js
File metadata and controls
42 lines (36 loc) · 1.62 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
// Wrap your code in an immediately-invoked function expression to avoid polluting the global scope
(function() {
// Cache frequently used elements to avoid repeatedly querying the DOM
var mainElement = document.getElementById("main");
var content1Element = document.getElementById("content1");
var content2Element = document.getElementById("content2");
// Set initial style for the main element
mainElement.style.display = "none";
// Event listener for messages
window.addEventListener("message", function(event) {
if (event.data.action === "open") {
// Update main element style
mainElement.style.display = "block";
// Check if content is undefined and update content2 element style accordingly
content2Element.style.display = (event.data.content === undefined) ? "none" : "block";
// Update content elements
content1Element.innerHTML = event.data.title;
content2Element.innerHTML = event.data.content;
// Use jQuery to animate the main element
$('#main').animate({
'margin-left': '-5%'
});
} else if (event.data.action === "close") {
// Use jQuery to animate the main element
$('#main').animate({
'margin-left': '-30%'
});
// Set a timeout to hide the main element and clear content after animation
setTimeout(function() {
mainElement.style.display = "none";
content1Element.innerHTML = "";
content2Element.innerHTML = "";
}, 1000);
}
});
})();