PageSourceSearch

https://sustainablepractice.org/wp-content/themes/twentytwentyfive-child/assets/scripts.js?ver=1790278224

js sustainablepractice.org collected 2026-09-24 22:32:21 UTC 7,865 bytes, 216 lines download raw bytes

1//Open external links in new tab automatically
2let anchorLinks = document.querySelectorAll("a");
3
4for (let i = 0; i < anchorLinks.length; i += 1) {
5  if (anchorLinks[i].host !== window.location.hostname) {
6    anchorLinks[i].setAttribute("target", "_blank");
7  }
8}
9
10//are we on a touch device
11var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0));
12
13var $ = jQuery;
14
15$(function(){
16    //add isTouch to header
17    if(isTouch){
18		$("body").addClass("is-touch");
19	}
20
21    //if there is a hash in the url, scroll to the content
22    if(window.location.hash){
23        var hash = window.location.hash;
24
25        if($(hash).length){
26            $('html, body').animate({
27                scrollTop: $(hash).offset().top
28            }, 900, 'swing');
29        }
30    }
31
32    //SEOPress Cookies Bar
33    if( $(".seopress-user-consent.seopress-user-message").length ){
34        $('.seopress-user-consent.seopress-user-message').wrapInner("<div class='seopress-inner-wrap'><div class='seopress-content-container'></div></div>");
35    }
36
37    //Add class to empty content
38    $('.wp-block-group:not(.is-style-placeholder-image):empty').addClass('empty');
39    $('p:empty').addClass('empty');
40
41}); 
42
43//Menus / Header
44$(function(){
45    //Fade out header elements
46    $(window).scroll(function(){
47        if( $(this).scrollTop() > 20){
48            $('header .wp-block-image:not(.is-style-site-symbol)').fadeOut();
49            $('header').addClass('scrolled');
50            $('header nav').addClass('scrolled');
51        } else{
52            $('header .wp-block-image:not(.is-style-site-symbol)').fadeIn();
53            $('header').removeClass('scrolled');
54            $('header nav').removeClass('scrolled');
55        }
56    });
57
58    //Add class to parent menu item on sub-menu toggle click
59    $('header button.wp-block-navigation-submenu__toggle').on('click', function(){
60        if($(this).hasClass('active')){
61            $(this).removeClass('active');
62            $(this).closest('li.wp-block-navigation-item.has-child').removeClass('active');
63        } else{
64            $('button.wp-block-navigation-submenu__toggle').removeClass('active');
65            $('li.wp-block-navigation-item.has-child').removeClass('active');
66            $(this).toggleClass('active');
67            $(this).closest('li.wp-block-navigation-item.has-child').toggleClass('active');
68        }
69	});
70
71    //make button toggle more accessible
72    if( $('header button.wp-block-navigation-submenu__toggle').hasClass('active')){
73        $('header button.wp-block-navigation-submenu__toggle').attr("aria-expanded", "true");
74    } else{
75        $('header button.wp-block-navigation-submenu__toggle').attr("aria-expanded", "false");
76    }
77
78    //Change button toggle icon
79    $("header nav button.wp-block-navigation__submenu-icon").each(function(){
80        $(this).html(function(i, html){
81            return "<i class='fa-solid fa-plus custom-submenu-toggle'></i>";
82        }); 
83    });
84
85    //wrap sub-menus in main-nav
86    $("header.site-alt nav.main-menu li.has-child").html(function(i, html){
87        return "<div class='ancestor-wrapper'>"+ html +"</div>";
88    });
89
90    //move sub-menu below ancestor-wrapper
91    $("nav.main-menu li.has-child ul.wp-block-navigation-submenu").insertAfter("nav.main-menu li.has-child .ancestor-wrapper");
92
93    //Make parent active so we can do a state change
94    $('ul.wp-block-navigation-submenu li.current-menu-item').closest('li.has-child').addClass('parent-active');
95
96});
97
98//Gutenberg Core Blocks
99$(function(){
100    //Core/Details
101    //Change headings in span
102    $(".wp-block-details:not(.is-style-heading-two):not(.is-style-heading-three):not(.is-style-heading-four) summary").html(function(i, html){
103        return "<i class='fa-solid fa-play has-small-font-size'></i>&nbsp;&nbsp;<span>"+ html +"</span>";
104    });
105    $(".wp-block-details.is-style-heading-two summary").each(function(){
106        $(this).html(function(i, html){
107            return "<i class='fa-solid fa-play has-small-font-size'></i>&nbsp;&nbsp;<span><h2>"+ html +"</h2></span>";
108        });
109    });
110    $(".wp-block-details.is-style-heading-three summary").each(function(){
111        $(this).html(function(i, html){
112            return "<i class='fa-solid fa-play has-small-font-size'></i>&nbsp;&nbsp;<span><h3>"+ html +"</h3></span>";
113        });
114    });
115    $(".wp-block-details.is-style-heading-four summary").each(function(){
116        $(this).html(function(i, html){
117            return "<i class='fa-solid fa-play has-small-font-size'></i>&nbsp;&nbsp;<span><h4>"+ html +"</h4></span>";
118        });
119    });
120
121    //Core/files
122    //open file links in new tab automatically
123    $(".wp-block-file").each(function() {
124        $(".wp-block-file a:not(.wp-element-button)").attr("target", "_blank");
125    });
126    $('.wp-block-file a.wp-element-button').each(function(){
127        var href = $(this).attr('href');
128        $(this).attr("download", href); //we want to actually put the file origin in here
129        $(this).attr("target", "_blank");
130    });
131
132    //Core/footnote
133    //add brackets around footnotes
134    $("sup.fn").each(function() {
135        $(this).html(function(i, html){
136            return "&nbsp;["+ html + "] &nbsp;";
137        });
138    });
139
140    //core/social-link
141    //always open in a new tab automatically
142    $('.wp-social-link a').each(function(){
143        $(this).attr("target", "_blank");
144    });
145
146    //Core/table: Add data label to tables
147    $('table th').each(function(i,elem) {
148        var num = i + 1;
149            $('table td:nth-child(' + num + ')').attr('data-label', $(elem).text());
150    });
151});
152
153//Fancybox
154$(document).ready(function(){
155    //add fancybox markup to all images and galleries
156    $("main .entry-content figure.wp-block-image a").each(function() {
157        $("main .entry-content figure.wp-block-image a").attr("data-fancybox", "gallery");
158	});
159    $("main .entry-content figure.wp-block-media-text__media a").each(function() {
160        $("main .entry-content figure.wp-block-media-text__media a").attr("data-fancybox", "gallery");
161	});
162
163    //add overlay hover to images
164    $('main .entry-content figure.wp-block-image a:not([target="_blank"])').each(function(){
165        $(this).html(function(i, html){
166            return "<div class='fancyOverlay'><i class='fa-solid fa-magnifying-glass'></i></div>"+ html;
167        });
168    });
169    $('main .entry-content figure.wp-block-media-text__media a').each(function(){
170        $(this).html(function(i, html){
171            return "<div class='fancyOverlay'><i class='fa-solid fa-magnifying-glass'></i></div>"+ html;
172        });
173    });
174    $('main .entry-content figure.wp-block-gallery .blocks-gallery-item a').each(function(){
175        $(this).html(function(i, html){
176            return "<div class='fancyOverlay'><i class='fa-solid fa-magnifying-glass'></i></div>"+ html;
177        });
178    });
179    $("main .entry-content figure.wp-block-post-featured-image a").each(function(){
180		$(this).html(function(i, html){
181            return "<div class='fancyOverlay'><i class='fa-solid fa-magnifying-glass'></i></div>"+ html;
182        });
183	});
184
185    //Get the all image captions into the a element
186    $('figure').each(function(){
187        $(this).find('a').attr('data-caption', $(this).find('figcaption').text());
188    });
189
190}); 
191
192Fancybox.bind("[data-fancybox]", {
193    animated: true,
194     
195    click: false,
196    dragToClose: false,
197    
198    Thumbs: false,
199    
200    Image: {
201        zoom: true,
202        fit: "contain-w",
203    },
204    
205    buttons: [
206        "slideShow",
207        //"thumbs",
208        "zoom",
209        "fullScreen",
210        "share",
211        "close"
212      ],
213    
214      loop: false,
215      protect: true,
216});

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.