Difference between revisions of "Template:Vilnius-Lithuania/JS/menuOverlay"

Line 1: Line 1:
 
//---------------Checking if the page is content page---------------
 
//---------------Checking if the page is content page---------------
var textSection = null;
+
        var textSection = null;
var navbar = document.getElementById("navbar");
+
        var navbar = document.getElementById("navbar");
window.addEventListener('load', function() {
+
        window.addEventListener('load', function() {
textSection = document.querySelector(".elevate-navbar");
+
            textSection = $(".elevate-navbar");
})
+
        })
window.addEventListener('scroll',function() {
+
        window.addEventListener('scroll', function() {
updateScrollbar();
+
            updateScrollbar();
checkNavbarPos();
+
            checkNavbarPos();
});
+
        });
  
  
  
function checkNavbarPos() {
+
        function checkNavbarPos() {
if (textSection != null) {
+
            if (textSection != null) {
var navbarTop = navbar.getBoundingClientRect().top;
+
                var navbarTop = navbar.getBoundingClientRect().top;
var mainTagTop = textSection.getBoundingClientRect().top;
+
                var mainTagTop = textSection.getBoundingClientRect().top;
if (navbarTop >= mainTagTop){
+
                if (navbarTop >= mainTagTop) {
                                        if(document.getElementById("bubbles-to-close").getAttribute("open") != true) navbar.setAttribute("onText", "true");
+
                    if (document.getElementById("bubbles-to-close").getAttribute("open") != true) navbar.setAttribute("onText", "true");
} else {
+
                } else {
navbar.setAttribute("onText", "false");
+
                    navbar.setAttribute("onText", "false");
}
+
                }
}
+
            }
var footerTop = document.getElementById("footerWrapper").getBoundingClientRect().top;
+
            var footerTop = document.getElementById("footerWrapper").getBoundingClientRect().top;
var scrollbarBottom = document.getElementById("scrollbar-container").getBoundingClientRect().bottom;
+
            var scrollbarBottom = document.getElementById("scrollbar-container").getBoundingClientRect().bottom;
if (scrollbarBottom >= footerTop) {
+
            if (scrollbarBottom >= footerTop) {
if (document.getElementById("scrollbar-container").getAttribute("hiddenScroll") == "false") {
+
                if (document.getElementById("scrollbar-container").getAttribute("hiddenScroll") == "false") {
document.getElementById("scrollbar-container").setAttribute("hiddenScroll", "true");
+
                    document.getElementById("scrollbar-container").setAttribute("hiddenScroll", "true");
}
+
                }
} else {
+
            } else {
if (document.getElementById("scrollbar-container").getAttribute("hiddenScroll") == "true") {
+
                if (document.getElementById("scrollbar-container").getAttribute("hiddenScroll") == "true") {
document.getElementById("scrollbar-container").setAttribute("hiddenScroll", "false");
+
                    document.getElementById("scrollbar-container").setAttribute("hiddenScroll", "false");
}
+
                }
}
+
            }
}
+
        }
  
//---------------Scrollbar height---------------
+
        //---------------Scrollbar height---------------
function updateScrollbar() {
+
        function updateScrollbar() {
var winScroll = document.body.scrollTop || document.documentElement.scrollTop;
+
            var winScroll = document.body.scrollTop || document.documentElement.scrollTop;
var height = document.documentElement.scrollHeight - window.innerHeight;;
+
            var height = document.documentElement.scrollHeight - window.innerHeight;;
var scrolled = (winScroll / height) * 100;
+
            var scrolled = (winScroll / height) * 100;
document.getElementById("scrollbar").style.height = scrolled + "%";
+
            document.getElementById("scrollbar").style.height = scrolled + "%";
}
+
        }
  
//---------------Closing the menu and returning to default values---------------
+
        //---------------Closing the menu and returning to default values---------------
