### Cookie Acceptance Logic (JavaScript) Source: https://www.electromechanicalsnow.com/manufacturer/ Manages the display and acceptance of a cookie banner. It checks for an existing cookie to determine if the banner should be shown and sets a cookie upon acceptance. Includes functions for setting and getting cookies specific to acceptance. ```javascript /*-- jQuery for cookies - mpjs.js --*/ $('.close_cookies').on('click', function(){ $('.cookies_design').css('display', 'none'); }); $(document).ready(function () { $('.cookies_design').css('display', 'none'); if (getCookieAccept('BroadlineAutomation') == null) { $('.cookies_design').removeAttr("style"); } $("#btnAcceptance").click(function () { setCookieAccept('BroadlineAutomation', '1'); $('.cookies_design').css('display', 'none'); }); }); function setCookieAccept(key, value) { var expires = new Date(); expires.setTime(expires.getTime() + (24 * 60 * 60 * 1000 * 365)); document.cookie = key + '=' + value + ';expires=' + expires.toUTCString() + ';path=/'; } function getCookieAccept(key) { var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)'); return keyValue ? keyValue[2] : null; } ``` -------------------------------- ### Cookie Acceptance Logic (JavaScript) Source: https://www.electromechanicalsnow.com/product/ Manages the display and acceptance of a cookie banner. It checks for an existing cookie to determine if the banner should be shown and sets a cookie upon acceptance. Includes functions for setting and getting cookies specific to acceptance. ```javascript /*-- jQuery for cookies - mpjs.js --*/ $('.close_cookies').on('click', function(){ $('.cookies_design').css('display', 'none'); }); $(document).ready(function () { $('.cookies_design').css('display', 'none'); if (getCookieAccept('BroadlineAutomation') == null) { $('.cookies_design').removeAttr("style"); } $("#btnAcceptance").click(function () { setCookieAccept('BroadlineAutomation', '1'); $('.cookies_design').css('display', 'none'); }); }); function setCookieAccept(key, value) { var expires = new Date(); expires.setTime(expires.getTime() + (24 * 60 * 60 * 1000 * 365)); document.cookie = key + '=' + value + ';expires=' + expires.toUTCString() + ';path=/'; } function getCookieAccept(key) { var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)'); return keyValue ? keyValue[2] : null; } ``` -------------------------------- ### JavaScript Exit-Intent Popup and Cookie Handling Source: https://www.electromechanicalsnow.com/about-us/ This script implements an exit-intent popup mechanism. It tracks mouse movement and triggers a popup when the mouse leaves the top of the viewport. It also manages a 'lightbox' cookie to prevent repeated popups and handles closing the popup via a close button or clicking outside the popup area. Includes helper functions for setting and getting cookies. ```javascript $(document).ready(function(){ var mouseX = 0; var mouseY = 0; document.addEventListener("mousemove", function(e) { mouseX = e.clientX; mouseY = e.clientY; }); $(document).mouseleave(function () { if (mouseY < 100) { if(getCookie('lightbox')== null) { setCookie('lightbox','1'); $('.exit-lightbox').slideDown(); } } }); $('.exit-close').click(function() { $('.exit-lightbox').slideUp(); }); $('html:not(.exit-box)').click(function() { $('.exit-lightbox').slideUp('slow'); }); $(".exit-box").click(function(e) { e.stopPropagation(); }); }); function setCookie(key, value) { var expires = new Date(); expires.setTime(expires.getTime() + (24 * 60 * 60 * 1000)); document.cookie = key + '=' + value + ';expires=' + expires.toUTCString() + ';path=/'; } function getCookie(key) { var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)'); return keyValue ? keyValue[2] : null; } ``` -------------------------------- ### Initialize Owl Carousel with Responsive Settings Source: https://www.electromechanicalsnow.com/contact-us/ Configures an Owl Carousel instance with various options including looping, margins, navigation, autoplay, and responsive breakpoints. This script enhances the display of image galleries or product listings. ```javascript $(document).ready(function () { $('.owl-carousel10').owlCarousel({ loop: true, margin: 30, nav: true, dots: false, autoWidth: true, responsiveClass: true, autoplay: true, autoplayTimeout: 2000, autoplayHoverPause: true, responsive: { 0: { items: 1 }, 600: { items: 2 }, 1000: { items: 5 }, 1280: { items: 6 } } }); }); ``` -------------------------------- ### Exit Intent Popup and Cookie Management (JavaScript) Source: https://www.electromechanicalsnow.com/manufacturer/ Handles an exit-intent popup triggered when a user's mouse moves towards the top of the screen. It uses cookies to prevent the popup from showing repeatedly. Includes functions for setting and getting cookies. ```javascript $(document).ready(function(){ var mouseX = 0; var mouseY = 0; document.addEventListener("mousemove", function(e) { mouseX = e.clientX; mouseY = e.clientY; }); $(document).mouseleave(function () { if (mouseY < 100) { if(getCookie('lightbox')== null) { setCookie('lightbox','1'); $('.exit-lightbox').slideDown(); } } }); $('.exit-close').click(function() { $('.exit-lightbox').slideUp(); }); $('html:not(.exit-box)').click(function() { $('.exit-lightbox').slideUp('slow'); }); $(".exit-box").click(function(e) { e.stopPropagation(); }); }); function setCookie(key, value) { var expires = new Date(); expires.setTime(expires.getTime() + (24 * 60 * 60 * 1000)); document.cookie = key + '=' + value + ';expires=' + expires.toUTCString() + ';path=/'; } function getCookie(key) { var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)'); return keyValue ? keyValue[2] : null; } ``` -------------------------------- ### Defer Image Loading by Setting Source Attribute Source: https://www.electromechanicalsnow.com/contact-us/ The `init` function iterates through all `` tags on the page. If an image has a 'data' attribute, it copies the value of the 'data' attribute to the 'src' attribute, effectively deferring image loading until the script runs. ```javascript function init() { var imgDefer = document.getElementsByTagName('img'); for (var i = 0; i < imgDefer.length; i++) { if (imgDefer[i].getAttribute('data')) { imgDefer[i].setAttribute('src', imgDefer[i].getAttribute('data')); } } } window.onload = init; ``` -------------------------------- ### Open Popup Window for RFQ Upload Source: https://www.electromechanicalsnow.com/blog/ This JavaScript function, ShowPopup, is designed to open a new browser window for uploading a Request for Quote (RFQ). It specifies the URL, window name, dimensions, and scrollbar settings for the popup window. ```javascript ShowPopup = function () { window.open("/rfq/uploadrfq", "PopupWindow", "width=850px,height=550px,top=80,left=250,resizable=0,scrollbars=yes") } ``` -------------------------------- ### Exit Intent Popup and Cookie Management (JavaScript) Source: https://www.electromechanicalsnow.com/product/ Handles an exit-intent popup triggered when a user's mouse moves towards the top of the screen. It uses cookies to prevent the popup from showing repeatedly. Includes functions for setting and getting cookies. ```javascript $(document).ready(function(){ var mouseX = 0; var mouseY = 0; document.addEventListener("mousemove", function(e) { mouseX = e.clientX; mouseY = e.clientY; }); $(document).mouseleave(function () { if (mouseY < 100) { if(getCookie('lightbox')== null) { setCookie('lightbox','1'); $('.exit-lightbox').slideDown(); } } }); $('.exit-close').click(function() { $('.exit-lightbox').slideUp(); }); $('html:not(.exit-box)').click(function() { $('.exit-lightbox').slideUp('slow'); }); $(".exit-box").click(function(e) { e.stopPropagation(); }); }); function setCookie(key, value) { var expires = new Date(); expires.setTime(expires.getTime() + (24 * 60 * 60 * 1000)); document.cookie = key + '=' + value + ';expires=' + expires.toUTCString() + ';path=/'; } function getCookie(key) { var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)'); return keyValue ? keyValue[2] : null; } ``` -------------------------------- ### Configure Google Analytics Source: https://www.electromechanicalsnow.com/ Initializes and configures Google Analytics (gtag.js) for website tracking. It ensures the `dataLayer` is available and pushes configuration commands to it, including the measurement ID. ```javascript window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag('js', new Date()); gtag('config', 'G-0VT3P8XF36'); ``` -------------------------------- ### Open Popup Window for File Upload Source: https://www.electromechanicalsnow.com/contact-us/ Defines a JavaScript function `ShowPopup` that opens a new browser window to a specific URL for uploading RFQ (Request for Quotation) files. This is typically used for user interaction with a file submission form. ```javascript ShowPopup = function () { window.open("/rfq/uploadrfq/", "PopupWindow") } ``` -------------------------------- ### Remove 'nohyperlink' Class from Mailto Links Source: https://www.electromechanicalsnow.com/blog/ This JavaScript snippet, executed after the document is ready, targets all anchor tags with an `href` attribute starting with 'mailto:'. It adds the class 'nohyperlink' to these elements after a 500ms delay, likely to prevent default mail client behavior or apply specific styling. ```javascript $(document).ready(function () { setTimeout(function () { $('a[href^="mailto:"]').addClass("nohyperlink") }, 500) }); ``` -------------------------------- ### Configure Google Analytics Source: https://www.electromechanicalsnow.com/manufacturer/ Initializes and configures Google Analytics tracking for the website. It sets up the dataLayer and sends the initial configuration command with the measurement ID. ```javascript window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-0VT3P8XF36'); ``` -------------------------------- ### JavaScript Mailto Link Styling Source: https://www.electromechanicalsnow.com/about-us/ This script targets all `` tags with an `href` attribute starting with 'mailto:' and adds a class 'nohyperlink' to them. This is likely used to visually distinguish or disable mailto links, preventing them from being treated as standard clickable links or applying specific styling. The operation is delayed by 500ms after the document is ready. ```javascript $(document).ready(function () { setTimeout(function () { $('a[href^="mailto:"]').addClass("nohyperlink") }, 500) }); ``` -------------------------------- ### Handle Search Submission and Input Source: https://www.electromechanicalsnow.com/ Manages the website's search functionality. It includes input validation to prevent script injection and enforce length limits, constructs search URLs based on type (Manufacturer, Part Type, Part Number), and handles Enter key presses for submission. It also manages a dropdown for search suggestions. ```javascript function SearchSubmit(e) { var r = $("#Keyword").val().trim(), a = ""; if ("" != r) { if (r.toLowerCase().indexOf("