PageSourceSearch

https://zuomod.com/wp-content/mu-plugins/helpers/route-visible-container.js?ver=94dd45d7

js zuomod.com collected 2026-10-03 21:26:51 UTC 4,382 bytes, 103 lines download raw bytes

1/**
2 * Route-visible container:
3 * - If data-wiz-show-only-path is set: visible only when path matches (optional child prefix match).
4 * - If that attribute is omitted/empty: visible on all paths unless hide rules apply.
5 * - data-wiz-hide-on-path: hide when path matches (optional data-wiz-exclude-children).
6 * - data-wiz-auth-visibility: optional prelogin | postlogin (based on the UserDetails cookie).
7 * Used by Elementor "Route visibility". Manual: wiz-route-visible-container + data attributes.
8 */
9(function () {
10    'use strict';
11
12    const CONTAINER_SELECTOR = '.wiz-route-visible-container';
13    const DATA_ATTR_PATH = 'data-wiz-show-only-path';
14    const DATA_ATTR_CHILDREN = 'data-wiz-include-children';
15    const DATA_ATTR_EXCLUDE_PATH = 'data-wiz-hide-on-path';
16    const DATA_ATTR_EXCLUDE_CHILDREN = 'data-wiz-exclude-children';
17    const DATA_ATTR_AUTH = 'data-wiz-auth-visibility';
18    const CLASS_AUTH_RESOLVED = 'wiz-auth-resolved';
19
20    function getCurrentPath() {
21        const pathname = typeof window.location !== 'undefined' ? window.location.pathname : '';
22        return pathname.replace(/^\/+|\/+$/g, '');
23    }
24
25    function parseAllowedPaths(value) {
26        if (!value || typeof value !== 'string') return [];
27        return value.split(',').map((p) => p.replace(/^\/+|\/+$/g, '').trim()).filter(Boolean);
28    }
29
30    function pathMatches(currentPath, allowedPaths, includeChildren) {
31        if (!currentPath || !allowedPaths.length) return false;
32        for (const p of allowedPaths) {
33            if (currentPath === p) return true;
34            if (includeChildren && p.length > 0 && currentPath.startsWith(`${p}/`)) return true;
35        }
36        return false;
37    }
38
39    function isWizLoggedIn() {
40        return document.cookie.split(';').some((c) => c.trim().indexOf('UserDetails=') === 0);
41    }
42
43    function applyVisibility() {
44        const currentPath = getCurrentPath();
45        const loggedIn = isWizLoggedIn();
46        const containers = document.querySelectorAll(CONTAINER_SELECTOR);
47
48        Array.prototype.forEach.call(containers, (el) => {
49            const raw = el.getAttribute(DATA_ATTR_PATH);
50            const allowedPaths = parseAllowedPaths(raw);
51            const includeChildren = el.getAttribute(DATA_ATTR_CHILDREN) === 'yes';
52            const hasShowRule = allowedPaths.length > 0;
53            const matchesAllow = !hasShowRule || pathMatches(currentPath, allowedPaths, includeChildren);
54
55            const rawExclude = el.getAttribute(DATA_ATTR_EXCLUDE_PATH);
56            const excludedPaths = parseAllowedPaths(rawExclude);
57            const excludeChildren = el.getAttribute(DATA_ATTR_EXCLUDE_CHILDREN) === 'yes';
58            const matchesExclude = excludedPaths.length > 0
59                && pathMatches(currentPath, excludedPaths, excludeChildren);
60
61            const authMode = el.getAttribute(DATA_ATTR_AUTH) || 'all';
62            let authAllowed = true;
63            if (authMode === 'prelogin') authAllowed = !loggedIn;
64            else if (authMode === 'postlogin') authAllowed = loggedIn;
65
66            const show = matchesAllow && !matchesExclude && authAllowed;
67            el.style.display = show ? '' : 'none';
68            if (el.hasAttribute(DATA_ATTR_AUTH)) {
69                el.classList.add(CLASS_AUTH_RESOLVED);
70            }
71        });
72    }
73
74    function resolveAuthFallback() {
75        const unresolvedNodes = document.querySelectorAll(
76            `${CONTAINER_SELECTOR}[${DATA_ATTR_AUTH}="prelogin"]:not(.${CLASS_AUTH_RESOLVED}),`
77            + `${CONTAINER_SELECTOR}[${DATA_ATTR_AUTH}="postlogin"]:not(.${CLASS_AUTH_RESOLVED})`
78        );
79        for (const node of unresolvedNodes) {
80            node.classList.add(CLASS_AUTH_RESOLVED);
81        }
82    }
83
84    function init() {
85        applyVisibility();
86
87        window.addEventListener('popstate', applyVisibility);
88        if (window.navigation && typeof window.navigation.addEventListener === 'function') {
89            window.navigation.addEventListener('navigate', () => {
90                setTimeout(applyVisibility, 0);
91            });
92        }
93
94        // Failsafe: if resolution logic breaks, avoid permanent hidden auth-gated blocks.
95        setTimeout(resolveAuthFallback, 1000);
96    }
97
98    if (document.readyState === 'loading') {
99        document.addEventListener('DOMContentLoaded', init);
100    } else {
101        init();
102    }
103})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.