mirror of
https://github.com/neosubhamoy/neosubhamoy-portfolio.git
synced 2025-12-20 01:09:35 +05:30
(fixed): search and share window overlapping when activating both
This commit is contained in:
@@ -16,7 +16,7 @@ const qrCode = document.getElementById("pageqrcode");
|
|||||||
const linkInput = document.getElementById("pageurlinput");
|
const linkInput = document.getElementById("pageurlinput");
|
||||||
const embedCode = document.getElementById("embedcodetag");
|
const embedCode = document.getElementById("embedcodetag");
|
||||||
const basePath = document.getElementById('phpHostBasePath').dataset.basePath;
|
const basePath = document.getElementById('phpHostBasePath').dataset.basePath;
|
||||||
let lastScrollTop = 0;
|
let lastScrollTop = 0, isSearchActive = false, isShareActive = false;
|
||||||
|
|
||||||
window.addEventListener("scroll", function () {
|
window.addEventListener("scroll", function () {
|
||||||
const st = window.pageYOffset || document.documentElement.scrollTop;
|
const st = window.pageYOffset || document.documentElement.scrollTop;
|
||||||
@@ -38,6 +38,7 @@ window.addEventListener("scroll", function () {
|
|||||||
|
|
||||||
// function to open floating search window
|
// function to open floating search window
|
||||||
function activate_search() {
|
function activate_search() {
|
||||||
|
isSearchActive = true;
|
||||||
floatingBar.classList.remove("floatingbar-click-slide-down");
|
floatingBar.classList.remove("floatingbar-click-slide-down");
|
||||||
floatingBar.classList.add("floatingbar-click-slide-up");
|
floatingBar.classList.add("floatingbar-click-slide-up");
|
||||||
searchBar.classList.remove("searchbar-click-decrease-width");
|
searchBar.classList.remove("searchbar-click-decrease-width");
|
||||||
@@ -67,17 +68,30 @@ function close_search() {
|
|||||||
windowWrapper.classList.remove("flotingbar-window-wrapper-show");
|
windowWrapper.classList.remove("flotingbar-window-wrapper-show");
|
||||||
windowWrapper.classList.add("hidden");
|
windowWrapper.classList.add("hidden");
|
||||||
searchWin.classList.remove("floatingsearch-window-show");
|
searchWin.classList.remove("floatingsearch-window-show");
|
||||||
|
isSearchActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// when the search icon is clicked
|
// when the search icon is clicked
|
||||||
searchBar.addEventListener("click", function () {
|
searchBar.addEventListener("click", function () {
|
||||||
activate_search();
|
if(!isShareActive) {
|
||||||
|
activate_search();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
close_share();
|
||||||
|
activate_search();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// when ALT + K shortcut key is pressed
|
// when ALT + K shortcut key is pressed
|
||||||
document.addEventListener("keydown", function(event) {
|
document.addEventListener("keydown", function(event) {
|
||||||
if (event.altKey && event.key === "k") {
|
if (event.altKey && event.key === "k") {
|
||||||
activate_search();
|
if(!isShareActive) {
|
||||||
|
activate_search();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
close_share();
|
||||||
|
activate_search();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -89,8 +103,12 @@ closeBtn.addEventListener("click", function () {
|
|||||||
// when ESC key is pressed
|
// when ESC key is pressed
|
||||||
document.addEventListener("keydown", function(event) {
|
document.addEventListener("keydown", function(event) {
|
||||||
if (event.key === "Escape") {
|
if (event.key === "Escape") {
|
||||||
close_search();
|
if(isSearchActive) {
|
||||||
close_share();
|
close_search();
|
||||||
|
}
|
||||||
|
else if(isShareActive) {
|
||||||
|
close_share();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -311,6 +329,7 @@ searchInput.addEventListener('input', function() {
|
|||||||
|
|
||||||
// function to open the share window
|
// function to open the share window
|
||||||
function activate_share() {
|
function activate_share() {
|
||||||
|
isShareActive = true;
|
||||||
//create qrcode of the current page link
|
//create qrcode of the current page link
|
||||||
qrCode.src = "https://api.qrserver.com/v1/create-qr-code/?data=" + window.location.href + "&color=38BDF8&bgcolor=0F172A";
|
qrCode.src = "https://api.qrserver.com/v1/create-qr-code/?data=" + window.location.href + "&color=38BDF8&bgcolor=0F172A";
|
||||||
//change pageUrlInput value to current page
|
//change pageUrlInput value to current page
|
||||||
@@ -333,10 +352,17 @@ function close_share() {
|
|||||||
shareBtn.classList.remove("hidden");
|
shareBtn.classList.remove("hidden");
|
||||||
shareWin.classList.remove("floatingshare-window-show");
|
shareWin.classList.remove("floatingshare-window-show");
|
||||||
document.body.classList.remove("overflow-hidden");
|
document.body.classList.remove("overflow-hidden");
|
||||||
|
isShareActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
shareBtn.addEventListener("click", function () {
|
shareBtn.addEventListener("click", function () {
|
||||||
activate_share();
|
if(!isSearchActive) {
|
||||||
|
activate_share();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
close_search();
|
||||||
|
activate_share();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
shareCloseBtn.addEventListener("click", function () {
|
shareCloseBtn.addEventListener("click", function () {
|
||||||
@@ -346,7 +372,13 @@ shareCloseBtn.addEventListener("click", function () {
|
|||||||
// when ALT + L shortcut key is pressed
|
// when ALT + L shortcut key is pressed
|
||||||
document.addEventListener("keydown", function(event) {
|
document.addEventListener("keydown", function(event) {
|
||||||
if (event.altKey && event.key === "l") {
|
if (event.altKey && event.key === "l") {
|
||||||
|
if(!isSearchActive) {
|
||||||
activate_share();
|
activate_share();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
close_search();
|
||||||
|
activate_share();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user