/** * State Info Widget * * Usage: * - Add this where widget will be displayed:
* - Add before footer tag: * * In main.js we will call stateInfo module. So need to add to GeoLocated function: * - if(typeof(location.state) != "undefined") SLFLPModules_stateInfo.run(location.state); * (check /state-info-widget/test/slf-state-info.js) * To Create new states create a new or copy IL.html and add state code to list * so to add CA: var stateList = [‘IL’, 'CA']; and add CA.html */ if(typeof String.prototype.trim !== 'function') { String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); } } window.SLFLPModules_stateInfo = (function() { var stateList = ['IL']; var stateListSuccess = ['IL']; function run(state){ //check if we are testing if(getQueryVariable('test-state-widget') != 'NA') state = getQueryVariable('test-state-widget'); //only allow states which is in our list and have a html file if(stateList.indexOf(state) == -1) return false; document.getElementById('state_info_widget').innerHTML =''; } function resize(size){ document.getElementById('state_info_widget').style.height = size + "px"; document.getElementById('state_info_widget_iframe').style.height = size + "px"; } function runSuccess(){ //try address first if(getQueryVariable('address') != 'NA'){ var address = getQueryVariable('address').split(","); if(address.length>2){ state = address[address.length-2].trim(); if(state.length == 2){ var loc = {}; loc.state = state; runSuccessGeo(loc); return false; } } } var url = 'https://geoip.solarleadfactory.com/callback/?c=SLFLPModules_stateInfo.runSuccessGeo'; var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = url; var x = document.getElementsByTagName('head')[0]; x.appendChild(s); } function runSuccessGeo(location){ var state = ''; if(typeof(location.state) != "undefined") state = location.state; //check if we are testing if(getQueryVariable('test-state-widget') != 'NA') state = getQueryVariable('test-state-widget'); //only allow states which is in our list and have a html file if(stateListSuccess.indexOf(state) == -1) return false; document.getElementById('state_info_widget').innerHTML =''; } function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split('&'); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split('='); if (decodeURIComponent(pair[0]) == variable) { return decodeURIComponent(pair[1]); } } return 'NA'; } return { run: run, runSuccess: runSuccess, runSuccessGeo: runSuccessGeo, resize:resize } }()); if(typeof(SLFLPModules_stateInfo_loaded) == "function") SLFLPModules_stateInfo_loaded();