PageSourceSearch

https://yogaalliance.org/wp-content/plugins/exclusive-discounts-me…/js/exclusive-discounts-public.js?ver=1.3.1

js yogaalliance.org collected 2026-10-01 07:29:00 UTC 5,818 bytes, 163 lines download raw bytes

1(function($){
2  'use strict';
3
4  // Utilidades mínimas
5  function getCookie(name) {
6    var safe = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
7    var m = document.cookie.match(new RegExp('(?:^|; )' + safe + '=([^;]*)'));
8    return m ? decodeURIComponent(m[1]) : '';
9  }
10
11  // Sincronización suave (no recarga) por si se navega vía AJAX
12  document.addEventListener('DOMContentLoaded', function(){
13    try {
14      var cookieName = (window.EXDISC && EXDISC.cookieName) ? EXDISC.cookieName : 'DashboardName';
15      if (!window.localStorage) return;
16      var val = localStorage.getItem(cookieName);
17      if (!val) {
18        for (var i=0;i<localStorage.length;i++){
19          var k = localStorage.key(i);
20          if (k && k.toLowerCase() === cookieName.toLowerCase()) {
21            val = localStorage.getItem(k); break;
22          }
23        }
24      }
25      if (val && getCookie(cookieName) !== val) {
26        (function(){
27        var isHTTPS = location.protocol === 'https:';
28        var base = cookieName + '=' + encodeURIComponent(val) + '; path=/; ' + (isHTTPS ? 'SameSite=None; Secure' : 'SameSite=Lax');
29        var host = location.hostname;
30        var parts = host.split('.');
31        document.cookie = base; // host-only
32        document.cookie = base + '; domain=' + host; // explicit host
33        if (parts.length >= 2) {
34          var parent = '.' + parts.slice(-2).join('.');
35          if (parent !== '.' + host) {
36            document.cookie = base + '; domain=' + parent; // parent domain
37          }
38        }
39      })();
40      }
41    } catch(e){}
42  });
43
44})(jQuery);
45
46
47  // Helper: normalize (lowercase + trim + collapse spaces)
48  function norm(s){
49    if (s == null) return '';
50    s = (''+s).toLowerCase().trim();
51    s = s.replace(/\s+/g,' ');
52    return s;
53  }
54
55  function readLocalFirst(name){
56    var val = '';
57    try {
58      if (window.localStorage) {
59        val = localStorage.getItem(name) || '';
60        if (!val) {
61          for (var i=0;i<localStorage.length;i++){
62            var k = localStorage.key(i);
63            if (k && k.toLowerCase() === name.toLowerCase()) { val = localStorage.getItem(k); break; }
64          }
65        }
66      }
67    } catch(e){}
68    return val || '';
69  }
70
71  function allowedByValue(v, allowed){
72    var n = norm(v);
73    var candidates = [n];
74    var eq = n.indexOf('=');
75    if (eq !== -1) {
76      var rhs = n.slice(eq+1).trim();
77      if (rhs) candidates.push(rhs);
78    }
79    for (var i=0;i<allowed.length;i++){
80      if (candidates.indexOf(norm(allowed[i])) !== -1) return true;
81    }
82    return false;
83  }
84
85  document.addEventListener('DOMContentLoaded', function(){
86    if (typeof EXDISC === 'undefined') return;
87    var mode = EXDISC.mode || 'server';
88    if (mode !== 'client_rest') return;
89
90    var shell = document.getElementById('exdisc-shell');
91    if (!shell) return;
92    var postId = shell.getAttribute('data-postid');
93    var val = readLocalFirst(EXDISC.cookieName);
94    // Also try cookie if present (best-effort)
95    if (!val) val = getCookie(EXDISC.cookieName);
96
97    if (allowedByValue(val, EXDISC.allowed)) {
98      // Reveal by fetching from REST to avoid exposing content in HTML
99      var url = (EXDISC.rest && EXDISC.rest.root ? EXDISC.rest.root : '/wp-json/') + 'wp/v2/discount/' + postId + '?_fields=content.rendered';
100      fetch(url, { credentials: 'same-origin' }).then(function(r){
101        if (!r.ok) throw new Error('REST ' + r.status);
102        return r.json();
103      }).then(function(data){
104        var html = (data && data.content && data.content.rendered) ? data.content.rendered : '';
105        var contentEl = document.getElementById('exdisc-content');
106        var deniedEl = document.getElementById('exdisc-denied');
107        if (contentEl) { contentEl.innerHTML = html; contentEl.style.display = 'block'; }
108        if (deniedEl) { deniedEl.style.display = 'none'; }
109      }).catch(function(err){
110        // keep denied visible
111        // console.error('EXDISC REST error', err);
112      });
113    } else {
114      // keep denied
115    }
116  });
117
118// --- Client-side filters for [exclusive_discounts] ---
119document.addEventListener('DOMContentLoaded', function(){
120  var filters = document.getElementById('ed-filters');
121  var grid = document.getElementById('exclusive-discounts-grid');
122  if (!filters || !grid) return;
123
124  function currentSelection(){
125    var sel = filters.querySelector('#ed-filter-location');
126    var locationVal = sel ? (sel.value || '').toLowerCase() : '';
127    var catChecks = Array.prototype.slice.call(filters.querySelectorAll('input[name="ed_filter_cat[]"]:checked'));
128    var cats = catChecks.map(function(i){ return (i.value || '').toLowerCase(); });
129    return { location: locationVal, cats: cats };
130  }
131
132  function itemMatches(item, sel){
133    var locs = (item.getAttribute('data-locs') || '').toLowerCase().trim().split(/\s+/).filter(
133Boolean);
134    var cats = (item.getAttribute('data-cats') || '').toLowerCase().trim().split(/\s+/).filter(Boolean);
135
136    // Location: if selected, item must include that location
137    if (sel.location && locs.indexOf(sel.location) === -1) return false;
138
139    // Categories: OR logic — if none selected -> pass; else at least one overlap
140    if (sel.cats.length > 0) {
141      var overlap = sel.cats.some(function(c){ return cats.indexOf(c) !== -1; });
142      if (!overlap) return false;
143    }
144    return true;
145  }
146
147  function applyFilters(){
148    var sel = currentSelection();
149    var items = grid.querySelectorAll('.discount-card-link');
150    items.forEach ? items.forEach(hideShow) : Array.prototype.forEach.call(items, hideShow);
151
152    function hideShow(a){
153      if (itemMatches(a, sel)) {
154        a.classList.remove('exdisc-hidden');
155      } else {
156        a.classList.add('exdisc-hidden');
157      }
158    }
159  }
160
161  filters.addEventListener('change', applyFilters);
162  applyFilters();
163});

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.