/** * @author Keith Bentrup * @classDescription The DynamicScript class creates optionally grouped script tags with optional callbacks. * @param {String} fullURL The URL to retrieve * @param {Function} optional callback A function to execute when the script has loaded * @param {String} optional group A group to associate related script elements used to check when an entire group is finished loading * @return {Object} Returns a DynamicScript object * @constructor * * The DynamicScript class can be used to lazy load javascript, make grouped JSONP calls, etc. * * ex: * var myDSObj = new DynamicScript('http://www.example.com/js/site.js', function () { ... }); * var myJSONP1 = new DynamicScript('http://www.example.com/js/site.js', function () { ... }, 'cat svc json'); * var myJSONP2 = new DynamicScript('http://www.example.com/js/site.js', function () { ... }, 'cat svc json'); */ // This defines the context root for all URL's var baseURL = "http://www.toysrus.de" + ("/isvc/trude-sl/.".replace(/\./,'')); //set media server url var akURL = ""; if (akURL == "") { akURL = baseURL; } else { akURL = akURL + "/"; } //following code is used for code safety of prepoulating the zip code from header section var _myStoreZipCode=""; var _myStoreZipFlag=false; if(typeof(myStoreZipCode) !== 'undefined'){ _myStoreZipCode=myStoreZipCode; if(myStoreZipCode == ""){ _myStoreZipFlag=true; } } if(typeof getMyStoreField('myStoreAPI',2) !== 'undefined'){ if(_myStoreZipFlag){ _myStoreZipCode = getMyStoreField('myStoreAPI',2); } } var _myStoreEnableAttr=""; if(typeof(myStoreEnabled) !=='undefined'){ _myStoreEnableAttr=myStoreEnabled; } var configLoaded = false; var countryName = "DE"; useSLAnalytics = "true" || false; DynamicScript = function (fullURL, confObj) { var confObj = confObj || {}; this._startLoading(); if (confObj.group) this.group = this._addToGroup(confObj.group); this.scriptEl = this._createScriptTag(fullURL, confObj); // note: just b/c a script is "loaded" doesn't mean it's executed, so some symbols (var, function, object) may be undefined // be sure to test (with an interval) in your callback if it requires a particular symbol if (confObj.callback) { this._setCallback(confObj.callback); } else { var ds = this; this._setCallback(function () { ds._stopLoading(); }); } }; DynamicScript._groups = {}; DynamicScript._scriptCounter = 0; DynamicScript.prototype = { _addToGroup : function (group) { if (!DynamicScript._groups[group]) DynamicScript._groups[group] = []; var DSGroup = DynamicScript._groups[group]; var len = DSGroup.length; DSGroup[len] = this; return group; }, _createScriptTag : function (fullURL, config) { var script = document.createElement("script"); if (!config.type) config.type = "text/javascript"; script.setAttribute("type", config.type); script.setAttribute("charset", "utf-8"); if (!config.cache) { fullURL += (/\?/.test(fullURL) ? '&' : '?' ) + (new Date()).getTime(); } script.setAttribute("src", fullURL); DynamicScript._scriptCounter = DynamicScript._scriptCounter + 1; script.setAttribute("id", config.id || 'DynamicScript' + DynamicScript._scriptCounter); document.getElementsByTagName("head")[0].appendChild(script); return script; }, _setCallback : function (callback) { var ds = this; // DynamicScript instance var scriptEl = ds.scriptEl; scriptEl.onreadystatechange = function() { // IE uses onreadystatechange to trigger callback if (scriptEl.readyState === 'loaded' || scriptEl.readyState === 'complete') { ds._stopLoading(); callback(this); } }; scriptEl.onload = function() { // others use onload to trigger callback ds._stopLoading(); callback(this); }; // Replacing this code since jQuery might not be loaded yet //if (jQuery.browser.safari && scriptEl.addEventListener) { // safari if (/Safari\/[0-9]+/.test(navigator.userAgent)) { ds._stopLoading(); scriptEl.addEventListener("load", function(){ callback(scriptEl) }); } }, _startLoading : function () { this.loading = true; }, _stopLoading : function () { this.loading = false; }, removeScriptTag : function () { document.getElementsByTagName("head")[0].removeChild(scriptEl); } }; DynamicScript.scriptsInGroupActive = function(group) { var groupArray = DynamicScript._groups[group]; if (groupArray) { var i = groupArray.length; while (i--) { if (groupArray[i].loading) return true; } } return false; }; DynamicScript.anyDSActive = function() { if (DynamicScript._groups) { var groupsObj = DynamicScript._groups; for (g in groupsObj) { var groupArray = groupsObj[g]; var i = groupArray.length; while (i--) { if (groupArray[i].loading) return true; } } } return false; }; // ====================== END DYNAMIC SCRIPTS ====================== // ====================== BEGIN TEMPLATES ========================== var locationCode = ""; var templates = [ // Main template '', // Map Bubble template '', // Result List template '', // Result Footer template '' ]; // Print the templates out for (var c=0; c' + localizedStyles + ''); document.write(''); // Load scripts if (window.jQuery && parseFloat(jQuery.fn.jquery)>=1.4) { OurJQuery = jQuery; var jsURLs = 'js/jqueryUI-jqueryPlugins-utils.js,js/storeLocator.js,'.split(","); } else { var jsURLs = 'js/jquery-jqueryUI-jqueryPlugins-utils.js,js/storeLocator.js,'.split(","); } if (jsURLs.length > 1) jsURLs.pop(); for (var c=0; c storeLocatorConfig.maxResults) { // We got too many results, but we want to suppress the error // message and show what we can. delete storeLocator.vars.results.ERRORS; storeLocator.vars.results.RESULTS.splice(storeLocatorConfig.maxResults, storeLocator.vars.results.COUNT - storeLocatorConfig.maxResults); storeLocator.vars.results.COUNT = storeLocatorConfig.maxResults; storeLocator.setLocation(); $("#result-footer").show(); } } else { $("#result-footer").show(); } storeLocator.vars.userSearched = false; }); // Setting up hover effects... var openMenu = function(obj) { clearTimeout($('#store-types-new').attr("timeout")); if (obj.attr("id") === "store-types-bubble") { clearTimeout(obj.attr("timeout")); } $("#store-search-type, #store-types-new").addClass("active"); }; $('#store-search-type').live('click',function() { if ($(this).hasClass("active")) { $("#store-search-type, #store-types-new, #store-types-bubble").removeClass("active"); } else { openMenu($(this)); } }); $('#store-search-type, #store-types-new, #store-types-bubble').live('mouseover',function() { if ($(this).attr("id") === "store-search-type" && !$(this).hasClass("active")) return; openMenu($(this)); }); $('#store-search-type, #store-types-new, #store-types-bubble').live('mouseout',function() { if ($(this).attr("id") === "store-types-bubble") { $(this).attr("timeout",setTimeout(function() { $('#store-types-bubble').removeClass("active"); },300)); } $('#store-types-new').attr("timeout",setTimeout(function() { $('#store-search-type, #store-types-new, #store-types-bubble').removeClass("active"); },300)); }); // Control types bubbles $('#controls label').live('hover',function() { var obj = $(this); var label_class = $(this).attr('class'); var bubble = $('#control-types-bubble'); //var left = obj.parent("dt").parent("dl").position().left + obj.position().left + obj.width() + 59; //QC77414 //var top = obj.position().top + 75; //QC77913 var left= obj.position().left + obj.width() + obj.parent("dt").parent("dl").position().left + 300; var top = $('#map-container').position().top-69; var buffer = '

