Skip to content

Commit

Permalink
updated - jquery to javascript, created prefixed class, added ability…
Browse files Browse the repository at this point in the history
… to have multiple iframeIds
  • Loading branch information
SteveJonesDev committed Feb 1, 2024
1 parent 6adc907 commit d165d45
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions src/js/frontend.js
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit d165d45

Please sign in to comment.