function closeMenu() {
+
        function closeMenu() {
var toggleable = document.querySelectorAll('.toggleable');
+
            var toggleable = document.querySelectorAll('.toggleable');
for (let item of toggleable) {
+
            for (let item of toggleable) {
item.classList.remove("active");
+
                item.classList.remove("active");
}
+
            }
document.getElementById("fixedOverlay").setAttribute("bg", "none");
+
            document.getElementById("fixedOverlay").setAttribute("bg", "none");
document.getElementById("appendable").classList.remove(currentChoice);
+
            document.getElementById("appendable").classList.remove(currentChoice);
currentChoice = null;
+
            document.querySelector(".hamb-wrapper").classList.remove("invisible");
const myNode = document.getElementById("appendable");
+
            currentChoice = null;
while (myNode.firstChild) {
+
            const myNode = document.getElementById("appendable");
myNode.removeChild(myNode.lastChild);
+
            while (myNode.firstChild) {
}
+
                myNode.removeChild(myNode.lastChild);
document.getElementById("bubbles-to-close").setAttribute("open", "false");
+
            }
checkNavbarPos();
+
            document.getElementById("bubbles-to-close").setAttribute("open", "false");
}
+
            checkNavbarPos();
  
function openSecBubble(link) {
+
        }
link.classList.add("active");
+
document.getElementById("appendable").classList.remove(currentChoice);
+
currentChoice = link.id;
+
document.getElementById("popup-next").classList.add("active");
+
var items = menuItems[currentChoice];
+
document.getElementById("appendable").classList.add(currentChoice)
+
let counter = 0;
+
for (const [key, value] of Object.entries(menuItems[currentChoice])) {
+
var node = document.createElement("li");
+
var nodeLink = document.createElement("a");
+
nodeLink.href = value.link;
+
nodeLink.innerHTML = value.name;
+
if (currentChoice = "project") {
+
counter++;
+
if (counter <= 5) node.classList.add('right-align');
+
}
+
node.appendChild(nodeLink);
+
document.getElementById("appendable").appendChild(node);
+
}
+
resizeBubble(link.id);
+
}
+
  
var openMenuEls = document.getElementsByClassName("menu-wrapper");
+
        function openSecBubble(link) {
for (let el of openMenuEls) {
+
            link.classList.add("active");
//---------------Clicking on menu sandwich/close button---------------
+
            document.getElementById("appendable").classList.remove(currentChoice);
el.addEventListener('click', function() {
+
            currentChoice = link.id;
//---------------If menu is open and close button is clicked, close menu---------------
+
            document.getElementById("popup-next").classList.add("active");
if (this.classList.contains("active")) {
+
            var items = menuItems[currentChoice];
closeMenu();
+
            document.getElementById("appendable").classList.add(currentChoice)
} else {
+
            let counter = 0;
document.getElementById("popup-main").classList.add("active");
+
            for (const [key, value] of Object.entries(menuItems[currentChoice])) {
this.classList.add("active");
+
                var node = document.createElement("li");
fxdOv = document.getElementById("fixedOverlay");
+
                var nodeLink = document.createElement("a");
fxdOv.setAttribute("bg", "dark");
+
                nodeLink.href = value.link;
document.getElementById("navbar").setAttribute("onText", "false");
+
                nodeLink.innerHTML = value.name;
document.getElementById("bubbles-to-close").setAttribute("open", "true");
+
                if (currentChoice = "project") {
if (fxdOv.classList.length != 0) {
+
                    counter++;
link = fxdOv.classList[0]
+
                    if (counter <= 5) node.classList.add('right-align');
openSecBubble(document.getElementById(link))
+
                }
}
+
                node.appendChild(nodeLink);
}
+
                document.getElementById("appendable").appendChild(node);
})
+
            }
}
+
            resizeBubble();
var currentChoice;
+
        }
var menuLinks = document.getElementsByClassName("main-choice");
+
for (let link of menuLinks) {
+
link.addEventListener('click', function() {
+
for (let lk of menuLinks) {
+
if (lk.classList.contains("active")) {
+
lk.classList.remove("active");
+
const myNode = document.getElementById("appendable");
+
while (myNode.firstChild) {
+
myNode.removeChild(myNode.lastChild);
+
}
+
}
+
}
+
openSecBubble(link)
+
})
+
}
+
  