%s

%s

'; bubble.removeClass('right-tail pan-text center-text zoom-text map-type-text').addClass(label_class); if (obj.hasClass('pan-text')) { buffer = buffer.replace(/%s/,storeLocatorConfig.panMapControls.heading); buffer = buffer.replace(/%s/,storeLocatorConfig.panMapControls.tooltip); } else if (obj.hasClass('center-text')) { buffer = buffer.replace(/%s/,storeLocatorConfig.resetMapControl.heading); buffer = buffer.replace(/%s/,storeLocatorConfig.resetMapControl.tooltip); } else if (obj.hasClass('zoom-text')) { buffer = buffer.replace(/%s/,storeLocatorConfig.zoomMapControls.heading); buffer = buffer.replace(/%s/,storeLocatorConfig.zoomMapControls.tooltip); } else if (obj.hasClass('map-type-text')) { buffer = buffer.replace(/%s/,storeLocatorConfig.mapTypeControls.heading); buffer = buffer.replace(/%s/,storeLocatorConfig.mapTypeControls.tooltip); bubble.addClass('right-tail'); left -= (bubble.width() + obj.width() + obj.position().left + 24); //QC77414 top -= 5; //QC77551 } else { return; } //Germany specific tooltip settings if ($('body').hasClass('de_DE') || $('body').hasClass('de_CH') || $('body').hasClass('nl_NL') || $('body').hasClass('es_ES') || $('body').hasClass('pt_PT')){ //if (!obj.hasClass('map-type-text')) top = 100; if (obj.hasClass('zoom-text')) top += 12; } else if ($('body').hasClass('fr_FR')){ if (obj.hasClass('map-type-text')){ left = 520; top = 116; } } $('#control-types-bubble .bubble-message').html(buffer); bubble.css({ left:left, top:top }); bubble.toggle(); }); // Store types help bubble $('#store-types-new .store-help, #store-types-new .display-name').live('mouseover',function() { var obj = $(this); clearTimeout($('#store-types-bubble').attr("timeout")); //If hovered over store type text if(obj.is("div.display-name")){ $('#store-types-bubble .bubble-message').html(obj.prev().children().html()); var left = obj.prev().children().position().left-25; } else { $('#store-types-bubble .bubble-message').html(obj.html()); var left = obj.position().left-25; } if(left > 700){ //If bubble goes out of the map frame left -=200; //Move bubble inside the frame $("div.store-types-bubble-tail").css("left", "230px"); //Set tail position }else{ $("div.store-types-bubble-tail").css("left", "14px"); //Set tail position to normal } var top = $("#map-container").position().top; if ($("body").hasClass("ie6")) top -= 2; /*if ((top-108) > ($('#store-types-new').height() / 2)) { $('#store-types-bubble .bubble-tail').css({ top:"auto", bottom:"14px" }); top -= $('#store-types-bubble').height() - 58; } else { $('#store-types-bubble .bubble-tail').css({ top:"14px" }); }*/ $('#store-types-bubble').css({ left:left, top:top }).addClass("active"); }); $('#store-types-new .store-help, #store-types-new .display-name').live('mouseout',function() { $('#store-types-bubble').attr("timeout",setTimeout(function() { $('#store-types-bubble').removeClass("active"); },300)); }); // Setup the welcome and hide buttons. $('#welcome-msg-button').live('click',function(e) { if ($('#welcome-msg').is(':visible')){ //If the welcome message is showing... $('#welcome-msg').slideUp(null,function() { $('#welcome-msg-button').removeClass('hide-button').addClass('welcome-button'); }); } else { //Otherwise, if it's not... $('#welcome-msg').slideDown(null,function() { $('#welcome-msg-button').removeClass('welcome-button').addClass('hide-button'); }); } }); // Make store name open map bubble $('#result-list .store-name').live('click',function(e){ storeLocator.events.resultList(e); storeLocator.hours.hide(); }); // Print icon $('#print-page').live('click',function(){ window.print(); }); // Map bubble tweak storeLocator.events.mapBubble = function(e) { var el = $(e.target); if (el.hasClass('close')) { storeLocator.map.bubble.hide(); storeLocator.list.goDim(); } else { if(!el.hasClass('active')){ $("#map-bubble .active").removeClass('active'); el.addClass('active'); if (el.hasClass('info')) { $("#map-bubble dd.info").addClass('active'); } else { $("#map-bubble dd.hours").addClass('active'); } } } }; // Map bubble tweak storeLocator.map.bubble.show = function(i,v,rec,marker,pan) { storeLocator.map.bubble.hide(); storeLocator.fire('sl:store-locator-store-select', v.store.locationCode) var pixels = storeLocator.map.markerToPixel(marker); var bubble = storeLocator.map.bubble.getInstanceOf(v.store.storeType.typeId, i, u.extend(v, {showDistance:storeLocator.vars.showDistance})); var offset = $('#map').offset(); var left = pixels.x + offset.left + 10; var top = pixels.y - $('#map-bubble').height() + offset.top + $("#map-bubble .tail").attr("offsetTop") + $("#map-bubble .tail").height() - 40; if ((left + $("#map-bubble").width()) > $(document).width()) { $("#map-bubble").addClass("right-tail"); left = pixels.x + offset.left - $("#map-bubble").width() - $("#map-bubble .tail").width() + 10; } else { $("#map-bubble").removeClass("right-tail"); } bubble.css({ left:left + "px", top:top + "px" }); if (pan) { storeLocator.list.pan(bubble.page); } storeLocator.list.hightLight(rec); }; // Map marker tweak storeLocator.map.marker.base = function(path) { var icon = new google.maps.MarkerImage(path); //icon.url = path; //icon.url = akURL + "images/store-icon-shadow.png"; //icon.size = new google.maps.Size(31,35); icon.size = new google.maps.Size(28,31); icon.anchor = new google.maps.Point(6,20); return icon; }; //Modified directions popup function //This modification adds localization support storeLocator.directions.popup = function(el){ storeLocator.fire('loading-popup-directions') var v = u.templateUtils.getData(el) //Initialize locale variable var popupLocale = 'us'; //Get current locale from body tag class if ($('body').hasClass('fr_CA') || $('body').hasClass('fr_FR')){ popupLocale = 'fr'; } else if ($('body').hasClass('de_DE') || $('body').hasClass('de_AT') || $('body').hasClass('de_CH') ) { popupLocale = 'de'; } else if ($('body').hasClass('nl_NL') ){ popupLocale = 'nl'; } else if ($('body').hasClass('es_ES') ){ popupLocale = 'es'; }else if ($('body').hasClass('pt_PT') ){ popupLocale = 'pt'; } if(storeLocator.vars.address != " "){ window.open('//maps.google.com/maps?saddr='+storeLocator.vars.lat+','+storeLocator.vars.lon+'('+encodeURI(storeLocator.vars.address)+')&daddr='+v.store.latitude+','+v.store.longitude+'('+encodeURI(v.store.address+' '+ ((v.store.address1)?v.store.address1+' ':'') + v.store.city+', '+v.store.stateCode+' '+v.store.postalCode)+')&hl=' + popupLocale, "", "resizable=yes,scrollbars=yes,status=yes") }else{ window.open('//maps.google.com/maps?q='+v.store.latitude+','+v.store.longitude+'('+encodeURI(v.store.address + ' ' + ((v.store.address1)?v.store.address1+' ':'') + v.store.city+', '+v.store.stateCode+' '+v.store.postalCode)+')&hl=' + popupLocale, "", "resizable=yes,scrollbars=yes,status=yes") } } // Modifying buildAddress behavior to accomodate the Reset button storeLocator.buildAddress = function() { var string = ''; if (storeLocator.config.radius.enabled && storeLocator.config.radius.options.length > 0) storeLocator.vars.radius = parseFloat($('#store-search-radius').val()); var address = storeLocator.vars.userSearchText || $('#store-search-street').val().uStrip(); if (address) { string += address; } else { storeLocator.resetPage(true); storeLocator.msg(storeLocator.templates.blankSearch); $('#result-list').html(storeLocator.templates.resultListError.uTemplate({ERRORS:{title:'', message:storeLocator.templates.blankSearch}})); $('#hide-results').hide(); $('#store-locator').removeClass('searching'); } return string; }; // We need the Reset button to search instead of pan var controlsHandler = storeLocator.events.controls; storeLocator.events.controls = function(e) { if (e.target.id === "re-center") { storeLocator.map.bubble.hide(); storeLocator.vars.showDistance = true; storeLocator.updateMap(); storeLocator.fire('center',{e:e}); return; } controlsHandler(e); }; /* Store locator hours flyout */ // configuration, and show/hide methods storeLocator.hours = { showing: false, previous: null, left: $("#hours-inner").css("left"), show: function(top, html){ $('#hours-outer').css({"display":"block"}); $("#hours-inner") .html(html) .css({"top":top}) .animate({"left":0}); storeLocator.hours.showing = true; }, hide: function(){ $("#hours-inner").animate({"left":this.left}, 100).parent().css({"display":"none"}); storeLocator.hours.showing = false; //$('#hours-outer').; } } $(".hours-animated").live("click", function(e){ storeLocator.events.resultList(e); var store = $(this).parents(".store"), top = parseInt(store.position().top) + parseInt($("#rec-slider").css("top")) + parseInt($("#result-header").css("height")), html = store.find(".hours-info").html() || "", current = parseInt(store.attr("id").match(/\d+/)); if (!storeLocator.hours.showing) { storeLocator.hours.show(top, html); } else { storeLocator.hours.hide(); if (!(current == storeLocator.hours.previous)) { // let hide_hours() finish animating setTimeout(function(){ storeLocator.hours.show(top, html);}, 100); } } storeLocator.hours.previous = current; }); /*Code to prePopulate the results on Store Locator Page after submission of from from header by User for MyStore Project*/ if(_myStoreZipCode != ""){ $('#store-search-submit').click(); } /*Code to retreive store Information For Setting up values in Cookie for My-Store Project*/ $(".makeMyStore").live("click",function(){ var $m=$(this).parent().parent(); var _storeName =$m.find('a.store-name')[0].innerHTML; var _address1=$m.find('p.store-address .address')[0].innerHTML; var _address2=$m.find('p.store-address .address')[1].innerHTML; var _address3=$m.find('p.store-address .address')[2] !== undefined ? $m.find('p.store-address .address')[2].innerHTML :""; var _phone=$m.find('input[name="storePhone"]').val(); var _fax=$m.find('input[name="storeFax"]').val() ? $m.find('input[name="storeFax"]').val() : ""; var _storeFrontId=$m.find('input[name="storeFrontId"]').val(); var _storeCity=$m.find('input[name="storeCity"]').val(); var _storePostal=$m.find('input[name="storePostal"]').val(); var cookieText="StoreHeaderName="+_storeName+"&"+"Address1="+_address1+"&"+"Address2="+_address2+"&"+"Address3="+_address3+"&"+ "comb-addr="+""+"&"+"Phone="+_phone+"&"+"City="+_storeCity+"&"+"Fax="+_fax; var javaCookie=_storeFrontId+"&"+_storeCity+"&"+_storePostal; /* setting cookies for UI and API*/ storeLocator.pars.cookies.setCookie('myStoreDetails', escape(cookieText), '/', 365); storeLocator.pars.cookies.setCookie('myStoreAPI', javaCookie, '/', 365); /* calling the function to show My Store details in header Note:---This method is defined in webstore as same functioanlity was needed in webstore. Called from webstore to avoid code repetition. */ getMyStoreDetails("myStoreDetails"); /* sample function call*/ showStoreLocatorMyStoreLBx('storeLocatorLB'); fireInfoMyStore('Make My Store'); }); $("#prev-stores, #next-stores, .get-directions, #hours-inner .close").live("click", function(){ storeLocator.hours.hide(); }); } })();