(function () { var getParams = function (url) { var params = {}; var parser = document.createElement('a'); parser.href = url; var query = parser.search.substring(1); var vars = query.split('&'); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split('='); params[pair[0]] = decodeURIComponent(pair[1]); } return params; }; var integrate = function (){ // override dealer site iframe height var style = document.createElement('style'); var css = '#uwm_pym_iframe iframe { height: revert-layer !important; }'; document.head.appendChild( style ); style.appendChild( document.createTextNode( css ) ); console.log('integrate'); // url of the sript var scriptUrl = document.getElementById('uwm_kia_integration'); // get lineup key var dealerCode = getParameterByName('d', scriptUrl.src); // get model var model = getParameterByName( 'm' ); var modelFromScript = getParameterByName( 'm', scriptUrl.src ); if ( model ) { // model from window location href model = model; } else if ( modelFromScript ) { // get model from integration script url model = modelFromScript; } // get model var salesdemo = getParameterByName( 'salesdemo' ); var params = getParams(window.location.href); var sd_campaign = (Object.keys(params).length && params.sd_campaign != undefined) ? params.sd_campaign : ""; if ( 'on' == salesdemo ) { var sString = '&salesdemo=on'; } else { var sString = ''; } // get intro status var introInfo = getParameterByName('intro', scriptUrl.src); // create iframe url var iframeUrl = '//uwcampaigns.com/cm_kia/front/?d=' + dealerCode + '&integration=&m=' + model +'&intro='+introInfo + "&sd_campaign=" + sd_campaign ; // main container element var uwmIframeContainer = document.getElementById('uwm_kia'); // create pym script and add it to the dom var pymScript = document.createElement('script'); pymScript.async = true; pymScript.src = '//uwcampaigns.com/cm_kia/js/global/front/pym.js'; // setup iframe uwmIframeContainer.innerHTML = "
"; // append pym script to main container uwmIframeContainer.appendChild( pymScript ); console.log('scriptUrl : ',scriptUrl,'dealerCode : ',dealerCode,'model : ',model,'salesdemo : ',salesdemo,'sString : ',sString,'sString : ',sString,'introInfo : ',introInfo,'iframeUrl : ',iframeUrl,'uwmIframeContainer : ',uwmIframeContainer); /** * 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, " ")); } console.log('integrated'); } integrate(); })();