Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

Scroll to content after ajax load

givanz2f2718ff663e
diff --git a/public/js/app.js b/public/js/app.js
index d107838..13d57a0 100755
--- a/public/js/app.js
+++ b/public/js/app.js
@@ -662,7 +662,7 @@ function loadAjax(url, selector, callback = null, params = {}, method = "get") {
}
if (!url) url = window.location.href;
- console.log(selector);
+
fetch(url, options).
then((response) => {
if (!response.ok) { throw new Error(response) }
@@ -688,6 +688,8 @@ function loadAjax(url, selector, callback = null, params = {}, method = "get") {
currentElement.replaceWith(newElement);
}
}
+
+ if (callback) callback();
}
window.dispatchEvent(new CustomEvent("vvveb.loadUrl", {detail: {url, selector}}));
@@ -704,7 +706,13 @@ document.addEventListener("click", function (e) {
if (!url) return;
- loadAjax(url, selector, () => window.history.pushState({url, selector}, null));
+ loadAjax(url, selector, () => {
+ if (element.dataset.scroll) {
+ let target = document.querySelector(selector);
+ target.scrollIntoView({behavior: "smooth", block: element.dataset.scroll ?? "center", inline: "center"});
+ }
+ window.history.pushState({url, selector}, null);
+ });
e.preventDefault();
}
diff --git a/public/js/filter.js b/public/js/filter.js
index 0476d85..a2fe776 100644
--- a/public/js/filter.js
+++ b/public/js/filter.js
@@ -73,8 +73,12 @@ document.addEventListener("click", (event) => {
if (target) {
let url = target.href;
let selector = "#site-content";
- loadAjax(url, selector);
+ loadAjax(url, selector, () => {
+ //let target = document.querySelector(selector);
+ let target = document.querySelector("body");
+ target.scrollIntoView({behavior: "smooth", block: "start", inline: "start"});
+ });
window.history.pushState({url, selector}, null, url);
event.preventDefault();
}
-});
\ No newline at end of file
+});