(function () { var integrate = function (){ console.log('integration'); // url of the sript var scriptUrl = document.getElementById('uwm_mmp_integration'); // get lineup key var lineupKey = getParameterByName('lid', scriptUrl.src); // get ymm from parent window var uwm_id = getParameterByName('uwm_id'); if ( !uwm_id ) { // try gettting ymm from script src url uwm_id = getParameterByName('uwm_id', scriptUrl.src); } // get uwmid var uwmid = getParameterByName('uwmid'); // add iframe ymm url variable var iframeUwmId = ( uwm_id ? '&uwm_id=' + uwm_id : '' ); // get targeted Vehicle and add target vehicle to query string and ignore if uwm_id has any value var targetedVehicle = getParameterByName('target', scriptUrl.src); if(targetedVehicle){ iframeUwmId = '&uwm_id=' + targetedVehicle; } iframeUwmId += ( uwmid ? '&uwmid=' + uwmid : '' ); // create iframe URL var iframeUrl = 'https://uwmedia.us/cm_lineup/front/?lid=' + lineupKey + iframeUwmId; // main container element var uwmIframeContainer = document.getElementById('uwm_mmp'); var pymJsLoaderScript = document.createElement('script'); pymJsLoaderScript.setAttribute( 'src','https://pym.nprapps.org/pym-loader.v1.min.js' ); uwmIframeContainer.appendChild(pymJsLoaderScript); // setup iframe uwmIframeContainer.innerHTML = "
"; /** * Get param from URL by name * * @param name of the param you are looking for * @param url to look for the param in by name * * @return String value of the param found */ function getParameterByName(name, url) { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent( results[2].replace(/\+/g, " ") .replace(/^\s+|\s+$/g,'') .replace(/ /g,'_') .replace(/%20| /g,'_') .replace(/%20_| /g,'_') .replace(/_+/g,'_') ); } /** * Get host from url string * * @param url to look for the param in by name * * @return String value of the host found */ function extractHostname( url ) { var tmp = document.createElement ('a'); tmp.href = url; return tmp.hostname; } }; /* integrate */ if (document.readyState !== 'loading') { integrate(); } else { document.addEventListener('DOMContentLoaded', integrate); } /* integrate */ })();