$('#appendable li a').on("click", function() {
+
        var openMenuEls = document.getElementsByClassName("menu-wrapper");
closeMenu();
+
        for (let el of openMenuEls) {
})
+
            //---------------Clicking on menu sandwich/close button---------------
 +
            el.addEventListener('click', function() {
 +
                //---------------If menu is open and close button is clicked, close menu---------------
 +
                if (this.classList.contains("active")) {
 +
                    closeMenu();
 +
                } else {
 +
                    document.getElementById("popup-main").classList.add("active");
 +
                    this.classList.add("active");
 +
                    document.querySelector(".hamb-wrapper").classList.add("invisible");
 +
                    fxdOv = document.getElementById("fixedOverlay");
 +
                    fxdOv.setAttribute("bg", "dark");
 +
                    document.getElementById("navbar").setAttribute("onText", "false");
 +
                    document.getElementById("bubbles-to-close").setAttribute("open", "true");
 +
                    if (fxdOv.classList.length != 0) {
 +
                        link = fxdOv.classList[0]
 +
                        openSecBubble(document.getElementById(link))
 +
                    }
 +
                }
 +
            })
 +
        }
 +
        var currentChoice;
 +
        var menuLinks = document.getElementsByClassName("main-choice");
 +
        for (let link of menuLinks) {
 +
            link.addEventListener('mouseover', function() {
 +
                for (let lk of menuLinks) {
 +
                    if (lk.classList.contains("active")) {
 +
                        lk.classList.remove("active");
 +
                        const myNode = document.getElementById("appendable");
 +
                        while (myNode.firstChild) {
 +
                            myNode.removeChild(myNode.lastChild);
 +
                        }
 +
                    }
 +
                }
 +
                openSecBubble(link)
 +
            })
 +
        }
  
$(window).resize(function() {
+
        $('#appendable li a').on("click", function() {
resizeBubble();
+
            closeMenu();
});
+
        })
  
        function resizeBubble(currChoice) {
+
        $(window).resize(function() {
 +
            resizeBubble();
 +
        });
 +
 
 +
        function resizeBubble() {
 
             $(function() {
 
             $(function() {
 
                 var elementWidth = $("#appendable").width();
 
                 var elementWidth = $("#appendable").width();
 
                 var elementHeight = $("#appendable").height();
 
                 var elementHeight = $("#appendable").height();
 
                 var resizingConstant = (function() {
 
                 var resizingConstant = (function() {
                     if (currChoice == "hp") {
+
                     if (currentChoice == "hp") {
                         return 2
+
                         return 1.4
                     } else if (currChoice == "team") {
+
                     } else if (currentChoice == "team") {
                         return 1.8
+
                         return 1.7
                     } else if (currChoice == "parts") {
+
                     } else if (currentChoice == "parts") {
                         return 1.35
+
                         return 1.45
 
                     } else {
 
                     } else {
 
                         return 1.15
 
                         return 1.15
Line 153: Line 156:
 
             })
 
             })
 
         }
 
         }
document.getElementById("bubbles-to-close").addEventListener('click', function() {
+
        document.getElementById("bubbles-to-close").addEventListener('click', function() {
var isOpen = document.getElementById("popup-main");
+
            var isOpen = document.getElementById("popup-main");
if (isOpen.classList.contains("active")) {
+
            if (isOpen.classList.contains("active")) {
closeMenu();
+
                closeMenu();
}
+
            }
})
+
        })
var menuItems = {
+
        var menuItems = {
project: {
+
            project: {
desc: {
+
                desc: {
name: "Description",
+
                    name: "Description",
link: "./Description"
+
                    link: "./Description"
},
+
                },
imp: {
+
                imp: {
name: "Implementation",
+
                    name: "Implementation",
link: "./Implementation",
+
                    link: "./Implementation",
},
+
                },
des: {
+
                des: {
name: "Design",
+
                    name: "Design",
link: "./Design",
+
                    link: "./Design",
},
+
                },
exp: {
+
                exp: {
name: "Experiments",
+
                    name: "Experiments",
link: "./Experiments",
+
                    link: "./Experiments",
},
+
                },
res: {
+
                res: {
name: "Results",
+
                    name: "Results",
link: "./Results",
+
                    link: "./Results",
},
+
                },
eng: {
+
                eng: {
name: "Engineering",
+
                    name: "Engineering",
link: "./Engineering",
+
                    link: "./Engineering",
},
+
                },
pof: {
+
                pof: {
name: "Proof of Concept",
+
                    name: "Proof of Concept",
link: "./ProofOfConcept",
+
                    link: "./ProofOfConcept",
},
+
                },
mod: {
+
                mod: {
name: "Model",
+
                    name: "Model",
link: "./Model",
+
                    link: "./Model",
},
+
                },
sof: {
+
                sof: {
name: "Software",
+
                    name: "Software",
link: "./Software",
+
                    link: "./Software",
},
+
                },
con: {
+
                con: {
name: "Contribution",
+
                    name: "Contribution",
link: "./Contribution",
+
                    link: "./Contribution",
}
+
                }
},
+
            },
parts: {
+
            parts: {
par: {
+
                par: {
name: "Parts",
+
                    name: "Parts",
link: "./Parts",
+
                    link: "./Parts",
},
+
                },
col: {
+
                col: {
name: "Parts Collection",
+
                    name: "Parts Collection",
link: "./PartsCollection",
+
                    link: "./PartsCollection",
}
+
                }
},
+
            },
hp: {
+
            hp: {
int: {
+
                int: {
name: "Integrated<br>Human Practices",
+
                    name: "Integrated<br>Human Practices",
link: "./Integrated",
+
                    link: "./Integrated",
},
+
                },
col: {
+
                col: {
name: "Education &<br>Public Engagement",
+
                    name: "Education &<br>Public Engagement",
link: "./Education",
+
                    link: "./Education",
}
+
                }
},
+
            },
team: {
+
            team: {
members: {
+
                members: {
name: "Members",
+
                    name: "Members",
link: "./Team",
+
                    link: "./Team",
},
+
                },
coll: {
+
                coll: {
name: "Collaborations",
+
                    name: "Collaborations",
link: "./Collaborations",
+
                    link: "./Collaborations",
},
+
                },
att: {
+
                att: {
name: "Attributions",
+
                    name: "Attributions",
link: "./Attributions",
+
                    link: "./Attributions",
}
+
                }
}
+
            }
}
+
        }

Revision as of 20:18, 19 October 2020

//---------------Checking if the page is content page---------------

       var textSection = null;
       var navbar = document.getElementById("navbar");
       window.addEventListener('load', function() {
           textSection = $(".elevate-navbar");
       })
       window.addEventListener('scroll', function() {
           updateScrollbar();
           checkNavbarPos();
       });


       function checkNavbarPos() {
           if (textSection != null) {
               var navbarTop = navbar.getBoundingClientRect().top;
               var mainTagTop = textSection.getBoundingClientRect().top;
               if (navbarTop >= mainTagTop) {
                   if (document.getElementById("bubbles-to-close").getAttribute("open") != true) navbar.setAttribute("onText", "true");
               } else {
                   navbar.setAttribute("onText", "false");
               }
           }
           var footerTop = document.getElementById("footerWrapper").getBoundingClientRect().top;
           var scrollbarBottom = document.getElementById("scrollbar-container").getBoundingClientRect().bottom;
           if (scrollbarBottom >= footerTop) {
               if (document.getElementById("scrollbar-container").getAttribute("hiddenScroll") == "false") {
                   document.getElementById("scrollbar-container").setAttribute("hiddenScroll", "true");
               }
           } else {
               if (document.getElementById("scrollbar-container").getAttribute("hiddenScroll") == "true") {
                   document.getElementById("scrollbar-container").setAttribute("hiddenScroll", "false");
               }
           }
       }
       //---------------Scrollbar height---------------
       function updateScrollbar() {
           var winScroll = document.body.scrollTop || document.documentElement.scrollTop;
           var height = document.documentElement.scrollHeight - window.innerHeight;;
           var scrolled = (winScroll / height) * 100;
           document.getElementById("scrollbar").style.height = scrolled + "%";
       }
       //---------------Closing the menu and returning to default values---------------
       function closeMenu() {
           var toggleable = document.querySelectorAll('.toggleable');
           for (let item of toggleable) {
               item.classList.remove("active");
           }
           document.getElementById("fixedOverlay").setAttribute("bg", "none");
           document.getElementById("appendable").classList.remove(currentChoice);
           document.querySelector(".hamb-wrapper").classList.remove("invisible");
           currentChoice = null;
           const myNode = document.getElementById("appendable");
           while (myNode.firstChild) {
               myNode.removeChild(myNode.lastChild);
           }
           document.getElementById("bubbles-to-close").setAttribute("open", "false");
           checkNavbarPos();
       }
       function openSecBubble(link) {
           link.classList.add("active");
           document.getElementById("appendable").classList.remove(currentChoice);
           currentChoice = link.id;
           document.getElementById("popup-next").classList.add("active");
           var items = menuItems[currentChoice];
           document.getElementById("appendable").classList.add(currentChoice)
           let counter = 0;
           for (const [key, value] of Object.entries(menuItems[currentChoice])) {
               var node = document.createElement("li");
               var nodeLink = document.createElement("a");
               nodeLink.href = value.link;
               nodeLink.innerHTML = value.name;
               if (currentChoice = "project") {
                   counter++;
                   if (counter <= 5) node.classList.add('right-align');
               }
               node.appendChild(nodeLink);
               document.getElementById("appendable").appendChild(node);
           }
           resizeBubble();
       }
       var openMenuEls = document.getElementsByClassName("menu-wrapper");
       for (let el of openMenuEls) {
           //---------------Clicking on menu sandwich/close button---------------
           el.addEventListener('click', function() {
               //---------------If menu is open and close button is clicked, close menu---------------
               if (this.classList.contains("active")) {
                   closeMenu();
               } else {
                   document.getElementById("popup-main").classList.add("active");
                   this.classList.add("active");
                   document.querySelector(".hamb-wrapper").classList.add("invisible");
                   fxdOv = document.getElementById("fixedOverlay");
                   fxdOv.setAttribute("bg", "dark");
                   document.getElementById("navbar").setAttribute("onText", "false");
                   document.getElementById("bubbles-to-close").setAttribute("open", "true");
                   if (fxdOv.classList.length != 0) {
                       link = fxdOv.classList[0]
                       openSecBubble(document.getElementById(link))
                   }
               }
           })
       }
       var currentChoice;
       var menuLinks = document.getElementsByClassName("main-choice");
       for (let link of menuLinks) {
           link.addEventListener('mouseover', function() {
               for (let lk of menuLinks) {
                   if (lk.classList.contains("active")) {
                       lk.classList.remove("active");
                       const myNode = document.getElementById("appendable");
                       while (myNode.firstChild) {
                           myNode.removeChild(myNode.lastChild);
                       }
                   }
               }
               openSecBubble(link)
           })
       }
       $('#appendable li a').on("click", function() {
           closeMenu();
       })
       $(window).resize(function() {
           resizeBubble();
       });
       function resizeBubble() {
           $(function() {
               var elementWidth = $("#appendable").width();
               var elementHeight = $("#appendable").height();
               var resizingConstant = (function() {
                   if (currentChoice == "hp") {
                       return 1.4
                   } else if (currentChoice == "team") {
                       return 1.7
                   } else if (currentChoice == "parts") {
                       return 1.45
                   } else {
                       return 1.15
                   }
               })();
               if (elementHeight > elementWidth) {
                   $("#bubbles #popup-next").css("height", elementHeight * resizingConstant);
                   $("#bubbles #popup-next").css("width", elementHeight * resizingConstant);
               } else {
                   $("#bubbles #popup-next").css("height", elementWidth * resizingConstant);
                   $("#bubbles #popup-next").css("width", elementWidth * resizingConstant);
               }
           })
       }
       document.getElementById("bubbles-to-close").addEventListener('click', function() {
           var isOpen = document.getElementById("popup-main");
           if (isOpen.classList.contains("active")) {
               closeMenu();
           }
       })
       var menuItems = {
           project: {
               desc: {
                   name: "Description",
                   link: "./Description"
               },
               imp: {
                   name: "Implementation",
                   link: "./Implementation",
               },
               des: {
                   name: "Design",
                   link: "./Design",
               },
               exp: {
                   name: "Experiments",
                   link: "./Experiments",
               },
               res: {
                   name: "Results",
                   link: "./Results",
               },
               eng: {
                   name: "Engineering",
                   link: "./Engineering",
               },
               pof: {
                   name: "Proof of Concept",
                   link: "./ProofOfConcept",
               },
               mod: {
                   name: "Model",
                   link: "./Model",
               },
               sof: {
                   name: "Software",
                   link: "./Software",
               },
               con: {
                   name: "Contribution",
                   link: "./Contribution",
               }
           },
           parts: {
               par: {
                   name: "Parts",
                   link: "./Parts",
               },
               col: {
                   name: "Parts Collection",
                   link: "./PartsCollection",
               }
           },
           hp: {
               int: {
                   name: "Integrated
Human Practices", link: "./Integrated", }, col: { name: "Education &
Public Engagement", link: "./Education", } }, team: { members: { name: "Members", link: "./Team", }, coll: { name: "Collaborations", link: "./Collaborations", }, att: { name: "Attributions", link: "./Attributions", } } }