-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated - jquery to javascript, created prefixed class, added ability…
… to have multiple iframeIds
- Loading branch information
1 parent
6adc907
commit d165d45
Showing
1 changed file
with
35 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |