PageSourceSearch

https://www.clearesult.com/themes/custom/clearesult_corp/js/custom.js?v=1.0.11

js clearesult.com collected 2026-10-02 02:25:01 UTC 16,486 bytes, 430 lines download raw bytes

1/**
2 * @file
3 * Global utilities.
4 *
5 */
6(function ($, Drupal, drupalSettings) {
7    'use strict';
8    /**
9     * Copyright 2012, Digital Fusion
10     * Licensed under the MIT license.
11     * http://teamdf.com/jquery-plugins/license/
12     *
13     * @author Sam Sehnert
14     * @desc A small plugin that checks whether elements are within
15     *     the user visible viewport of a web browser.
16     *     only accounts for vertical position, not horizontal.
17     */
18
19    $.fn.visible = function (partial) {
20
21        var $t = $(this),
22            $w = $(window),
23            viewTop = $w.scrollTop(),
24            viewBottom = viewTop + $w.height(),
25            _top = $t.offset().top,
26            _bottom = _top + $t.height(),
27            compareTop = partial === true ? _bottom : _top,
28            compareBottom = partial === true ? _top : _bottom;
29
30        return ((compareBottom <= viewBottom) && (compareTop >= viewTop));
31
32    };
33
34    var win = $(window);
35
36    var allMods = $(".layer");
37
38    allMods.each(function (i, el) {
39        var el = $(el);
40        if (el.visible(true)) {
41            el.addClass("already-visible");
42        }
43    });
44
45    win.scroll(function (event) {
46
47        allMods.each(function (i, el) {
48            var el = $(el);
49            if (el.visible(true)) {
50                el.addClass("come-in");
51            }
52            // else {
53            //     el.removeClass("come-in");
54            // }
55        });
56    });
57
58    function updateGridAlignment() {
59        $('.section-divider-video-block .row.card-container').each(function () {
60            const count = $(this).find('.section-divider-grid').length;
61            $(this).css('justify-content', count > 2 ? 'flex-start' : 'center');
62        });
63    }
64    $(document).ready(updateGridAlignment);
65    $(window).on('resize', updateGridAlignment);
66
67    async function loadUrlData(url) {
68        let response = await fetch(url);
69        let data = await response.json();
70        return data;
71    }
72    var latest_ef = Cookies.get("latest-energy-forum");
73
74    function latestEnergyForumHTML(response_data, set_cookie = true) {
75        var link_html = '';
76        $.each(response_data, function (i, ef) {
77            link_html += "<li class='marquee-ele'><a href='" + ef.view_node + "' title='" + ef.title + "'><span class='latest-ef-title'>" + ef.title + "</span><span class='latest-ef-arrow'> >></span></a></li>";
78        });
79        if (link_html != '') {
80            link_html = '<ul class="marquee">' + link_html + '</ul>';
81        }
82        $('.header-energy-forum-link').html(link_html);
83        if (set_cookie) {
84            Cookies.set("latest-energy-forum", JSON.stringify(response_data), { expires: 1, path: '/' });
85        }
86    }
87    if (latest_ef == undefined) {
88        loadUrlData("/latest-energy-forum").then(function (response_data) {
89            latestEnergyForumHTML(response_data, true);
90        });
91    } else {
92        try {
93            var response_data = $.parseJSON(latest_ef);
94            latestEnergyForumHTML(response_data, false);
95        } catch (err) {
96            // on error again call the API
97            loadUrlData("/latest-energy-forum").then(function (response_data) {
98                latestEnergyForumHTML(response_data, true);
99            });
100        }
101    }
102
103    // Update copyright text
104    var copyright_time = Cookies.get("copyright-text");
105
106    function updateCopyright(date_response, set_cookie = false) {
107        $('#block-copyright .text-formatted.field--name-body').html(date_response.copyright);
108
109        if (set_cookie) {
110            var expDate = new Date();
111            expDate.setTime(date_response.expiry * 1000);
112            Cookies.set("copyright-text", JSON.stringify(date_response), { expires: expDate, path: '/' });
113        }
114    }
115    if (copyright_time == undefined) {
116        loadUrlData('/api/copyright').then(function (date_response) {
117            if (date_response != undefined) {
118                updateCopyright(date_response, true);
119            }
120        });
121    } else {
122        try {
123            var date_response = $.parseJSON(copyright_time);
124            updateCopyright(date_response, false);
125        } catch (err) {
126            loadUrlData("/api/copyright").then(function (date_response) {
127                if (date_response != undefined) {
128                    updateCopyright(date_response, true);
129                }
130            });
131        }
132    }
133
134    if ($(".atlas-section .field--type-link a").length) {
135      $(document).on('click', ".atlas-section .field--type-link a", function (event) {
136        let hrefEle = $(this).attr("href");
137        hrefEle = hrefEle.split('#');
138        let hash = false;
139        if (hrefEle.length > 1 && (hrefEle[0] == "" || hrefEle[0].replace(/\/*$/, '') == window.location.pathname.replace(/\/*$/, ''))) {
140            hash = '#' + hrefEle[1];
141            event.preventDefault();
142            pageScroll(hash);
143        }
144      });
145    }
146
147    if ($("a.btn-primary").length) {
148      $('.page-node-type-practices a.btn-primary').each(function(){
149        $(this).click(function(event){
150          let hrefEle = $(this).attr("href");
151          hrefEle = hrefEle.split('#');
152          let hash = false;
153          if (hrefEle.length > 1 && (hrefEle[0] == "" || hrefEle[0].replace(/\/*$/, '') == window.location.pathname.replace(/\/*$/, ''))) {
154            hash = '#' + hrefEle[1];
155            event.preventDefault();
156            $("html, body").animate({ scrollTop: $(hash).offset().top }, "slow");
157            setTimeout(() => {
158              if ($(hash).offset()) {
159                if ($(window).width() <= 499) {
160                    $("html, body").animate({ scrollTop: $(hash).offset().top - 130 }, "fast");
161                } else {
162                    $("html, body").animate({ scrollTop: $(hash).offset().top - 120 }, "slow");
163                }
164              }
165            }, 500);
166          }
167        });
168      });
169    }
170
171    if ($('.page-node-type-practices #doc-library .panel-heading').length) {
172      $('.page-node-type-practices #doc-library .panel-heading').click();
173    }
174
175    $("#block-headertophighlightedblock .latest-news").click(function (e) {
176      e.preventDefault();
177      let hrefEle = '#block-explorenewssectionheading';
178      if ($('body').hasClass('path-frontpage')) {
179        pageScroll($(hrefEle));
180      } else {
181        window.open("/insights", "_self");
182      }
183    });
184
185    if ($('.external-redirect').length) {
186      $(document).on('click', '.external-redirect', function (event) {
187        event.preventDefault();
188        var external_link = '';
189        if ($(this).attr('href')) {
190            external_link = this.href;
191        } else {
192            external_link = $(this).children("a").attr("href");
193        }
194        window.open(external_link, '_blank');
195      });
196    }
197
198    function pageScroll(ele) {
199      if ($(ele).offset()) {
200        if ($(window).width() <= 499) {
201            $("html, body").animate({ scrollTop: $(ele).offset().top - 150 }, "slow");
202        } else {
203            $("html, body").animate({ scrollTop: $(ele).offset().top - 120 }, "slow");
204        }
205        $(".footer__section").addClass('animated fadeIn');
206      }
207    }
208
209    $(document).on('click', '.sf-accordion-toggle a', function (event) {
210        if (!$('.sf-accordion-toggle a').hasClass("sf-expanded")) {
211            $('.sf-has-clone-parent').addClass('sf-hidden');
212        }
213    });
214
215    $('.footer .footer__container .footer__section .region-footer-first .content .field__item a').on("click", function (event) {
216        let hrefEle = $(this).attr("href");
217        hrefEle = hrefEle.split('#');
218        if (hrefEle.length > 1) {
219          event.preventDefault();
220          pageScroll('#' + hrefEle[1]);
221        }
222    });
223
224    // Open generic popup on redsox page.
225    function showGenericPopupWithImage(imageUrl) {
226        if (imageUrl !== undefined && imageUrl !== "") {
227            $('#genericModal')
228                .modal('show')
229                .find(".popup-modal-image img")
230                .attr({ "src": imageUrl });
231        } else {
232            $('#genericModal')
233                .modal('show')
234                .find(".no-image-behaviour")
235                .html("Image not uploaded.");
236        }
237    }
238
239    $(".cta-section .popup-image-cta").on("click", function (e) {
240        e.preventDefault();
241        if ($(window).width() >= 991) {
242            showGenericPopupWithImage($(this).data("desktop-popup-image-url"));
243        } else {
244            showGenericPopupWithImage($(this).data("mobile-popup-image-url"));
245        }
246    });
247
248    // Go Back link redirection script
249    if ($(".go-back-link").length) {
250      $(".go-back-link").click(function (e) {
251        e.preventDefault();
252        if ($('.page-node-type-portfolio').length > 0) {
253          if (document.referrer === '') {
254            window.location.href = '/practices';
255          }
256          else {
257            window.location.href = document.referrer
258          }
259        }
260        if ($('.nrcan-landing').length > 0) {
261          window.location.href = '/home-canada';
262        }
263        if ($('.greener-home-pre-project-audit-page').length > 0 || $('.book-energy-audit').length > 0 || $('.our-trade-allies').length > 0) {
264          window.location.href = '/NRCan';
265        }
266        if ($('.ira-landing').length > 0) {
267          window.location.href = '/';
268        }
269      });
270    }
271
272    // scroll to new page
273    var hashUrl = window.location.hash;
274    function scrollToNewPage(ele) {
275        if ($(ele).offset()) {
276            if ($(window).width() <= 499) {
277                $("html, body").animate({ scrollTop: $(ele).offset().top - 350 }, "slow");
278            } else {
279                $("html, body").animate({ scrollTop: $(ele).offset().top + 220 }, "slow");
280            }
281        }
282    }
283    scrollToNewPage(hashUrl)
284
285    function scrollToBlock(hash) {
286        if (hash && (hash.includes('contractor') || hash.includes('utility') || hash.includes('business') || hash.includes('government') || hash.includes('residential') || hash.includes('accolades'))) {
287            $("html, body").animate({ scrollTop: $(hash).offset().top - 120 }, 'fast');
288        }
289        if (hash && hash.includes('block-ourcommunities')) {
290            $("html, body").animate({ scrollTop: $(hash).offset().top - 130 }, 'fast');
291        }
292        if (hash && hash.includes('going-net-zero-by-2025')) {
293            $("html, body").animate({ scrollTop: $(hash).offset().top - 150 }, 'fast');
294        }
295    }
296    scrollToBlock(hashUrl)
297
298    window.addEventListener('popstate', function (event) {
299        var hashUrl = window.location.hash;
300        scrollToBlock(hashUrl)
301    });
302    $(window).on('load', function () {
303        var hashUrl = window.location.hash;
304        scrollToBlock(hashUrl)
305    });
306    // function to handle scroll to top functionality for product supernav
307    $(window).on('hashchange', function () {
308        var hash = window.location.hash;
309        if (hash && (hash.includes('qualify') || hash.includes('marketplace') || hash.includes('carbon') || hash.includes('connect') || hash.includes('insights') || hash.includes('chooseev') || hash.includes('80Plus') || hash.includes('academy'))) {
310            $("html, body").animate({ scrollTop: $(hash).offset().top - 120 }, 'fast');
311        }
312    });
313
314    // Code to execute on canada pages.
315    if (drupalSettings.is_canada_page) {
316        $('#block-footer-social-links .content .btn-primary').each(function (e) {
317            let href = $(this).attr("href");
318            if (href == '/contact') {
319                let main_menu = document.getElementById('superfish-main-menu');
320                let contact_us_button = main_menu.querySelector('.contact-btn');
321                $(this).attr("href", $(contact_us_button).attr('href'));
322            }
323        });
324    }
325
326    $('.carbon-calculator #usage-input').keyup(function(){
327      if ($.isNumeric($(this).val())) {
328        $('#block-carboncalculator .btn-primary').removeAttr('disabled').css('background-color', '#d63827');
329      }
330      else if ($(this).val() == '') {
331        $('#block-carboncalculator .btn-primary').prop('disabled', true).css('background-color', '#ccc');
332      }
333      else {
334        $('#block-carboncalculator .btn-primary').prop('disabled', true).css('background-color', '#ccc');
335      }
336    });
337
338    $('#block-carboncalculator .btn-primary').click(function(){
339        let multiplier = drupalSettings.calculator.multiplier;
340        let input_val = $('#usage-input').val();
341        let result = (Number(multiplier))*(Number(input_val));
342        $(".carbon-footprint h4.result-value").text(result);
343        $(".carbon-footprint").show();
344      });
345
346    // Page(behind popup) scroll get stop when Modal popup is open
347    $(".member-bio").click(function () {
348        if ($(this).attr('data-bs-target')!= undefined && $(this).attr('data-bs-target') == "#popupModal") {
349          $('html').addClass("modal-open");
350        }
351    })
352    $('#popupModal').on('hidden.bs.modal', function () {
353        $('html').removeClass("modal-open")
354    });
355
356    $(window).on('load', function() {
357        $('.owl-nav .owl-prev').attr('aria-label', 'prev');
358        $('.owl-nav .owl-next').attr('aria-label', 'next');
359        $('.carousel-insights .owl-nav, .mt-carousel-partners .owl-nav, .logos-carousel .owl-nav, .cl-carousel-atlas .owl-nav,  .cl-carousel-atlas .owl-dots').attr('role', 'listitem');
360        $('.sf-accordion-toggle #superfish-main-menu-toggle').attr('aria-label', 'Main menu toggle');
361    });
362    // ADA compliance fix for video text section block
363    $(document).ready(function() {
364        if ($(".atlas-video iframe").length > 0) {
365            $(".atlas-video iframe").attr("role", "presentation");
366        }
367        if ($(".video-overlay iframe").length > 0) {
368            $(".video-overlay iframe").attr("role", "presentation");
369        }
370        //remove aria-expanded for ADA fixes master template.
371        $('.accordian-collapsible-tabs-wrapper [id^="faq-item-"]').on('change', function() {
372            $('.accordian-collapsible-tabs-wrapper [id^="question"]').removeAttr('aria-expanded');
373        });
374        $('.mt-carousel-partners .owl-nav, .mt-carousel-container .owl-nav, .mt-carousel-container .owl-dots').attr('role', 'listitem');
375
376        $('.dropdown-menu a').on('click', function () {
377            // Remove aria-expanded attribute after Bootstrap sets it
378            setTimeout(() => {
379                $('.sort-by-feature .dropdown-toggle').removeAttr('aria-expanded');
380            }, 0);
381        });
382        $('#block-headertophighlightedblock div.desktop form i.fa-search').click(function(){
383          $(this).closest('form').find('input.form-submit').trigger('click');
384        });
385
386        //remove aria-expanded for ADA fixes.
387        $('.doc-library #faq-item #question').removeAttr('aria-expanded');
388        $("#block-headertophighlightedblock").find('form').attr("role", "search");
389        $('.gtranslate_wrapper').attr({role: "region", 'aria-label': "Language Selector"});
390    });
391
392    // Observe the changes to the footer links and remove hstc query parameter from link URL.
393    const targetNode = document.getElementsByClassName('remove-hstc')[0];
394    const config = { attributes: true, childList: false, subtree: false };
395    const link_observer_callback = (mutationList, observer) => {
396        for (const mutation of mutationList) {
397            if (mutation.type === "attributes") {
398                jQuery('.remove-hstc').each(function() {
399                    jQuery(this).attr('href', jQuery(this).attr('href').split('?')[0]);
400                });
401                observer.disconnect();
402            }
403        }
404    };
405    const observer = new MutationObserver(link_observer_callback);
406    observer.observe(targetNode, config);
407
408    // Hiding pipe from last menu item of each row in footer
409    function fixSeparators() {
410        const items = document.querySelectorAll('.block-superfishmt-subfooter-menu .content .menu li');
411        let currentTop = null;
412    
413        items.forEach((item, i) => {
414        item.classList.remove('no-separator');
415    
416        if (i < items.length - 1) {
417            const next = items[i + 1];
418    
419            if (item.offsetTop !== next.offsetTop) {
420            item.classList.add('no-separator');
421            }
422        }
423        });
424    
425        items[items.length - 1].classList.add('no-separator');
426    }
427    window.addEventListener('load', fixSeparators);
428    window.addEventListener('resize', fixSeparators);
429
430})(jQuery, Drupal, drupalSettings);

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.