1/** 2 * Header 3 */ 4ow.pages.header = (function(){ 5 6 var HeaderLoginControl = ow.controls.headerlogincontrol; 7 var HeroLoginControl = ow.controls.logincontrol; 8 var StoreLocatorFormControl = ow.controls.storelocatorformcontrol; 9 var ChangeStoreControl = ow.controls.changestorecontrol; 10 var YourStoreControl = ow.controls.yourstorecontrol; 11 var commonUtils = ow.utils.wc.commonUtils; 12 var owutils = ow.utils.wc.owutils; 13 var Inventory = ow.utils.wc.inventory; 14 var store = ow.utils.wc.store; 15 var AddToCartControl = ow.controls.addtocartcontrol; 16 var bus = ow.utils.wc.eventbus; 17 var owLogoTopNav = $('.ow-logo-notag'); 18 var owLogo = $('.ow-logo'); 19 20 var Header = function(){ 21 22 this.initialize = function() { 23 document.addEventListener("DOMContentLoaded", function() { 24 if(("true" === $.cookie("fra.catalogue") || "1" === $.cookie("fra_catalogue") || "1" === $.cookie("force_fra_catalogue")) 25 && ow.url.FRAHomeURL != undefined && ow.url.FRAHomeURL.trim().length > 0){ 26 27 $("div.wc-search div.easy-autocomplete-container").addClass("framode"); 28 $("#searchBox").addClass("framode"); 29 $("#SimpleSearchForm_SearchTerm").addClass("framode"); 30 $("#search_submit").addClass("framode"); 31 var searchForm = document.getElementById('CatalogSearchForm'); 32 searchForm.setAttribute('action', ''); 33 searchForm.setAttribute('method', ''); 34 35 var searchBox = document.getElementById('SimpleSearchForm_SearchTerm'); 36 37 var doRedirectWithDebounce = _.debounce(function(keyword) { 38 searchRedirect(keyword); 39 }, 2000); 40 41 var searchRedirect = function(term) { 42 sessionStorage.setItem("fromRedirect", 'true'); 43 return window.location.assign(ow.url.FRAHomeURL + "?q=" + term + "&source=wc"); 44 } 45 46 searchBox.setAttribute('data-autocomplete', '{}'); 47 searchBox.addEventListener('keyup', function(event) { 48 event.preventDefault(); 49 if (event.keyCode === 13) { 50 console.log("13 clicked"); 51 searchRedirect(searchBox.value); 52 } else { 53 doRedirectWithDebounce(searchBox.value); 54 } 55 }); 56 57 $("div.input-group.wc-search").css("display","inline-table"); 58 } else { 59 $("#search_submit").show(); 60 $("#SimpleSearchForm_SearchTerm").show(); 61 $("div.input-group.wc-search").css("display","inline-table"); 62 } 63 }); 64 65 var self = this; 66 67 var changeStoreControl = new ChangeStoreControl({el:$(document)}); 68 69 this.prepareMobileCategoryMenuESpot(); 70 71 if(typeof ow.utils.wc.customerinfoutil === "function"){ 72 ow.utils.wc.customerinfoutil = new ow.utils.wc.customerinfoutil(); 73 } 74 ow.utils.wc.customerinfoutil.isLoggedIn(function(loggedInFlag){ 75 var personUIURI=""; 76 self.headerlogincontrol = new HeaderLoginControl({el:$(document)}); 77 if($('.home-side-panel').length > 0){ 78 if(loggedInFlag){ //loggedIn 79 personUIURI="PersonUI"; 80 } else { //not loggedIn 81 personUIURI="PersonUIAnonymous"; 82 }
83 var url = ow.state.cachedHttpRequest + personUIURI + '?storeId=' + ow.state.storeId + '&catalogId=' + ow.state.catalogId; 84 $.get(url, function(response) { 85 $('.headeruserinfo').replaceWith($('.containerheader', response).html()); 86 $('.adminheaderuserinfo').replaceWith($('.admincontainerheader', response).html()).show(); 87// self.headerlogincontrol = new HeaderLoginControl({el:$(document)}); 88 //adding the logic to display the admin section 89 90 //section to set the margin for the admin nav bar 91 if ($('.navbar-fixed-top').length > 0){ 92 var navbarHeight = $('.navbar-fixed-top').height(); 93 $('.logobar').css('margin-top',navbarHeight); 94 } 95 96 if($('.home-side-panel').length > 0){ 97 $('.home-side-panel').append($('.containerbody', response).html()); 98 self.loginControl = new HeroLoginControl(); 99 self.storeLocatorFormControl = new StoreLocatorFormControl(); 100 $(document).trigger('contentresize'); 101 } 102 }); 103 } 104 105 if(typeof ow.utils.wc.customerinfoutil === "function"){ 106 ow.utils.wc.customerinfoutil = new ow.utils.wc.customerinfoutil(); 107 } 108 109 //Call getUserData and consume result in callback function 110 //This make sure up-to-date customer data is retrieved from /OWUserInfo ajax if the cacehed data is missing or expired. 111 112 ow.utils.wc.customerinfoutil.getUserData(function(userData) { 113 //Check if empty results are returned 114 if (!$.isEmptyObject(userData)){ 115 var XMPieCMDURL = owutils.noCommentURL(ow.url.xmpieOrderURL); 116 //Use the userData, available fields are defined in OWUserInfo.jsp 117 if (userData.customerType === "BUSINESS" && userData.xmpieB2BEnabled && $('.xmpieLink').length > 0) { 118 //XMPie B2B call, Only trigger calls if link exist - enabled by espot 119 $('.xmpieLink').parent().show(); 120 $('.xmpieLink').click(function(e) { 121 e.preventDefault(); 122 $.get(XMPieCMDURL, function(response) { 123 if (response.b2bAccessUrl && response.b2bAccessUrl != ''){ 124 var decodedURL = decodeURIComponent(response.b2bAccessUrl); 125 window.location = decodedURL; 126 } else { 127 alert("Service not available at the moment, try again later."); 128 } 129 }); 130 131 }); 132 } 133 } 134 }); 135 136 }); 137 138 var yourstorecontrol = new YourStoreControl({el:$(document)}); 139 140 $(function(){ 141 //check for store url param and then set the store 142 var storeNumber = (self.getUrlParameter("store") ? self.getUrlParameter("store") : "" ); 143 if (storeNumber){ 144 store.setStore(storeNumber, function(store) { 145 if(store) { 146 bus.trigger("setPrefStore", store); 147 Inventory.update(); 148 } 149 }); 150 } else if(store.isLocationSet()){ 151 var preferredStore = store.getStore(); 152 // modify the check to verify if the store set in cookie is the same as the one in localstorage. 153 var isPreferredStoreEnabled = typeof preferredStore === "undefined" || preferredStore === null || (preferredStore['uniqueId'] !== $.cookie('PREFERRED_STORE_ID')); 154 var isBrowserPreferencesEnabled = $.cookie('OW_BROWSE_AVAILABILITY_PREFERENCES') === 'true' || ow.state.browseAvailabilityPreferencesEnabled; 155 var isPreferredStoreNotMatchDeliverPostcode = typeof $.cookie('OW_DELIVER_POSTCODE') !== 'undefined' 156 && (_.isEmpty(ow.utils.localStorageUtil.sessionStorage("PREFERRED_STORE")) 157 || JSON.parse(ow.utils.localStorageUtil.sessionStorage("PREFERRED_STORE")).deliverPostcode !== $.cookie('OW_DELIVER_POSTCODE')); 158 159 if( isPreferredStoreEnabled || ( isBrowserPreferencesEnabled && isPreferredStoreNotMatchDeliverPostcode )){ 160 store.reloadStore(function() { 161 var preferredStore = store.getStore(); 162 bus.trigger("setPrefStore", preferredStore); 163 if(typeof ow.state.searchpage === "undefined" && typeof ow.state.storeLocatorPage === 'undefined'){ 164 Inventory.update(); 165 } 166 }); 167 } else { 168 bus.trigger("setPrefStore", preferredStore); 169 if(typeof ow.state.searchpage === "undefined" && typeof ow.state.storeLocatorPage === 'undefined'){ 170 Inventory.update(); 171 } 172 } 173 } else { 174 store.findNearestStore(function(nearestStore) { 175 bus.trigger("setPrefStore", nearestStore); 176 Inventory.update(); 177 }); 178 } 179 180 // Search form validation. 181 var searchForm = $('#CatalogSearchForm'); 182 var searchFormButton = searchForm.find('#search_submit'); 183 var searchInput = searchForm.find('[name="searchTerm"]'); 184 185 searchForm.validate({ 186 // overwrite default error placement 187 errorPlacement : function(error, element) { 188 element.attr("placeholder", error.text()); 189 }, 190 submitHandler : function(form) { 191 searchInput.val($.trim(searchInput.val())); 192 if (searchForm.valid()) { 193 var options = ow.utils.localStorageUtil.sessionStorage("options"); 194 options.searchTerm=''; 195 ow.utils.localStorageUtil.sessionStorage( "options", options); 196 197 form.submit(); 198 searchFormButton.trigger('buttoncomplete'); 199 } 200 else { 201 searchFormButton.trigger('buttonfailed'); 202 } 203 204 } 205 }); 206 207 }); 208 209 var customerTypeJson = null;
210 if(typeof ow.utils.wc.customerinfoutil === "function"){ 211 ow.utils.wc.customerinfoutil = new ow.utils.wc.customerinfoutil(); 212 } 213 ow.utils.wc.customerinfoutil.getUserData(function(userData) { 214 if(typeof userData.customerType !== 'undefined' && userData.customerType != null) { 215 customerTypeJson = {"customerType": userData.customerType}; 216 } 217 commonUtils.loadEspots(customerTypeJson); 218 }); 219 220 return this; 221 }; 222 223 this.prepareMobileCategoryMenuESpot=function(){ 224 /* move Mobile espot to right place in the hamburger menu */ 225 $("[data-espotname='MobileMenu_VirtualCategory_Before_V2']").children().each(function(){$(this).prependTo("#view-range-menu-ul");}); 226 $("[data-espotname='MobileMenu_VirtualCategory_After_V2']").children().each(function(){$(this).appendTo("#view-range-menu-ul");}) ; 227 $("[data-espotname='MobileMenu_AfterCategories_V2']").children().each(function(){$(this).appendTo("#view-range-menu-ul");}) ; 228 }; 229 this.responseHandler = function() { 230 // Load the responsive desktop website 231 utils.attachEvent(".responsive-text-link", { 232 onclick: function(e) { 233 // set the siteChoice cookie 234 cookie("siteChoice", "V2", {path:'/'}); 235 location.reload(); 236 } 237 }); 238 }; 239 this.refreshMiniCart = function() { 240 var addToCartControl = new AddToCartControl(); 241 addToCartControl.updateMiniCartNoShow(); 242 }; 243 244 this.getUrlParameter= function(sParam) 245 { 246 var sPageURL = window.location.search.substring(1); 247 var sURLVariables = sPageURL.split('&'); 248 for (var i = 0; i < sURLVariables.length; i++) 249 { 250 var sParameterName = sURLVariables[i].split('='); 251 if (sParameterName[0] == sParam) 252 { 253 return sParameterName[1]; 254 } 255 } 256 }; 257 }; 258 259 return Header; 260 261}());
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.