From d165d45c5c08bd28545516d9b74065d1d2517584 Mon Sep 17 00:00:00 2001 From: Steve Jones Date: Thu, 1 Feb 2024 01:11:52 -0500 Subject: [PATCH] updated - jquery to javascript, created prefixed class, added ability to have multiple iframeIds --- src/js/frontend.js | 53 ++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/src/js/frontend.js b/src/js/frontend.js index 9d01c37..febecfb 100644 --- a/src/js/frontend.js +++ b/src/js/frontend.js @@ -1,19 +1,36 @@ -jQuery(function ($) { - $(window).load(function () { - const iframe = document.getElementById('rwcGetParams'); - if (document.contains(iframe)) { - const loc = window.location.toString(); - const params = loc.split('?')[1]; - let query; - if (params) { - if (iframe.src.indexOf('?') >= 0) { - query = '&'; - } else { - query = '?'; +const EDPPI = EDPPI || {}; + +EDPPI.IframeParameterAppender = class { + constructor(iframeIds) { + this.iframeIds = Array.isArray(iframeIds) ? iframeIds : [iframeIds]; + this.init(); + } + + init() { + document.addEventListener('DOMContentLoaded', () => { + this.appendParamsToIframes(); + }); + } + + appendParamsToIframes() { + window.addEventListener('load', () => { + this.iframeIds.forEach((iframeId) => { + const iframe = document.getElementById(iframeId); + if (iframe && document.body.contains(iframe)) { + const loc = window.location.toString(); + const params = loc.split('?')[1]; + if (params) { + const query = iframe.src.includes('?') ? '&' : '?'; + const newsrc = iframe.src + query + params; + iframe.setAttribute('src', newsrc); + } } - const newsrc = iframe.src + query + params; - $('#rwcGetParams').attr('src', newsrc); - } - } - }); -}); + }); + }); + } +}; + +// Usage +new EDPPI.IframeParameterAppender(['rwcGetParams', 'eqdGetParams']); +// Or for a single iframe +//new EDPPI.IframeParameterAppender('rwcGetParams');