2019-09-30 15:38:41 +03:00
|
|
|
/*
|
2019-12-31 18:17:27 +03:00
|
|
|
* This script make #search-result-wrapper switch to unloaded or shown automatically.
|
2019-09-30 15:38:41 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
|
2021-01-23 10:07:18 +03:00
|
|
|
const btnSbTrigger = $("#sidebar-trigger");
|
|
|
|
const btnSearchTrigger = $("#search-trigger");
|
|
|
|
const btnCancel = $("#search-cancel");
|
|
|
|
const btnClear = $("#search-cleaner");
|
2019-09-30 15:38:41 +03:00
|
|
|
|
2021-01-23 10:07:18 +03:00
|
|
|
const main = $("#main");
|
|
|
|
const topbarTitle = $("#topbar-title");
|
|
|
|
const searchWrapper = $("#search-wrapper");
|
|
|
|
const resultWrapper = $("#search-result-wrapper");
|
|
|
|
const results = $("#search-results");
|
|
|
|
const input = $("#search-input");
|
|
|
|
const hints = $("#search-hints");
|
2019-12-31 18:17:27 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*--- Actions in small screens (Sidebar unloaded) ---*/
|
|
|
|
|
2021-01-23 10:07:18 +03:00
|
|
|
const scrollBlocker = (function () {
|
|
|
|
let offset = 0;
|
2019-12-31 18:17:27 +03:00
|
|
|
return {
|
2020-08-19 07:26:45 +03:00
|
|
|
block() {
|
2019-12-31 18:17:27 +03:00
|
|
|
offset = $(window).scrollTop();
|
|
|
|
},
|
2020-08-19 07:26:45 +03:00
|
|
|
release() {
|
|
|
|
$("html,body").scrollTop(offset);
|
2019-12-31 18:17:27 +03:00
|
|
|
},
|
2020-08-19 07:26:45 +03:00
|
|
|
getOffset() {
|
2019-12-31 18:17:27 +03:00
|
|
|
return offset;
|
|
|
|
}
|
2020-08-19 07:26:45 +03:00
|
|
|
};
|
|
|
|
}());
|
2019-12-31 18:17:27 +03:00
|
|
|
|
2021-01-23 10:07:18 +03:00
|
|
|
const mobileSearchBar = (function () {
|
2019-12-31 18:17:27 +03:00
|
|
|
return {
|
2020-08-19 07:26:45 +03:00
|
|
|
on() {
|
|
|
|
btnSbTrigger.addClass("unloaded");
|
|
|
|
topbarTitle.addClass("unloaded");
|
|
|
|
btnSearchTrigger.addClass("unloaded");
|
|
|
|
searchWrapper.addClass("d-flex");
|
|
|
|
btnCancel.addClass("loaded");
|
2019-12-31 18:17:27 +03:00
|
|
|
},
|
2020-08-19 07:26:45 +03:00
|
|
|
off() {
|
|
|
|
btnCancel.removeClass("loaded");
|
|
|
|
searchWrapper.removeClass("d-flex");
|
|
|
|
btnSbTrigger.removeClass("unloaded");
|
|
|
|
topbarTitle.removeClass("unloaded");
|
|
|
|
btnSearchTrigger.removeClass("unloaded");
|
2019-12-31 18:17:27 +03:00
|
|
|
}
|
2020-08-19 07:26:45 +03:00
|
|
|
};
|
|
|
|
}());
|
2019-12-31 18:17:27 +03:00
|
|
|
|
2021-01-23 10:07:18 +03:00
|
|
|
const resultSwitch = (function () {
|
|
|
|
let visible = false;
|
2019-12-31 18:17:27 +03:00
|
|
|
|
|
|
|
return {
|
2020-08-19 07:26:45 +03:00
|
|
|
on() {
|
2021-01-23 10:07:18 +03:00
|
|
|
if (!visible) {
|
2020-08-19 07:26:45 +03:00
|
|
|
resultWrapper.removeClass("unloaded");
|
|
|
|
main.addClass("hidden");
|
2019-12-31 18:17:27 +03:00
|
|
|
|
2021-01-23 10:07:18 +03:00
|
|
|
visible = true;
|
2019-12-31 18:17:27 +03:00
|
|
|
scrollBlocker.block();
|
|
|
|
}
|
|
|
|
},
|
2020-08-19 07:26:45 +03:00
|
|
|
off() {
|
2021-01-23 10:07:18 +03:00
|
|
|
if (visible) {
|
2019-12-31 18:17:27 +03:00
|
|
|
results.empty();
|
2020-08-19 07:26:45 +03:00
|
|
|
if (hints.hasClass("unloaded")) {
|
|
|
|
hints.removeClass("unloaded");
|
2019-12-31 18:17:27 +03:00
|
|
|
}
|
2020-08-19 07:26:45 +03:00
|
|
|
resultWrapper.addClass("unloaded");
|
2021-01-23 08:21:40 +03:00
|
|
|
btnClear.removeClass("visible");
|
2020-08-19 07:26:45 +03:00
|
|
|
main.removeClass("hidden");
|
2019-12-31 18:17:27 +03:00
|
|
|
|
2020-08-19 07:26:45 +03:00
|
|
|
input.val("");
|
2021-01-23 10:07:18 +03:00
|
|
|
visible = false;
|
2019-12-31 18:17:27 +03:00
|
|
|
|
|
|
|
scrollBlocker.release();
|
|
|
|
}
|
|
|
|
},
|
2021-01-23 10:07:18 +03:00
|
|
|
isVisible() {
|
|
|
|
return visible;
|
2019-12-31 18:17:27 +03:00
|
|
|
}
|
2020-08-19 07:26:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}());
|
2019-09-30 15:38:41 +03:00
|
|
|
|
|
|
|
|
2019-12-31 18:17:27 +03:00
|
|
|
function isMobileView() {
|
2020-08-19 07:26:45 +03:00
|
|
|
return btnCancel.hasClass("loaded");
|
2019-12-31 18:17:27 +03:00
|
|
|
}
|
2019-09-30 15:38:41 +03:00
|
|
|
|
2019-12-31 18:17:27 +03:00
|
|
|
btnSearchTrigger.click(function() {
|
|
|
|
mobileSearchBar.on();
|
|
|
|
resultSwitch.on();
|
|
|
|
input.focus();
|
2019-09-30 15:38:41 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
btnCancel.click(function() {
|
2019-12-31 18:17:27 +03:00
|
|
|
mobileSearchBar.off();
|
|
|
|
resultSwitch.off();
|
2019-09-30 15:38:41 +03:00
|
|
|
});
|
|
|
|
|
2019-12-31 18:17:27 +03:00
|
|
|
input.focus(function() {
|
2020-08-19 07:26:45 +03:00
|
|
|
searchWrapper.addClass("input-focus");
|
2019-12-31 18:17:27 +03:00
|
|
|
});
|
2019-09-30 15:38:41 +03:00
|
|
|
|
2019-12-31 18:17:27 +03:00
|
|
|
input.focusout(function() {
|
2020-08-19 07:26:45 +03:00
|
|
|
searchWrapper.removeClass("input-focus");
|
2019-12-31 18:17:27 +03:00
|
|
|
});
|
2019-09-30 15:38:41 +03:00
|
|
|
|
2020-08-19 07:26:45 +03:00
|
|
|
input.on("keyup", function(e) {
|
|
|
|
if (e.keyCode === 8 && input.val() === "") {
|
2019-12-31 18:17:27 +03:00
|
|
|
if (!isMobileView()) {
|
|
|
|
resultSwitch.off();
|
|
|
|
} else {
|
2020-08-19 07:26:45 +03:00
|
|
|
hints.removeClass("unloaded");
|
2019-12-31 18:17:27 +03:00
|
|
|
}
|
|
|
|
} else {
|
2020-08-19 07:26:45 +03:00
|
|
|
if (input.val() !== "") {
|
2019-12-31 18:17:27 +03:00
|
|
|
resultSwitch.on();
|
|
|
|
|
2020-08-19 07:26:45 +03:00
|
|
|
if (!btnClear.hasClass("visible")) {
|
2021-01-23 08:21:40 +03:00
|
|
|
btnClear.addClass("visible");
|
2019-12-31 18:17:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isMobileView()) {
|
2020-08-19 07:26:45 +03:00
|
|
|
hints.addClass("unloaded");
|
2019-12-31 18:17:27 +03:00
|
|
|
}
|
|
|
|
}
|
2019-09-30 15:38:41 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-08-19 07:26:45 +03:00
|
|
|
btnClear.on("click", function() {
|
|
|
|
input.val("");
|
2019-12-31 18:17:27 +03:00
|
|
|
if (isMobileView()) {
|
2020-08-19 07:26:45 +03:00
|
|
|
hints.removeClass("unloaded");
|
2019-12-31 18:17:27 +03:00
|
|
|
results.empty();
|
|
|
|
} else {
|
|
|
|
resultSwitch.off();
|
2019-09-30 15:38:41 +03:00
|
|
|
}
|
2019-12-31 18:17:27 +03:00
|
|
|
input.focus();
|
2021-01-23 08:21:40 +03:00
|
|
|
btnClear.removeClass("visible");
|
2019-09-30 15:38:41 +03:00
|
|
|
});
|
|
|
|
|
2020-08-19 07:26:45 +03:00
|
|
|
});
|