From 517577828669da968395f9ef724a90bec3d076bc Mon Sep 17 00:00:00 2001 From: Nicholas Pagazani Date: Thu, 23 May 2024 00:04:38 +0200 Subject: [PATCH] Delay loading styling JS until remote form is loaded --- themes/osi/assets/js/build/theme.asset.php | 2 +- themes/osi/assets/js/build/theme.js | 2 +- themes/osi/assets/js/src/theme/donation-form.js | 12 +++++++++++- themes/osi/assets/js/src/theme/theme.js | 1 - 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/themes/osi/assets/js/build/theme.asset.php b/themes/osi/assets/js/build/theme.asset.php index 337df28..d91162f 100644 --- a/themes/osi/assets/js/build/theme.asset.php +++ b/themes/osi/assets/js/build/theme.asset.php @@ -1 +1 @@ - array(), 'version' => 'ee5da5bfafd11f296b5b'); + array(), 'version' => '1a77530059955fb6eaa5'); diff --git a/themes/osi/assets/js/build/theme.js b/themes/osi/assets/js/build/theme.js index c314f18..1ff42ac 100644 --- a/themes/osi/assets/js/build/theme.js +++ b/themes/osi/assets/js/build/theme.js @@ -1 +1 @@ -(()=>{var e={690:()=>{jQuery},648:()=>{document.addEventListener("DOMContentLoaded",(function(){const e=document.getElementById("remoteForm-form-ContributionPage7"),t=document.getElementById("first_name").closest(".form-group"),n=document.getElementById("last_name").closest(".form-group"),a=document.getElementById("email-primary").closest(".form-group"),s=document.getElementById("credit_card_number").closest(".form-group"),o=document.getElementById("cvv2").closest(".form-group"),r=document.getElementById("credit_card_exp_date_M").closest(".form-group"),l=document.getElementById("credit_card_exp_date_Y").closest(".form-group"),c=document.getElementById("remoteform-submit"),i=document.querySelector("label.rf-label").parentNode,d=document.querySelectorAll('.form-check-input:not([value="54"])'),u=document.createElement("div");u.className="form-check-grid",i.parentNode.insertBefore(u,i),d.forEach((e=>{u.appendChild(e.parentNode)}));const m=document.createElement("div");m.style.display="none",m.append(t,n,a,s,o,r,l,c),e.insertBefore(m,i.nextSibling),document.querySelectorAll(".form-check-label").forEach((e=>{e.textContent=e.textContent.replace(/ - \$[\d\.]+/,"")}));const h=document.querySelector('input[value="54"]');h&&(h.type="checkbox",h.closest(".form-check").querySelector("label").textContent="Yes, I want to become an OSI member!",m.prepend(h.closest(".form-check"))),d.forEach((e=>{e.nextElementSibling.addEventListener("click",(function(){d.forEach((t=>{t!==e&&(t.checked=!1)})),e.checked=!0,e.dispatchEvent(new Event("change"))}))}));const p=document.createElement("button");p.textContent="Contribute",p.type="button",p.addEventListener("click",(()=>{"none"===m.style.display?(m.style.display="block",p.textContent="Cancel",m.style.transition="all 0.3s ease"):(m.style.display="none",p.textContent="Contribute")})),e.appendChild(p)}))},706:()=>{var e,t,n,a,s;e=jQuery,t=e(window).scrollTop(),n=e(".header-main"),e("#content"),e("body #content:not(.has_no_sidebar)"),a=-1,s="header-main-small",n.innerHeight(),n.innerHeight(),e(window).on("scroll",(function(o){var r=e(this).scrollTop();e(window).width()>784?r>100?n.addClass(s):n.removeClass(s):(r>120&&r>t?(a=-1,n.addClass(s)):(-1==a&&(a=r),r{var e;e=jQuery,(()=>{const t=e(".license-categories"),n=["ls","categories"],a=e(".license-search input"),s=e(".category-filter-cb"),o=e("#clear-search"),r=e("#clear-categories"),l=e("#search-prompt"),c=e("#toggle-license-search"),i=e("#toggle-license-categories");let d=window.location.href,u={};const m=()=>{const s={};a.length&&(""!==a.val()?(s.ls=a.val(),l.removeClass("hide"),l.find("span").html(a.val()),c.removeClass("open").siblings().removeClass("open")):(delete s.ls,l.addClass("hide"),c.addClass("open").siblings().addClass("open")));const o=t.find("input:checked");o.length?(o.each(((t,n)=>{s.categories||(s.categories=[]),s.categories.push(e(n).val())})),s.categories=s.categories.join(","),r.removeClass("hide"),i.find("span").html("("+o.length+")")):(delete s.categories,r.addClass("hide"),i.find("span").html(""));const m=new URL(d),h=new URL(d);for(const e of h.searchParams.entries())m.searchParams.delete(e[0]);for(const e in s)m.searchParams.set(e,s[e]);window.history.pushState({path:m.toString()},"",m.toString()),d=m.toString();let g=!1;n.forEach((e=>{u[e]===s[e]&&typeof u[e]==typeof s[e]||(g=!0)})),u=s,g&&p()},h=()=>{e(".license-table .term-item").on("click",(function(n){n.preventDefault();const a=e(this).attr("data-term");t.find('[value="'+a+'"]').prop("checked",!0).parent("label").addClass("active"),m()}))},p=()=>{const t=e(".license-table tbody");t.html("Loading..."),e.post(OSI_LICENSE_DB.ajaxURL,{action:OSI_LICENSE_DB.action,...u},(e=>{e.success&&e.data?.html&&e.data.licenses.length?(t.html(e.data.html),h()):t.html("No licenses found! Please try widening your search.")})).fail((()=>{t.html("Something went wrong! Please refresh and try again.")}))};(()=>{const e=new URL(d);n.forEach((t=>{e.searchParams.has(t)&&(u[t]=e.searchParams.get(t))}))})(),u.s&&a.val(u.s),u.categories&&u.categories.trim().split(",").forEach((e=>{e=e.trim();const n=t.find(`#osi-filter-cb-${e}`);n.length&&n.prop("checked",!0)})),s.each((function(){e(this).is(":checked")&&e(this).parent("label").addClass("active")})),s.is(":checked")&&r.removeClass("hide"),s.on("change",(function(){e(this).parent("label").toggleClass("active"),m()})),e(".license-search form").on("submit",(function(e){e.preventDefault(),m()})),o.on("click",(function(){a.val(""),m()})),r.on("click",(function(){s.prop("checked",!1).parent("label").removeClass("active"),m()})),h()})()},386:()=>{!function(e){const t=jQuery(".single-license .license-meta > span");let n,a;for(let e=0;e{var e;(e=jQuery)(".sub-menu").addClass("menu-collapse"),e(".menu-item-has-children > a").append(''),e(".menu-toggle").on("click",(function(t){t.preventDefault(),e(this).parent().next(".sub-menu").hasClass("menu-collapse")?(e(this).parent().next(".sub-menu").removeClass("menu-collapse"),e(this).parent().parent(".menu-item-has-children").addClass("tab-active"),e(this).parent().parent().parent(".sub-menu").addClass("can-overflow"),e(this).addClass("menu-toggle-active"),t.stopPropagation()):(e(this).parent().next(".sub-menu").addClass("menu-collapse"),e(this).parent().parent(".menu-item-has-children").removeClass("tab-active"),e(this).parent().parent().parent(".sub-menu").removeClass("can-overflow"),e(this).parent().parent().find(".sub-menu").removeClass("can-overflow"),e(this).removeClass("menu-toggle-active"),t.stopPropagation())}))},14:()=>{!function(){var e,t,n,a,s,o;if((e=document.getElementById("site-navigation"))&&void 0!==(t=e.getElementsByTagName("button")[0]))if(void 0!==(n=e.getElementsByTagName("ul")[0])){for(n.setAttribute("aria-expanded","false"),-1===n.className.indexOf("nav-menu")&&(n.className+=" nav-menu"),t.onclick=function(){-1!==e.className.indexOf("toggled")?(e.className=e.className.replace(" toggled",""),t.setAttribute("aria-expanded","false"),n.setAttribute("aria-expanded","false")):(e.className+=" toggled",t.setAttribute("aria-expanded","true"),n.setAttribute("aria-expanded","true"))},s=0,o=(a=n.getElementsByTagName("a")).length;s a, .page_item_has_children > a");if("ontouchstart"in window)for(t=function(e){var t,n=this.parentNode;if(n.classList.contains("focus"))n.classList.remove("focus");else{for(e.preventDefault(),t=0;t{var e;(e=jQuery)("#openSearch").click((function(){e(".header-search-wrapper").slideDown(),e(this).addClass("active"),e(".header-search-wrapper .search-field").focus()})),e("#closeSearch").click((function(){e(".header-search-wrapper").slideUp(),e("#openSearch").removeClass("active")}))},823:()=>{var e,t=document.getElementById("openMainMenu"),n=document.getElementById("closeSidebar"),a=document.getElementById("openSidebar"),s=".nav-main";function o(){var e=document.querySelectorAll("html")[0],t=e.className;-1===t.indexOf("open-the-menu")?e.className=t+" open-the-menu":e.className=t.replace(" open-the-menu","")}function r(){var e=document.querySelectorAll("html")[0],t=e.className;-1===t.indexOf("open-the-sidebar")?e.className=t+" open-the-sidebar":e.className=t.replace(" open-the-sidebar","")}function l(){var e=window.innerHeight,t=window.matchMedia("(max-width: 48.9em)");document.addEventListener("DOMContentLoaded",(function(){t.matches&&(document.querySelectorAll(s)[0].style.height=e-50+"px")}),!1),t.addListener((function(t){t.matches?document.querySelectorAll(s)[0].style.height=e-50+"px":document.querySelectorAll(s)[0].style.height=null}))}null!=t&&(t.attachEvent?(t.attachEvent("onclick",o),null!==a&&a.attachEvent("onclick",r)):(t.addEventListener("click",o),null!==a&&a.addEventListener("click",r))),null!=n&&(n.attachEvent?n.attachEvent("onclick",o):n.addEventListener("click",o)),l(),document.addEventListener("DOMContentLoaded",(function(){l()}),!1),window.onresize=function(){clearTimeout(e),e=setTimeout((function(){l()}),100)}},103:()=>{/(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",(function(){var e,t=location.hash.substring(1);/^[A-z0-9_-]+$/.test(t)&&(e=document.getElementById(t))&&(/^(?:a|select|input|button|textarea)$/i.test(e.tagName)||(e.tabIndex=-1),e.focus())}),!1)},624:()=>{"use strict";class e{constructor(e){this.tableNode=e,this.columnHeaders=e.querySelectorAll("thead th"),this.sortColumns=[];for(var t=0;ta.value?-1:1}));a.firstChild;)a.removeChild(a.lastChild);for(var d=0;d{var e;(e=jQuery)(document).ready((function(){e(".toggle-header h2").click((function(){var t=e(this).parent().attr("id");e(this).parent().hasClass("open")?(e(this).parent().removeClass("open"),e('[data-toggle="'+t+'"]').removeClass("open")):(e(this).parent().addClass("open"),e('[data-toggle="'+t+'"]').addClass("open"))}))}))}},t={};function n(a){var s=t[a];if(void 0!==s)return s.exports;var o=t[a]={exports:{}};return e[a](o,o.exports,n),o.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var a in t)n.o(t,a)&&!n.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";n(690),n(706),n(876),n(14),n(624),n(655),n(7),n(823),n(103),n(151),n(386),n(648)})()})(); \ No newline at end of file +(()=>{var e={690:()=>{jQuery},706:()=>{var e,t,a,n,s;e=jQuery,t=e(window).scrollTop(),a=e(".header-main"),e("#content"),e("body #content:not(.has_no_sidebar)"),n=-1,s="header-main-small",a.innerHeight(),a.innerHeight(),e(window).on("scroll",(function(r){var o=e(this).scrollTop();e(window).width()>784?o>100?a.addClass(s):a.removeClass(s):(o>120&&o>t?(n=-1,a.addClass(s)):(-1==n&&(n=o),o{var e;e=jQuery,(()=>{const t=e(".license-categories"),a=["ls","categories"],n=e(".license-search input"),s=e(".category-filter-cb"),r=e("#clear-search"),o=e("#clear-categories"),l=e("#search-prompt"),i=e("#toggle-license-search"),c=e("#toggle-license-categories");let d=window.location.href,u={};const h=()=>{const s={};n.length&&(""!==n.val()?(s.ls=n.val(),l.removeClass("hide"),l.find("span").html(n.val()),i.removeClass("open").siblings().removeClass("open")):(delete s.ls,l.addClass("hide"),i.addClass("open").siblings().addClass("open")));const r=t.find("input:checked");r.length?(r.each(((t,a)=>{s.categories||(s.categories=[]),s.categories.push(e(a).val())})),s.categories=s.categories.join(","),o.removeClass("hide"),c.find("span").html("("+r.length+")")):(delete s.categories,o.addClass("hide"),c.find("span").html(""));const h=new URL(d),m=new URL(d);for(const e of m.searchParams.entries())h.searchParams.delete(e[0]);for(const e in s)h.searchParams.set(e,s[e]);window.history.pushState({path:h.toString()},"",h.toString()),d=h.toString();let v=!1;a.forEach((e=>{u[e]===s[e]&&typeof u[e]==typeof s[e]||(v=!0)})),u=s,v&&p()},m=()=>{e(".license-table .term-item").on("click",(function(a){a.preventDefault();const n=e(this).attr("data-term");t.find('[value="'+n+'"]').prop("checked",!0).parent("label").addClass("active"),h()}))},p=()=>{const t=e(".license-table tbody");t.html("Loading..."),e.post(OSI_LICENSE_DB.ajaxURL,{action:OSI_LICENSE_DB.action,...u},(e=>{e.success&&e.data?.html&&e.data.licenses.length?(t.html(e.data.html),m()):t.html("No licenses found! Please try widening your search.")})).fail((()=>{t.html("Something went wrong! Please refresh and try again.")}))};(()=>{const e=new URL(d);a.forEach((t=>{e.searchParams.has(t)&&(u[t]=e.searchParams.get(t))}))})(),u.s&&n.val(u.s),u.categories&&u.categories.trim().split(",").forEach((e=>{e=e.trim();const a=t.find(`#osi-filter-cb-${e}`);a.length&&a.prop("checked",!0)})),s.each((function(){e(this).is(":checked")&&e(this).parent("label").addClass("active")})),s.is(":checked")&&o.removeClass("hide"),s.on("change",(function(){e(this).parent("label").toggleClass("active"),h()})),e(".license-search form").on("submit",(function(e){e.preventDefault(),h()})),r.on("click",(function(){n.val(""),h()})),o.on("click",(function(){s.prop("checked",!1).parent("label").removeClass("active"),h()})),m()})()},386:()=>{!function(e){const t=jQuery(".single-license .license-meta > span");let a,n;for(let e=0;e{var e;(e=jQuery)(".sub-menu").addClass("menu-collapse"),e(".menu-item-has-children > a").append(''),e(".menu-toggle").on("click",(function(t){t.preventDefault(),e(this).parent().next(".sub-menu").hasClass("menu-collapse")?(e(this).parent().next(".sub-menu").removeClass("menu-collapse"),e(this).parent().parent(".menu-item-has-children").addClass("tab-active"),e(this).parent().parent().parent(".sub-menu").addClass("can-overflow"),e(this).addClass("menu-toggle-active"),t.stopPropagation()):(e(this).parent().next(".sub-menu").addClass("menu-collapse"),e(this).parent().parent(".menu-item-has-children").removeClass("tab-active"),e(this).parent().parent().parent(".sub-menu").removeClass("can-overflow"),e(this).parent().parent().find(".sub-menu").removeClass("can-overflow"),e(this).removeClass("menu-toggle-active"),t.stopPropagation())}))},14:()=>{!function(){var e,t,a,n,s,r;if((e=document.getElementById("site-navigation"))&&void 0!==(t=e.getElementsByTagName("button")[0]))if(void 0!==(a=e.getElementsByTagName("ul")[0])){for(a.setAttribute("aria-expanded","false"),-1===a.className.indexOf("nav-menu")&&(a.className+=" nav-menu"),t.onclick=function(){-1!==e.className.indexOf("toggled")?(e.className=e.className.replace(" toggled",""),t.setAttribute("aria-expanded","false"),a.setAttribute("aria-expanded","false")):(e.className+=" toggled",t.setAttribute("aria-expanded","true"),a.setAttribute("aria-expanded","true"))},s=0,r=(n=a.getElementsByTagName("a")).length;s a, .page_item_has_children > a");if("ontouchstart"in window)for(t=function(e){var t,a=this.parentNode;if(a.classList.contains("focus"))a.classList.remove("focus");else{for(e.preventDefault(),t=0;t{var e;(e=jQuery)("#openSearch").click((function(){e(".header-search-wrapper").slideDown(),e(this).addClass("active"),e(".header-search-wrapper .search-field").focus()})),e("#closeSearch").click((function(){e(".header-search-wrapper").slideUp(),e("#openSearch").removeClass("active")}))},823:()=>{var e,t=document.getElementById("openMainMenu"),a=document.getElementById("closeSidebar"),n=document.getElementById("openSidebar"),s=".nav-main";function r(){var e=document.querySelectorAll("html")[0],t=e.className;-1===t.indexOf("open-the-menu")?e.className=t+" open-the-menu":e.className=t.replace(" open-the-menu","")}function o(){var e=document.querySelectorAll("html")[0],t=e.className;-1===t.indexOf("open-the-sidebar")?e.className=t+" open-the-sidebar":e.className=t.replace(" open-the-sidebar","")}function l(){var e=window.innerHeight,t=window.matchMedia("(max-width: 48.9em)");document.addEventListener("DOMContentLoaded",(function(){t.matches&&(document.querySelectorAll(s)[0].style.height=e-50+"px")}),!1),t.addListener((function(t){t.matches?document.querySelectorAll(s)[0].style.height=e-50+"px":document.querySelectorAll(s)[0].style.height=null}))}null!=t&&(t.attachEvent?(t.attachEvent("onclick",r),null!==n&&n.attachEvent("onclick",o)):(t.addEventListener("click",r),null!==n&&n.addEventListener("click",o))),null!=a&&(a.attachEvent?a.attachEvent("onclick",r):a.addEventListener("click",r)),l(),document.addEventListener("DOMContentLoaded",(function(){l()}),!1),window.onresize=function(){clearTimeout(e),e=setTimeout((function(){l()}),100)}},103:()=>{/(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",(function(){var e,t=location.hash.substring(1);/^[A-z0-9_-]+$/.test(t)&&(e=document.getElementById(t))&&(/^(?:a|select|input|button|textarea)$/i.test(e.tagName)||(e.tabIndex=-1),e.focus())}),!1)},624:()=>{"use strict";class e{constructor(e){this.tableNode=e,this.columnHeaders=e.querySelectorAll("thead th"),this.sortColumns=[];for(var t=0;tn.value?-1:1}));n.firstChild;)n.removeChild(n.lastChild);for(var d=0;d{var e;(e=jQuery)(document).ready((function(){e(".toggle-header h2").click((function(){var t=e(this).parent().attr("id");e(this).parent().hasClass("open")?(e(this).parent().removeClass("open"),e('[data-toggle="'+t+'"]').removeClass("open")):(e(this).parent().addClass("open"),e('[data-toggle="'+t+'"]').addClass("open"))}))}))}},t={};function a(n){var s=t[n];if(void 0!==s)return s.exports;var r=t[n]={exports:{}};return e[n](r,r.exports,a),r.exports}a.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return a.d(t,{a:t}),t},a.d=(e,t)=>{for(var n in t)a.o(t,n)&&!a.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";a(690),a(706),a(876),a(14),a(624),a(655),a(7),a(823),a(103),a(151),a(386)})()})(); \ No newline at end of file diff --git a/themes/osi/assets/js/src/theme/donation-form.js b/themes/osi/assets/js/src/theme/donation-form.js index 0245664..9fbe60f 100644 --- a/themes/osi/assets/js/src/theme/donation-form.js +++ b/themes/osi/assets/js/src/theme/donation-form.js @@ -1,4 +1,14 @@ -document.addEventListener('DOMContentLoaded', function() { +function waitForElement(selector, callback) { + if (document.querySelector(selector)) { + callback(); + } else { + setTimeout(function() { + waitForElement(selector, callback); + }, 100); + } +} + +waitForElement("#remoteForm-form-ContributionPage7", function() { const form = document.getElementById('remoteForm-form-ContributionPage7'); const firstName = document.getElementById('first_name').closest('.form-group'); const lastName = document.getElementById('last_name').closest('.form-group'); diff --git a/themes/osi/assets/js/src/theme/theme.js b/themes/osi/assets/js/src/theme/theme.js index 710b320..429bf13 100644 --- a/themes/osi/assets/js/src/theme/theme.js +++ b/themes/osi/assets/js/src/theme/theme.js @@ -9,4 +9,3 @@ import './sidebar-nav.js'; import './skip-link-focus-fix.js'; import './search-toggle.js'; import './license-header-wrap.js'; -import './donation-form.js';