Skip to content

armgit / Vvveb

Public Imported from GitHub
0

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

Set theme ajax config defaults only if they are not already set to allow easier override

givanzf27de29cc038
diff --git a/public/js/app.js b/public/js/app.js
index 7ac1b72..8133f0f 100755
--- a/public/js/app.js
+++ b/public/js/app.js
@@ -19,7 +19,8 @@
* https://github.com/givanz/Vvveb
*/
-if (VvvebTheme === undefined) var VvvebTheme = {};
+window.VvvebTheme = window.VvvebTheme || {ajax:{}};
+window.VvvebApp = window.VvvebApp || {};
VvvebTheme.Ajax = {
call: function(url, parameters, element, selector, callback, requestType = "POST") {
@@ -829,12 +830,11 @@ function loadAjax(url, selector, callback = null, params = {}, method = "get") {
}
-VvvebTheme.ajax = {
- selector:"a[data-url], a[data-page-url], a[data-v-url], a[data-v-menu-item-url], a[data-v-post-url], a[data-v-product-url], a[data-v-cat-url], a[data-v-archive-url], a[data-v-admin-url], a[data-v-post-author-url], a[data-v-breadcrumb-item-url], a[data-v-categories-cat-url], a[data-v-cart-product-url]",
- siteContainer:["#site-content", "body > section"],
- scrollContainer:"body",
- skipUrl:[]
-}
+VvvebTheme.ajax.selector = VvvebTheme.ajax.selector || "a[data-url], a[data-page-url], a[data-v-url], a[data-v-menu-item-url], a[data-v-post-url], a[data-v-product-url], a[data-v-cat-url], a[data-v-archive-url], a[data-v-admin-url], a[data-v-post-author-url], a[data-v-breadcrumb-item-url], a[data-v-categories-cat-url], a[data-v-cart-product-url]";
+VvvebTheme.ajax.siteContainer = VvvebTheme.ajax.siteContainer || ["#site-content", "body > section"];
+VvvebTheme.ajax.scrollContainer = VvvebTheme.ajax.scrollContainer || "body";
+VvvebTheme.ajax.skipUrl = VvvebTheme.ajax.skipUrl || [];
+
if (!isEditor()) {
document.addEventListener("click", function (e) {
@@ -847,12 +847,12 @@ if (!isEditor()) {
|| (VvvebTheme.ajax.skipUrl.length && (VvvebTheme.ajax.skipUrl.includes(url) || VvvebTheme.ajax.skipUrl.includes(window.location.pathname)))
) return;
- let selector = element.dataset.selector ?? VvvebTheme.ajax.siteContainer;
+ let selector = element.dataset.selector || VvvebTheme.ajax.siteContainer;
loadAjax(url, selector, () => {
//if (element.dataset.scroll) {
let target = document.querySelector(VvvebTheme.ajax.scrollContainer);
- let scrollTo = element.dataset.scroll ?? (selector == VvvebTheme.ajax.siteContainer ? "start" : "center");
+ let scrollTo = element.dataset.scroll || (selector == VvvebTheme.ajax.siteContainer ? "start" : "center");
target.scrollIntoView({behavior: "smooth", block: scrollTo, inline: scrollTo});
//}
window.history.pushState({url, selector}, null, url);
diff --git a/public/js/app/theme.js b/public/js/app/theme.js
index 2eb1d3f..af7411c 100644
--- a/public/js/app/theme.js
+++ b/public/js/app/theme.js
@@ -2,6 +2,9 @@
* Sticky navbar
*
*/
+
+window.VvvebTheme = window.VvvebTheme || {ajax:{}};
+window.VvvebApp = window.VvvebApp || {};
// When the user scrolls the page, execute navbarSticky
window.onscroll = function() {navbarSticky()};
@@ -275,13 +278,13 @@ function afterPageLoad() {
//theme ajax configuration
//include elements that will be updated on ajax calls, include body > section to trigger whole page update if sections mismatch between different page structures
-VvvebTheme.ajax.siteContainer = ["#site-content", ".inner-page-hero", "body > section", "body > nav"];
-VvvebTheme.ajax.progressStatus = updateProgressStatus;
-VvvebTheme.ajax.afterLoad = afterPageLoad;
+VvvebTheme.ajax.siteContainer = VvvebTheme.ajax.siteContainer || ["#site-content", ".inner-page-hero", "body > section", "body > nav"];
+VvvebTheme.ajax.progressStatus = VvvebTheme.ajax.progressStatus || updateProgressStatus;
+VvvebTheme.ajax.afterLoad = VvvebTheme.ajax.afterLoad || afterPageLoad;
//include posts, product and menu items for ajax
//VvvebTheme.ajax.selector = "a[data-url], a[data-page-url], a[data-v-url], a[data-v-menu-item-url], a[data-v-post-url], a[data-v-product-url], a[data-v-cat-url], a[data-v-archive-url], a[data-v-admin-url], a[data-v-post-author-url], a[data-v-breadcrumb-item-url], a[data-v-categories-cat-url], a[data-v-cart-product-url]";
//skip home for dark hero and contact form for google js code
-VvvebTheme.ajax.skipUrl = ["/checkout"/*, "/page/contact"*/];
+VvvebTheme.ajax.skipUrl = (VvvebTheme.ajax.skipUrl && VvvebTheme.ajax.skipUrl?.length) || ["/checkout"/*, "/page/contact"*/];
//image lightbox
if (typeof GLightbox !== 'undefined') {