PageSourceSearch

https://www.artsoftheworkingclass.org/assets/js/global.js?v=K7fkjFbMoL06K8JB

js artsoftheworkingclass.org collected 2026-10-02 05:28:09 UTC 17,357 bytes, 458 lines download raw bytes

1/* Global Notifications */
2function getParameterByName(name, url) {
3    if (!url) url = window.location.href;
4    name = name.replace(/[\[\]]/g, "\\$&");
5    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
6        results = regex.exec(url);
7    if (!results) return null;
8    if (!results[2]) return '';
9    return decodeURIComponent(results[2].replace(/\+/g, " "));
10}
11
12function setNotification() {
13    var action = getParameterByName('action');
14    var stripe = getParameterByName('stripe');
15    var success = getParameterByName('success');
16
17    document.addEventListener('DOMContentLoaded', function() {
18        if(success == null && action == null && stripe == null) return;
19
20        var notifications = document.querySelector('.global-notifications');
21        if(stripe){
22            notifications.classList.add(`stripe-${stripe}`);
23
24            notifications.addEventListener('animationend', () => {
25                notifications.classList.remove(`stripe-${stripe}`);
26            });
27        }else{
28            notifications.classList.add(`${action}-${success}`);
29
30            notifications.addEventListener('animationend', () => {
31                notifications.classList.remove(`${action}-${success}`);
32            });
33        }
34    });
35}
36
37let scrollPosition = 0;
38
39function disableScrolling() {
40  scrollPosition = window.pageYOffset;
41  document.body.style.overflow = 'hidden';
42  document.body.style.position = 'fixed';
43  document.body.style.top = `-${scrollPosition}px`;
44  document.body.style.width = '100%';
45  document.documentElement.style.scrollBehavior = 'auto';
46}
47
48function enableScrolling() {
49  document.body.style.removeProperty('overflow');
50  document.body.style.removeProperty('position');
51  document.body.style.removeProperty('top');
52  document.body.style.removeProperty('width');
53  window.scrollTo(0, scrollPosition);
54  document.documentElement.style.scrollBehavior = 'smooth';
55}
56
57function hexToRGBA(hexColor, opacity) {
58    const hex = hexColor.slice(1);
59    const r = parseInt(hex.substring(0, 2), 16);
60    const g = parseInt(hex.substring(2, 4), 16);
61    const b = parseInt(hex.substring(4, 6), 16);
62    return `rgba(${r}, ${g}, ${b}, ${opacity})`;
63}
64
65function secondLevelMenu(){
66    //NAVBAR
67    let navArray = [];
68    const navbar = document.querySelector('.nav');
69    if(navbar){
70        navbar.querySelectorAll('li').forEach(link => {         
71            if (link.dataset.label.charAt(0) === "-") {
72                link.dataset.parent = link.dataset.label.substring(1);                               
73                if(link.dataset.label.includes("--")){
74                    var data = link.dataset.parent.split("--")
75                    link.dataset.parent = data[0];
76                    link.dataset.child = data[1];
77                    
78                    link.querySelector('.nav-link').innerHTML = link.dataset.child;
79                    navArray.push({parent: data[0], child: link});
80                }else{
81                    link.querySelector('.nav-link').innerHTML = link.dataset.parent;  
82    
83                    const anchor = link.querySelector('a');
84                    const div = document.createElement('div');
85                    const ul = document.createElement('ul');
86    
87    
88                    div.innerHTML = anchor.innerHTML;
89                    div.classList.add('links-label')
90                    div.dataset.label = link.dataset.parent;
91                    anchor.parentNode.replaceChild(div, anchor);
92    
93                    link.appendChild(ul);
94                    ul.classList.add('secondary-links');
95                }               
96            }
97        })
98    
99        //move links
100        navArray.forEach(item => {
101            var secondaryList = document.querySelector(`.nav div.links-label[data-label="${item.parent}"]`).parentNode.querySelector('ul');
102            secondaryList.appendChild(item.child)
103        })
104    }
105
106    //FOOTER
107    navArray = [];
108    const footerNav = document.querySelector('.footer-nav');
109    if(footerNav){
110        footerNav.querySelectorAll('li').forEach(link => {         
111            if (link.dataset.label.charAt(0) === "-") {
112    
113                link.dataset.parent = link.dataset.label.substring(1);
114                if(link.dataset.label.includes("--")){
115                    var data = link.dataset.parent.split("--")
116                    link.dataset.parent = data[0];
117                    link.dataset.child = data[1];
118                    
119                    link.querySelector('.footer-nav-link').innerHTML = link.dataset.child;
120                    navArray.push({parent: data[0], child: link});
121                    }
122                    else{
123                    link.querySelector('.footer-nav-link').innerHTML = link.dataset.parent;  
124    
125                    const anchor = link.querySelector('a');
126                    const div = document.createElement('div');
127                    const ul = document.createElement('ul');
128                    const groupUl = document.createElement('ul')
129    
130    
131                    div.innerHTML = anchor.innerHTML;
132                    div.classList.add('footer-links-label')
133                    groupUl.classList.add('footer-links-group')
134                    div.dataset.label = link.dataset.parent;
135                    anchor.parentNode.replaceChild(div, anchor);
136    
137                    link.appendChild(ul);
138                    ul.classList.add('footer-secondary-links');
139    
140                    
141                    document.querySelector('.footer-navigation').appendChild(groupUl)
142                    groupUl.appendChild(link)
143    
144    
145                    if (footerNav.hasAttribute('center')) {
146                        link.style.alignItems = "center";
147                        ul.style.justifyContent = "center";
148                    }
149                }    
150            }
151        })
152
153        //move links
154        navArray.forEach(item => {
155            var secondaryList = document.querySelector(`custom-footer div.footer-links-label[data-label="${item.parent}"]`).parentNode.querySelector('ul');
156            secondaryList.appendChild(item.child)
157        })
158
159        if (footerNav.hasAttribute('center')) {
160            footerNav.style.justifyContent = "center"
161        }
162
163        if(footerNav.children.length === 0){
164            footerNav.remove();
165        }   
166    }     
167}
168
169function debounce(fn, delay) {
170    let timerId;
171    return function(...args) {
172      if (timerId) {
173        clearTimeout(timerId);
174      }
175      timerId = setTimeout(() => {
176        fn(...args);
177        timerId = null;
178      }, delay);
179    };
180}
181
182function setNavigation(){
183    const menuBtn = document.querySelector('.menu-button');
184    const menu = document.querySelector('.menu');
185    const menuContent = document.querySelector('.menu-content');
186    const sidebar = document.querySelector('.sidebar')
187    const blurDiv = document.querySelector('.blur');
188    menuBtn.addEventListener('click', e => menuHandler(e));
189    window.addEventListener('resize', menuOnResize);
190
191    document.addEventListener('click', e => closeMenu(e));
192    document.addEventListener("keydown", e => closeMenu(e));
193
194    function closeMenu(e){
195        if(menu.getAttribute('isopen') == 'false') return;
196
197        if(e.target == blurDiv || e.key === "Escape"){
198            menuHandler();
199        }
200    }
201
202    function menuHandler(e){       
203        menu.style.transition = 'transform var(--ease-transition)';
204        menuContent.style.transition = 'opacity var(--ease-transition)';
205        if(menu.getAttribute('isopen') == 'true'){
206            var sidebarWidth = sidebar.offsetWidth;
207            enableScrolling();
208            menu.setAttribute("isopen", false);
209            blurDiv.style.display = 'none';
210
211            if(window.matchMedia('(min-width: 992px)').matches){
212                menu.style.transform = `translateX(calc(-${menu.offsetWidth}px + ${sidebar.offsetWidth}px))`;
213                menuBtn.style.borderLeft = 'none';
214            }else{
215                setTimeout(() => {
216                   menuContent.style.display = 'none';
217                }, 300);
218                menuContent.style.opacity = '0';
219            }
220            
221
222            menuBtn.querySelector('.first-line').style.position = 'static';
223            menuBtn.querySelector('.first-line').style.transform = 'rotateZ(0deg)';
224            menuBtn.querySelector('.second-line').style.position = 'static';
225            menuBtn.querySelector('.second-line').style.transform = 'rotateZ(0deg)';
226            menuBtn.querySelector('.mobile-line').style.opacity = '1';
227
228            if(sidebar){
229                sidebar.style.borderLeft = 'none';
230            }     
231        }else{
232
233            //Close custom search if opened
234            var customSearch = document.querySelector('.custom-search');
235            if(customSearch && customSearch.getAttribute('isopen') == "true"){
236                document.querySelector('custom-header').closeSearchHandler();
237            }
238
239            disableScrolling();
240            menu.setAttribute("isopen", true);
241            blurDiv.style.display = 'block';
242            
243            if(window.matchMedia('(min-width: 992px)').matches){
244                menu.style.transform = 'translateX(0vw)';
245                menuBtn.style.borderLeft = '1px solid var(--text-color)';
246            }else{
247                menuContent.style.display = 'flex';
248                setTimeout(() => {
249                    menuContent.style.opacity = '1';
250                }, 10);
251            }
252
253            menuBtn.querySelector('.first-line').style.position = 'absolute';
254            menuBtn.querySelector('.first-line').style.transform = 'rotateZ(-45deg)';
255            menuBtn.querySelector('.second-line').style.position = 'absolute';
256            menuBtn.querySelector('.second-line').style.transform = 'rotateZ(45deg)';
257            menuBtn.querySelector('.mobile-line').style.opacity = '0';
258
259            if(sidebar){
260                sidebar.style.borderLeft = '1px solid var(--text-color)';
261            }
262        }     
263    }
264
265    function menuOnResize(){
266        //Close custom search if opened
267       /*  var customSearch = document.querySelector('.custom-search');
268        if(customSearch && customSearch.getAttribute('isopen') == "true"){
269            document.querySelector('custom-header').closeSearchHandler();
270        } */
271
272        menu.style.transition = 'none';
273        menuContent.style.transition = 'none';
274        if(menu.getAttribute('isopen') == 'true'){
275            menu.style.transform = 'translateX(0vw)';
276            menuContent.style.display = 'flex';
277            menuContent.style.opacity = '1';
278            menuBtn.style.borderLeft = '1px solid var(--text-color)';
279
280        }else{
281            var sidebarWidth = sidebar.offsetWidth;
282            
283            if(window.matchMedia('(max-width: 991px)').matches){
284                menuContent.style.display = 'none';
285                menuContent.style.opacity = '0';
286                menu.style.transform = 'translateX(0vw)';
287            }else{
288                window.matchMedia('(min-width: 1439px)').matches ? menu.style.transform = `translateX(calc((-29vw + 5vw) * var(--scale)))` :  menu.style.transform = `translateX(calc(-410px * var(--scale) + 72px))`; 
289                menuContent.style.display = 'flex';
290                menuContent.style.opacity = '1';
291                menuBtn.style.borderLeft = 'none';
292            }
293            
294        }
295    }  
296}
297
298function copyUrlToClipboard(parentElement){
299    let parent = document.querySelector(`.${parentElement}`)
300    let alert = parent.querySelector('.clipboard-alert');
301
302    parent.querySelector('.clipboard-link').addEventListener('click', () => {
303        navigator.clipboard.writeText(window.location.href);
304        alert.style.display = "block";
305
306        setTimeout(function () {
307            alert.style.display = "none";
308        }, 3000);
309    })
310}
311
312function setToggle() {
313    const toggleHeadingElements = document.getElementsByClassName("kg-toggle-heading");
314
315    const svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
316    svgElement.setAttribute("viewBox", "0 0 30 18");
317    svgElement.setAttribute("fill", "none");
318    svgElement.setAttribute("xmlns", "http://www.w3.org/2000/svg");
319
320    const pathElement = document.createElementNS("http://www.w3.org/2000/svg", "path");
321    pathElement.setAttribute("d", "M30 3L15 18L-6.55671e-07 3L2.6625 0.337501L15 12.675L27.3375 0.3375L30 3Z");
322
323    svgElement.appendChild(pathElement);
324
325    document.querySelectorAll('.kg-toggle-card').forEach(card => {
326        card.querySelector('.kg-toggle-heading svg').remove();
327
328        const container = card.querySelector(".kg-toggle-card-icon");
329        const clonedSvg = svgElement.cloneNode(true);
330
331        container.appendChild(clonedSvg);
332    })
333    
334    const toggleFn = function(event) {
335        
336        const targetElement = event.target;
337        const parentElement = targetElement.closest('.kg-toggle-card');
338        var toggleState = parentElement.getAttribute("data-kg-toggle-state");
339        if (toggleState === 'close') {
340            parentElement.setAttribute('data-kg-toggle-state', 'open');
341        } else {
342            parentElement.setAttribute('data-kg-toggle-state', 'close');
343        }
344    };
345
346    for (let i = 0; i < toggleHeadingElements.length; i++) {
347        toggleHeadingElements[i].addEventListener('click', toggleFn, false);
348    }
349}
350
351function setAccountText(){
352    let account = document.querySelector('#account-data');
353    document.querySelector('.account .heading-1-wrapper h1').innerHTML = account.getAttribute('data-name');
354    document.querySelector('.account .hero-description-wrapper p').innerHTML = account.getAttribute('data-description');
355}
356
357function findSrcSet(imageUrl, width){
358    let splitString = 'images/';
359    let insertString = `size/w${width}/`;
360
361    let splitted = imageUrl.split(splitString);
362    let modifiedUrl = splitted[0] + splitString + insertString + splitted[1];
363
364    return modifiedUrl;
365}
366
367const calcHeightContainers = ["featured-stories-slider", "latest-stories-grid", "authors-grid", "tag-stories-grid"]
368
369window.addEventListener('load', function() {
370    calculateTextHeight(calcHeightContainers)
371})
372window.addEventListener('resize', debounce(() => {calculateTextHeight(calcHeightContainers)}, 200)) 
373
374/* This function calculates the paragraph height and sets the highest one to all. Makes content align */
375function calculateTextHeight(containers){
376    if(!containers) return;
377
378    containers.forEach(container => {
379        containerItem = document.querySelector(`#${container}`);
380        if(!containerItem) return;
381
382        var items = containerItem.querySelectorAll('.card-lower-part');
383        if(items.length == 0) return;
384
385        var startHeights = [];
386
387        items.forEach(item => {
388            item.style.minHeight = "auto";
389        })
390
391        if(window.matchMedia('(min-width: 480px)').matches || container == "featured-stories-slider"){
392            items.forEach(item => {
393                startHeights.push(item.offsetHeight)
394            })
395    
396            var filteredHeights = startHeights.filter((value) => typeof value === "number" && !isNaN(value));
397            var highest =  Math.max(...filteredHeights);
398    
399            items.forEach(item => {
400                item.style.minHeight = `${highest}px`;
401            })
402        }
403    })
404}
405
406function setDemoColorSchemes(){
407    const url = new URL(window.location.href);
408    const searchParams = new URLSearchParams(url.search);
409    var paramValue = searchParams.get('color-scheme');
410    var storage = localStorage.getItem('color-scheme')
411
412    if(paramValue || storage){
413
414        if(!paramValue){
415            paramValue = storage;
416        }
417
418        localStorage.setItem('color-scheme', paramValue);
419
420        var root = document.documentElement;
421
422        switch (paramValue) {
423            case "dark":
424                root.style.cssText = `
425                    --background-color: #080808;
426                    --text-color: #ffffff;
427                    --text-60-opac: #9c9c9c;
428                    --text-color-lower-opac: #6b6b6b;
429                    --placeholder-color: #393939;
430                `
431                break;
432
433            case "elegant":
434                root.style.cssText = `
435                    --background-color: #F2F1EF;
436                    --text-color: #472419;
437                    --text-60-opac: #8c766f;
438                    --text-color-lower-opac: #ad9f99;
439                    --placeholder-color: #e1ddda;
440                `
441                break;
442        
443            default:
444                root.style.cssText = `
445                    --background-color: #FDF6F0;
446                    --text-color: #006D77;
447                    --text-60-opac: #57837A;
448                    --text-color-lower-opac: #E29578;
449                    --placeholder-color: #FFDDD2;
450                `
451                break;
452        }
453    }
454}
455
456
457
458  

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.