1(self["webpackChunkmcweb3"] = self["webpackChunkmcweb3"] || []).push([[313],{ 2 3/***/ 2673: 4/***/ (function() { 5 6mcWeb.ajaxVariantSelector = new function ($) { 7 'use strict'; 8 9 var obj = this; 10 obj.view; 11 obj.getModule = function (me) { 12 var myContainer = $(me).closest('.ajax-vsc'); 13 var myId = $(myContainer).data("v-unique-id"); 14 var myModule = mcWeb.ajaxVariantSelector.instances[myId]; 15 return myModule; 16 }; 17 this.vm = function (parent) { 18 obj.view = parent; 19 var self = this; 20 self.id = parent.id + "-avs"; 21 self.parentId = parent.id; 22 self.initialised = false; 23 self.storeSelectionInBrowser = false; 24 self.service = new WebApiService("ProductVariant"); 25 self.subscriptionsAdded = false; 26 self.isVariantMother = false; 27 self.load = function (data, settings) {}; 28 self.registerModule = function () { 29 var myContainer = $(self.parentId); 30 $(myContainer).addClass("ajax-vsc"); 31 $(myContainer).attr('data-v-unique-id', self.id); 32 if (mcWeb.ajaxVariantSelector.instances == undefined) mcWeb.ajaxVariantSelector.instances = []; 33 mcWeb.ajaxVariantSelector.instances[self.id] = self; 34 }; 35 self.bind = function (data) { 36 if (!self.initialised) { 37 self.variantType1Id = null; 38 self.variantType2Id = null; 39 if (data !== undefined) { 40 if (data.storeInBrowser) { 41 self.storeSelectionInBrowser = true; 42 } 43 if (data.loadSelectedValuesFromDOM) { 44 var domAttr1 = jQuery('.variant-selector-container .v-container.active[data-variant-type="1"]'); 45 if (domAttr1.length > 0) { 46 self.variantType1Id = jQuery(domAttr1[0]).data('attributeValueId'); 47 } 48 var domAttr2 = jQuery('.variant-selector-container .v-container.active[data-variant-type="2"]'); 49 if (domAttr2.length > 0) { 50 self.variantType2Id = jQuery(domAttr2[0]).data('attributeValueId'); 51 } 52 } 53 if (obj.view.isVariantMother()) { 54 self.isVariantMother = true; 55 } 56 if (obj.view.motherPlid != undefined) { 57 self.motherPlid = obj.view.motherPlid(); 58 } 59 } 60 self.registerModule(); 61 self.initialised = true; 62 } 63 }; 64 self.reinit = function () { 65 if (self.storeSelectionInBrowser) { 66 self.restoreDataFromLocalStorage(self.motherPlid); 67 } 68 //todo: refresh classes in html based on data found on self 69 if (self.variantType1Id !== undefined && self.variantType1Id !== null && self.variantType1Id >= 0) { 70 if (self.variantType2Id !== undefined && self.isVariantMother) { 71 //lets highlight the correct variant of type 1 and so on, which will try to do by using the selectVariant method for the selected attribute 72 var variantTypeToActivate = $(self.parentId).find(".v-container[data-attribute-value-id=" + self.variantType1Id + "]")[0]; 73 if (variantTypeToActivate != undefined && variantTypeToActivate != null) self.selectVariant(variantTypeToActivate); 74 } 75 } 76 }; 77 self.selectVariant = function (me) { 78 var $me = $($(me).find("a[data-attribute-value-id]")[0]); 79 if (!self.subscriptionsAdded) { 80 //we need to reset this info when the lightbox is closed 81 PubSub.subscribe(mcWeb.lightbox.events.onHideLightbox, function () { 82 self.variantType1Id = null; 83 self.variantType2Id = null; 84 }); 85 self.subscriptionsAdded = true; 86 } 87 var variantType = $me.data('variant-type'); 88 var attributeValueId = $me.data('attribute-value-id'); 89 var valueActive = $me.data('active'); 90 var otherAttributeValueId = null; 91 var motherPlid = $me.data('mother-plid'); 92 var myContainer = $me.closest('.variant-selector-container'); 93 var variantTypeCount = myContainer.data('variant-types'); 94 var removeOldSelected = false; 95 if (variantType == 1) { 96 if (self.variantType1Id != null && (self.variantType2Id == null || self.variantType2Id == -1)) { 97 //must reset selected class for attrib 1 98 removeOldSelected = true; 99 } 100 self.variantType1Id = attributeValueId; 101 otherAttributeValueId = self.variantType2Id; 102 } else { 103 if (self.variantType2Id != null && self.variantType1Id == null || self.variantType2Id == -1) { 104 //must reset selected class for attrib 2 105 removeOldSelected = true; 106 } 107 self.variantType2Id = attributeValueId; 108 otherAttributeValueId = self.variantType1Id; 109 } 110 if (self.storeSelectionInBrowser) { 111 self.updateLocalStorage(motherPlid); 112 } 113 114 // if(valueActive){ 115 if ((otherAttributeValueId != null && otherAttributeValueId != -1 || variantTypeCount == 1) && attributeValueId != null) { 116 self.getChildPlidAction(motherPlid, self.variantType1Id, self.variantType2Id, variantType).then(function (result) { 117 if (result && result.Success) { 118 obj.view.show(result.Plid, 0); 119 } else { 120 console.log(result.Message); 121 } 122 }); 123 } else { 124 //the other value has not been set yet 125 //remove highlighting of already hightlighted item 126 self.setupOtherVariantType(removeOldSelected, $me, motherPlid, attributeValueId, variantType); 127 //update showing of selected variant, if needed 128 129 var myHeadingPch = myContainer.find(".vsc-heading-value"); 130 if (myHeadingPch.length > 0) { 131 var attribName = $me.data("value-name"); 132 myHeadingPch[0].innerText = attribName; 133 } 134 } 135 //} 136 //else{ 137 //} 138 }; 139 140 self.updateLocalStorage = function (plid) { 141 window.StorageService.localStorage.setItem('mcWeb.ajaxVariantSelector.variantType1_' + plid, self.variantType1Id); 142 window.StorageService.localStorage.setItem('mcWeb.ajaxVariantSelector.variantType2_' + plid, self.variantType2Id); 143 }; 144 self.restoreDataFromLocalStorage = function (plid) { 145 if (self.isVariantMother) { 146 self.variantType2Id = -1; 147 self.variantType1Id = -1; 148 } else { 149 var tmp = window.StorageService.localStorage.getItem('mcWeb.ajaxVariantSelector.variantType1_' + plid); 150 if (tmp != undefined) self.variantType1Id = tmp; 151 tmp = window.StorageService.localStorage.getItem('mcWeb.ajaxVariantSelector.variantType2_' + plid); 152 if (tmp != undefined) self.variantType2Id = tmp; 153 } 154 }; 155 self.setupOtherVariantType = function (removeOldSelected, $me, motherPlid, attributeValueId, variantType) { 156 //the other value has not been set yet 157 //remove highlighting of already hightlighted item 158 if (removeOldSelected) { 159 $(".variant-selector-container .v-container").removeClass("active"); 160 } 161 //secondly highlight the selected item 162 //todo: remove all highlighting from liste of the other variants 163 164 var myContainer = $me.closest('.v-container'); 165 $(myContainer).addClass('active'); 166 //if the container is part of a dropdown, we need to change the text from attribute to attributevalue 167 if ($(myContainer).parent().hasClass("dropdown-menu")) { 168 var myButton = $(myContainer).parent().parent().find("button.dropdown-toggle"); 169 var myImgPlch = $(myButton).find(".color-preview-box-pch"); 170 var myColour = $(myContainer).find(".color-preview-box").clone(); 171 if (myColour.length > 0 && myImgPlch.length > 0) { 172 $(myImgPlch[0]).html(myColour); 173 } 174 var textContainer = $(myButton).find("span.ddl-button-span"); 175 var itemContainer = $(myContainer).find("a[data-mother-plid]"); 176 var itemText = $(itemContainer).prop("title"); 177 textContainer[0].innerText = itemText; 178 } 179 self.getInactiveAttributeValuesAction(motherPlid, attributeValueId, variantType).then(function (result) { 180 if (result && result.Success) { 181 var otherVariantType = 2; 182 if (variantType === 2) otherVariantType = 1; 183 if (result.SingleAvailableAttributeValueId !== null) { 184 jQuery(".variant-container [data-variant-types=2] [data-attribute-value-id=".concat(result.SingleAvailableAttributeValueId, "][data-variant-type=").concat(otherVariantType, "]")).click(); 185 } 186 if (result.AttributeValueIds != null) { 187 //active all varianttypes 188 $(".v-container[data-variant-type=" + otherVariantType + "]").removeClass("disabled"); //data-variant-type mangler i container div 189 $(".v-container[data-variant-type=" + otherVariantType + "]").addClass("activated"); 190 191 //deactivate those that should not be acctive 192 for (var i = 0; i < result.AttributeValueIds.length; i++) { 193 //må få inn data-attribute-value-id inn på div rundt a-taggen, og så kan vi finne de for å legge til inaktiv status 194 var itemToDisable = $(".v-container[data-variant-type=" + otherVariantType + "][data-attribute-value-id=" + result.AttributeValueIds[i] + "]"); 195 itemToDisable.addClass("disabled"); 196 itemToDisable.removeClass("activated"); 197 itemToDisable.find("a").prop('title', result.InfoMsg); 198 } 199 } 200 } 201 }); 202 }; 203 self.getChildPlidAction = function (motherPlid, attributeValueId1, attributeValue2Id, lockedVariantType) { 204 var param = { 205 MotherPlid: motherPlid, 206 AttributeValueId1: attributeValueId1, 207 AttributeValueId2: attributeValue2Id, 208 LockedVariantType: lockedVariantType 209 }; 210 return self.service.PostAction("GetVariantChildPlidAsync", param); 211 }; 212 213 //gives us a liste of attributevaluesids from the variant that are not available for the given attribute type 214 self.getInactiveAttributeValuesAction = function (motherPlid, selectedAttributeValueId, attributeType) { 215 var param = { 216 MotherPlid: motherPlid, 217 AttributeValueId: selectedAttributeValueId, 218 VariantType: attributeType 219 }; 220 return self.service.PostAction("GetInactiveAttributeValues", param); 221 }; 222 223 //show the variant-selector since it is now ready
224 if (parent.id === '#PanelProductInfo') { 225 jQuery(parent.id).addClass("variant-ready"); 226 } 227 }; 228}(jQuery); 229 230/***/ }), 231 232/***/ 3477: 233/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { 234 235"use strict"; 236/* harmony export */ __webpack_require__.d(__webpack_exports__, { 237/* harmony export */ A: function() { return /* binding */ AjaxRenderingEngineEventTypes; }, 238/* harmony export */ X: function() { return /* binding */ AjaxRenderingEngine; } 239/* harmony export */ }); 240/* harmony import */ var _scripts_McUtils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4746); 241/* harmony import */ var _scripts_ViewModels_quickview__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5213); 242 243 244var AjaxRenderingEngineEventTypes = { 245 onFieldContentChanged: "AjaxRenderingEngine.onFieldContentChanged", 246 onNewAreasShown: "AjaxRenderingEngine.onNewAreasShown", 247 onPopupReady: "AjaxRenderingEngine.onPopupReady", 248 onPopupFilterChanged: "AjaxRenderingEngine.onPopupFilterChanged", 249 onAjaxRenderingLoaded: "AjaxRenderingEngine.onAjaxRenderingLoaded", 250 onKnockoutRenderingCompleted: "AjaxRenderingEngine.onKnockoutRenderingCompleted", 251 onPriceRefreshRequested: "AjaxRenderingEngine.onPriceRefreshRequested", 252 onPushProductsIntoField: "AjaxRenderingEngine.onPushProductsIntoField", 253 onClearFieldFilter: "AjaxRenderingEngine.onClearFieldFilter", 254 onFieldsRefresh: "AjaxRenderingEngine.onFieldsRefresh", 255 onFilterLoadRequested: "AjaxRenderingEngine.onFilterLoadRequested", 256 onAddNewAreaContent: "AjaxRenderingEngine.onAddNewAreaContent", 257 onReloadFieldByListingType: "AjaxRenderingEngine.onReloadFieldByListingType" 258}; 259var AjaxRenderingEngine = new function AjaxRenderingEngine($) { 260 PubSub.subscribe(AjaxRenderingEngineEventTypes.onAddNewAreaContent, function (message, data) { 261 jQuery('#A' + data.AreaId).html(data.Content); 262 self.updateFields('#A' + data.AreaId + ' .ajax-field', "#AttributeListBox", false, false, false, 0); 263 }); 264 var self = this; 265 self.service = new WebApiService("AreaRenderer"); 266 self.filterService = new WebApiService("AttributeFilter"); 267 self.fieldRenderService = new WebApiService("FieldRenderer"); 268 self.statsService = new WebApiService("Stats"); 269 self.imageService = new WebApiService("ImageRenderer"); 270 self.deviceSize = ""; 271 self.currentSlideshow = null; 272 self.allowUseOfProductCache = true; 273 self.currentField = null; 274 self.PreviewProduktLagerId = null; 275 self.scrollEventIsRegistered = false; 276 self.scrollEventFieldIsRegistered = false; 277 self.scrollEventFooterIsRegistered = false; 278 self.HasMorePages = false; 279 self.PagingMode = 1; 280 self.LoadingFromScroll = false; 281 self.fieldsReadyToLoad = []; 282 self.leftSideFieldsReadyToLoad = []; 283 self.lazyLoadFieldSetupDone = false; 284 self.footerObserver = null; 285 self.IntersectionObserveAllowed = 'IntersectionObserver' in window; 286 self.AutoScrolledPages = 0; 287 self.InitialPageNumber = 1; 288 self.CurrentPageNumber = 1; 289 self.HighestPageNumberSeen = 1; 290 self.LowestPageNumberSeen = 1; 291 self.InitialLoadDone = false; 292 self.subscriptionsInitialised = false; 293 self.PrevPagingLoaded = false; 294 self.myScrollToElement = null; 295 self.currentArticleId = 0; 296 self.CheckStatistics = false; 297 self.ListingTypeGrid = false; 298 self.lightBoxIsOpen = false; 299 self.slideOverBoxIsOpen = false; 300 self.attributeFilterInitiated = false; 301 self.rhsQuickview = new _scripts_ViewModels_quickview__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .A.vm('slideover-placeholder'); 302 self.centerQuickview = new _scripts_ViewModels_quickview__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .A.vm('lightbox-placeholder'); 303 self.currentSearchKeyword = ""; 304 self.finishedLoadingFieldsAbove = false; 305 self.fieldUpdateInProgress = false; 306 self.placeholderDict = {}; 307 self.publishMode = false; 308 this.load = function () { 309 if (jQuery('body.listtype-grid').length > 0) { 310 self.ListingTypeGrid = true; 311 } 312 jQuery("div.HeaderPublishAreaContainer .load-later").each(function (index, item) { 313 jQuery(item).removeClass("load-later"); 314 jQuery(item).addClass("load-first"); 315 }); 316 self.publishMode = $("body.publish-mode").length > 0; 317 var pageParam = self.getParameterByName('pageID'); 318 if (pageParam.length > 0) { 319 self.InitialPageNumber = parseInt(pageParam); 320 self.CurrentPageNumber = self.InitialPageNumber; 321 self.HighestPageNumberSeen = self.InitialPageNumber; 322 self.LowestPageNumberSeen = self.InitialPageNumber; 323 } 324 var articleIdentifier = jQuery("div#current-article-id"); 325 if (articleIdentifier.length > 0) { 326 self.currentArticleId = jQuery(articleIdentifier[0]).data("current-article"); 327 } 328 self.CheckStatistics = window.D4AiActive !== undefined && window.D4AiActive && window.D4AiRegisterStats !== undefined && window.D4AiRegisterStats;
329 var loadFirstParams = { 330 targetKey: "div.load-first .ajax-field.not-loaded", 331 filterTargetKey: "#AttributeListBox", 332 onlyUpdateProductList: false, 333 doNotRenderFilter: false, 334 useDummyData: false, 335 popupFilter: 0, 336 nextPageNumber: 0 337 }; 338 var loadSecond = { 339 targetKey: "div.load-later .web-pub-field[data-popup='0'] .ajax-field.loaded[data-sf='0'][data-field-is-productlist='1']", 340 filterTargetKey: "#AttributeListBox", 341 onlyUpdateProductList: true, 342 doNotRenderFilter: false, 343 useDummyData: false, 344 popupFilter: 0, 345 nextPageNumber: 0 346 }; 347 var loadLeftSideParams = { 348 targetKey: "div.load-left .ajax-field.not-loaded", 349 filterTargetKey: "#AttributeListBox", 350 onlyUpdateProductList: false, 351 doNotRenderFilter: false, 352 useDummyData: false, 353 popupFilter: 0, 354 nextPageNumber: 0 355 }; 356 var loadLaterParams = { 357 targetKey: "div.load-later .web-pub-field[data-popup='0'] .ajax-field.not-loaded[data-sf='0']:not(.menu-container div.load-later .web-pub-field[data-popup='0'] .ajax-field.not-loaded[data-sf='0'])", 358 filterTargetKey: "#AttributeListBox", 359 onlyUpdateProductList: false, 360 doNotRenderFilter: false, 361 useDummyData: false, 362 popupFilter: 0, 363 nextPageNumber: 0 364 }; 365 var loadLaterWithFilterParams = { 366 targetKey: "div.load-later .web-pub-field[data-popup='0'] .ajax-field.not-loaded[data-sf='1']:not(.menu-container div.load-later .web-pub-field[data-popup='0'] .ajax-field.not-loaded[data-sf='1'])", 367 filterTargetKey: "#AttributeListBox", 368 onlyUpdateProductList: false, 369 doNotRenderFilter: false, 370 useDummyData: false, 371 popupFilter: 0, 372 nextPageNumber: 0 373 }; 374 var loadPopupParams = { 375 targetKey: "div.ajax-field.not-loaded[data-popup='1']", 376 filterTargetKey: "#AttributeListBox", 377 onlyUpdateProductList: false, 378 doNotRenderFilter: false, 379 useDummyData: false, 380 popupFilter: 1, 381 nextPageNumber: 0 382 }; 383 if (jQuery(".ProductMenu").css("order") === 1) { 384 self.unhideProductMenu(); //do not wait for attributes are loaded when order is 1 385 } 386 387 self.fieldsToLoad = []; 388 self.fieldsToLoad.push(loadFirstParams); 389 self.fieldsToLoad.push(loadSecond); 390 self.fieldsToLoad.push(loadLeftSideParams); 391 self.fieldsToLoad.push(loadLaterParams); 392 self.fieldsToLoad.push(loadLaterWithFilterParams); 393 self.firstPageViewPopup = loadPopupParams; 394 self.updateContentForPreloadedFields(); 395 self.runUpdateFields(); 396 self.updateSelectedAttributeListVisibility(); 397 PubSub.publish(AjaxRenderingEngineEventTypes.onAjaxRenderingLoaded); 398 if (jQuery(window).scrollTop() === 0) self.finishedLoadingFieldsAbove = true; 399 }; 400 this.getQuickview = function (placement) { 401 if (placement === "rhs") return self.rhsQuickview;else return self.centerQuickview; 402 }; 403 this.openQuickView = function (nodeid, plid, manufacturerid, placement, areaname, me) { 404 if (me !== undefined) { 405 //check if we can use the given placement 406 var myCenteredPopup = jQuery(me).closest("#center-popup"); 407 if (placement == 'c' && myCenteredPopup.length > 0) { 408 //the popup would normalle be shown in center, but right now the ad is already shown in center, 409 //so lets use the rhs instead 410 placement = 'rhs'; 411 } else if (placement === 'rhs' && jQuery(me).closest("#rhs-popup").length > 0) { 412 placement = 'c'; 413 } 414 } 415 var quickview = self.getQuickview(placement); 416 quickview.init({ 417 areaName: areaname, 418 nodeId: nodeid 419 }); 420 quickview.show(plid, manufacturerid); 421 }; 422 this.loadNextPage = function () { 423 self.updateFields("div.load-later .ajax-field.not-loaded[data-field-is-productlist='1']", "#AttributeListBox", true, false, false, 0, true); 424 }; 425 this.loadPrevPage = function () { 426 var prevPageNumber = self.CurrentPageNumber - 1; 427 if (prevPageNumber < 1) { 428 //we're already on the first page, so we just stop processing 429 return; 430 } 431 self.updateFields("div.load-later .ajax-field.not-loaded[data-field-is-productlist='1']", "#AttributeListBox", true, false, false, 0, prevPageNumber); 432 }; 433 this.reloadPageCallback = function (fieldIds) { 434 //receives array with fieldids to update 435 if (self.fieldsToLoad === undefined) self.fieldsToLoad = []; 436 if (fieldIds == undefined || fieldIds.length == 0) { 437 self.updateFields(".ajax-field.not-loaded", "#AttributeListBox", false, false, false, 0, 0); 438 } else { 439 if (isNaN(fieldIds)) { 440 for (var i = 0; i < fieldIds.length; i++) { 441 var params = { 442 targetKey: ".field-container-" + fieldIds[i] + " div.ajax-field", 443 filterTargetKey: "#AttributeListBox", 444 onlyUpdateProductList: false, 445 doNotRenderFilter: false, 446 useDummyData: false, 447 popupFilter: 0, 448 nextPageNumber: 0 449 }; 450 if (jQuery(params.targetKey).length > 0) self.fieldsToLoad.push(params); 451 } 452 } else { 453 var params = { 454 targetKey: ".field-container-" + fieldIds + " div.ajax-field", 455 filterTargetKey: "#AttributeListBox", 456 onlyUpdateProductList: false, 457 doNotRenderFilter: false, 458 useDummyData: false, 459 popupFilter: 0, 460 nextPageNumber: 0 461 }; 462 if (jQuery(params.targetKey).length > 0) self.fieldsToLoad.push(params); 463 } 464 self.runUpdateFields(); 465 } 466 }; 467 468 ////moved 469 this.reloadAllLinkedFields = function () { 470 getLibrary("renderEngineExtras").then(function () { 471 reloadAllLinkedFieldsExtra(self); 472 }); 473 }; 474 475 //find a single element on the page, ask the server to render it again, and then swap it out for the new one 476 this.reloadSingleElement = function (nodeId, activePlid, area, fieldId, element) { 477 //TODO: MOVE, move to separate publisher-only file 478 getLibrary("renderEngineExtras").then(function () { 479 reloadSingleElement(self, nodeId, activePlid, area, fieldId, element); 480 }); 481 }; 482 this.reloadLightboxFields = function () {
483 self.updateFields(".modal-content .ajax-field.not-loaded", "#AttributeListBox", false, false, false, 0); 484 }; 485 this.reloadFieldByListingType = function (listingtype) { 486 self.reloadFromCallbackActive = true; 487 self.updateFields(".ajax-field[data-listing-type=" + listingtype + "]", "#AttributeListBox", false, false, false, 0, 0); 488 }; 489 PubSub.subscribe(AjaxRenderingEngineEventTypes.onReloadFieldByListingType, function (msg, listingType) { 490 self.reloadFieldByListingType(listingType); 491 }); 492 this.reloadProductListField = function () { 493 self.resetAutoScrolledPages(); 494 self.updateFields(".ajax-field[data-field-is-productlist='1']", "#AttributeListBox", true, false, false, 0, 0); 495 }; 496 this.reloadInstantSearchPreview = function (plid) { 497 self.PreviewProduktLagerId = plid; 498 self.updateFields(".InstantSearch .d4-instant-search-loadbyajax .ajax-field", "", false, true, false, 0, false); 499 }; 500 this.setListingType = function (listingAsGrid) { 501 self.ListingTypeGrid = listingAsGrid; 502 if (listingAsGrid) { 503 jQuery('body').addClass('.listtype-grid'); 504 jQuery('body').removeClass('.listtype-list'); 505 var fieldContentContainer = jQuery('.ajax-field.inner-layout-container[data-area-id="CenterContentDynamicProdListAlternate"]'); 506 var fieldContainer = fieldContentContainer.closest(".web-pub-field"); 507 var fieldSorters = fieldContainer.children(".FieldSorter"); 508 if (fieldSorters.length > 0) { 509 fieldSorters.each(function (index, item) { 510 $(item).html(''); 511 }); 512 } 513 jQuery('.ajax-field.inner-layout-container.not-loaded[data-area-id="CenterContentDynamicProdListAlternate"]').html(''); 514 } else { 515 jQuery('body').addClass('.listtype-list'); 516 jQuery('body').removeClass('.listtype-grid'); 517 var fieldContentContainer = jQuery('.ajax-field.inner-layout-container[data-area-id="CenterContentDynamicAdList"]'); 518 var fieldContainer = fieldContentContainer.closest(".web-pub-field"); 519 var fieldSorters = fieldContainer.children(".FieldSorter"); 520 if (fieldSorters.length > 0) { 521 fieldSorters.each(function (index, item) { 522 $(item).html(''); 523 }); 524 } 525 jQuery('.ajax-field.inner-layout-container[data-area-id="CenterContentDynamicAdList"]').html(''); 526 } 527 var newUrl = self.getCurrentFirstPage(); 528 self.CurrentPageNumber = 1; 529 window.history.pushState(newUrl, '', newUrl); 530 }; 531 this.SetAllowedUseOfProductCache = function (val) { 532 self.allowUseOfProductCache = val; 533 }; 534 this.reloadPageListingOnlyCallback = function (skipFilter) { 535 self.reloadFromCallbackActive = true; 536 var doSkipFilter = true; 537 if (skipFilter !== undefined) doSkipFilter = skipFilter; 538 self.updateFields(".ajax-field[data-field-is-productlist='1']", "#AttributeListBox", true, doSkipFilter, false, 0); 539 }; 540 this.reloadForPublisher = function (newDeviceSize) { 541 if (newDeviceSize) self.deviceSize = newDeviceSize; 542 self.updateFields(".ajax-field.not-loaded", "#AttributeListBox", false, false, false, 0); 543 }; 544 this.reloadFields = function (parentIdentifier) { 545 self.addRemainingFieldsToDom(); 546 self.reloadFromCallbackActive = true; 547 self.updateFields(parentIdentifier + " .ajax-field", "#AttributeListBox", false, false, false, 0, 0); 548 }; 549 this.ChangeSortType = function (dropDownControl) { 550 var cont = jQuery(dropDownControl); 551 McAjaxRequest('/WebPages/Extras/SessionStateApi.aspx', 'ChangeSort', cont.val(), self.reloadPageCallback); 552 }; 553 this.ToggleGroupVariants = function (obj) { 554 getLibrary("renderEngineExtras").then(function () { 555 toggleGroupVariants(self, obj); 556 }); 557 }; 558 this.ToggleStockMode = function (obj) { 559 getLibrary("renderEngineExtras").then(function () { 560 toggleStockMode(self, obj); 561 }); 562 }; 563 this.ToggleStockModeFjernlager = function (obj) { 564 getLibrary("renderEngineExtras").then(function () { 565 toggleStockModeFjernlager(self, obj); 566 }); 567 }; 568 this.getParameterByName = function (name) { 569 name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
570 var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), 571 results = regex.exec(location.search); 572 return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); 573 }; 574 this.addFieldToArea = function (areaName, fieldId, nodeId) { 575 //todo: move to publisher script 576 getLibrary("renderEngineExtras").then(function () { 577 addFieldToAreaExtra(self, areaName, fieldId, nodeId); 578 }); 579 }; 580 this.replaceField = function (fieldId, nodeId, isEdm) { 581 getLibrary("renderEngineExtras").then(function () { 582 replaceFieldExtra(self, fieldId, nodeId, isEdm); 583 }); 584 }; 585 $.fn.scrollView = function (offset) { 586 return this.each(function () { 587 if (offset == undefined) offset = 0; 588 $('html, body').animate({ 589 scrollTop: $(this).offset().top + offset 590 }, 1000); 591 }); 592 }; 593 this.getCurrentFirstPage = function () { 594 getLibrary("renderEngineExtras").then(function () { 595 RemovePageNumberFromLink(document.location.href); 596 }); 597 }; 598 this.addValueToQueryString = function (me, attributeId, attributeValueId) { 599 getLibrary("renderEngineExtras").then(function () { 600 addValueToQueryStringExtra(self, me, attributeId, attributeValueId); 601 }); 602 }; 603 this.updateSelectedAttributeListVisibility = function () { 604 var searchLoc = decodeURIComponent(self.getParameterByName('Filter')); 605 if (searchLoc.length <= 0) { 606 jQuery("div.SelectedAttributeBox .filter-selection-container").addClass("hide"); 607 } else { 608 jQuery("div.SelectedAttributeBox .filter-selection-container").removeClass("hide"); 609 } 610 }; 611 this.doScrollToNextPage = function (element) { 612 self.resetAutoScrolledPages(); 613 return self.scrollToNextPage(element); 614 }; 615 this.scrollToNextPage = function (element) { 616 getLibrary("renderEngineExtras").then(function () { 617 scrollToNextPageExtra(self, element); 618 }); 619 return false; 620 }; 621 this.navigateToPage = function (element) { 622 try { 623 var url = element.getAttribute("href"); 624 var title = element.getAttribute("title"); 625 window.history.pushState(url, document.title + ' - ' + title, url); 626 scrollViewToTopOfPage(500); 627 self.updateFields(".ajax-field", "#AttributeListBox", true, true, false, 0); //todo: check that we're actually only changing page, because otherwise we need to set the param doNotRenderFilter to false 628 return false; //indicate navgiation is complete 629 } catch (e) { 630 return true; //must navigate using the link 631 } 632 }; 633 634 this.fetchAttributeValues = function (attributeId, target, targetId, nodeId, fieldId) { 635 getLibrary("renderEngineExtras").then(function () { 636 fetchAttributeValuesExtra(self, attributeId, targetId, nodeId, fieldId); 637 }); 638 }; 639 this.hidePaging = function () { 640 var pagingTag = jQuery('.field-paging-container'); 641 jQuery(pagingTag).addClass('hidden'); 642 }; 643 this.showPagingContainer = function () { 644 var pagingTag = jQuery('.field-paging-container'); 645 jQuery(pagingTag).removeClass('hidden'); 646 }; 647 this.showPageLoadingIcon = function () { 648 var pagingTag = jQuery('.field-paging-next'); 649 jQuery(pagingTag).addClass('hidden'); 650 var loadingTag = jQuery('.field-paging-loading'); 651 jQuery(loadingTag).removeClass('hidden'); 652 }; 653 this.hidePageLoadingIcon = function () { 654 var pagingTag = jQuery('.field-paging-next'); 655 jQuery(pagingTag).removeClass('hidden'); 656 var loadingTag = jQuery('.field-paging-loading'); 657 jQuery(loadingTag).addClass('hidden'); 658 }; 659 this.runUpdateFields = function () { 660 if (self.fieldsToLoad != undefined && self.fieldsToLoad.length > 0) { 661 var param = self.fieldsToLoad.shift(); 662 self.updateFields(param.targetKey, param.filterTargetKey, param.onlyUpdateProductList, param.doNotRenderFilter, param.useDummyData, param.popupFilter, param.nextPageNumber); 663 } 664 }; 665 this.refreshPriceCache = function () { 666 self.service.PostAction("ClearPriceCaches").then(function (result) {}); 667 }; 668 this.updateFields = function (targetKey, filterTargetKey, onlyUpdateProductList, doNotRenderFilter, useDummyData, popupFilter, nextPageNumber) { 669 //todo: vis venteikon 670 var fieldsToLoad = $(targetKey); 671 var fieldsArray = []; 672 var queryFilterParam = self.getParameterByName("Filter"); 673 var queryMinParam = self.getParameterByName("Min"); 674 var queryMaxParam = self.getParameterByName("Max"); 675 var pageIndex = self.getParameterByName("pageID"); 676 var otherContactId = self.getParameterByName("kontaktid"); 677 var getNextPage = !!nextPageNumber; 678 var getPrevPage = false;
679 var isInsidePopup = targetKey.indexOf(".modal") > -1; 680 if (nextPageNumber !== undefined && onlyUpdateProductList) { 681 pageIndex = nextPageNumber; 682 } 683 if (getNextPage) { 684 pageIndex = nextPageNumber; 685 if (onlyUpdateProductList && nextPageNumber < self.CurrentPageNumber) { 686 getPrevPage = true; 687 } 688 self.showPageLoadingIcon(); 689 } 690 if (self.deviceSize == "") self.deviceSize = mcWeb.responsive.getScreenSize(); 691 var isForInstantSearch = targetKey.indexOf(".d4-instant-search-loadbyajax") >= 0; 692 var isForLeftSide = targetKey.indexOf(".load-left") >= 0; 693 var fieldRequestFilter = {}; 694 var requestFilterAdded = false; 695 var sendFilterOnly = false; 696 for (var i = 0; i < fieldsToLoad.length; i++) { 697 var current = $(fieldsToLoad[i]); 698 var isProductListField = false; 699 var areaid = current.data("area-id"); 700 if (onlyUpdateProductList) { 701 if (areaid !== "CenterContentDynamicAdList" && areaid !== "CenterContentDynamicProdListAlternate") continue; //only need to update productlist, lets skip all other fields 702 703 sendFilterOnly = $(current).hasClass("loaded") && !getNextPage && !self.InitialLoadDone; 704 if (pageIndex === 0) pageIndex = self.InitialPageNumber; 705 } 706 if (current.parents(".stop-ajax-rendering").length > 0) continue; //this area is not yet ready to be rendered, it is known to be hidden. 707 708 if (areaid === "CenterContentDynamicAdList" || areaid === "CenterContentDynamicProdListAlternate") { 709 if (!self.publishMode) { 710 if (self.ListingTypeGrid && areaid === "CenterContentDynamicProdListAlternate") { 711 current.html(''); //remove spinner for fields with no content 712 continue; //only one of the areas should be updated, so skip the area that isn't used for the current listing type 713 } else if (!self.ListingTypeGrid && areaid === "CenterContentDynamicAdList") { 714 current.html(''); //remove spinner for fields with no content 715 continue; 716 } 717 } 718 isProductListField = true; 719 var filterContainer = $(filterTargetKey); 720 if (filterContainer === undefined || filterContainer === null) return; //filter not meant to be visible 721 722 filterContainer = $(filterContainer); 723 var filterClientId = ""; 724 if (filterContainer != undefined && filterContainer != null && filterContainer.length > 0 && filterContainer[0] != null) { 725 filterClientId = filterContainer[0].id; 726 } else doNotRenderFilter = true; 727 var cacheKey = ""; 728 if (self.allowUseOfProductCache && pageIndex <= 1) { 729 //if (!onlyUpdateProductList || doNotRenderFilter) //loading the page, data will have been cached when determining the visibility of fields 730 cacheKey = current.attr("data-cachekey"); 731 } 732 fieldRequestFilter = { 733 NodeId: current.data("node-id"), 734 Url: document.location.pathname + document.location.search, 735 Filter: queryFilterParam, 736 MinPrice: queryMinParam, 737 MaxPrice: queryMaxParam, 738 SearchString: self.getParameterByName("q"), 739 ClientId: filterClientId, 740 PageIndex: pageIndex, 741 FilterCacheKey: cacheKey, 742 FilterIsJson: false, 743 OpenAttributes: self.openAttributesList, 744 OtherContactId: otherContactId 745 }; 746 requestFilterAdded = true; 747 } else if (jQuery(current).data("sf") === 1) { 748 fieldRequestFilter = { 749 NodeId: current.data("node-id"), 750 Url: document.location.pathname + document.location.search, 751 Filter: JSON.stringify(self.currentPopupFilter), 752 //todo: keep a filter after # in the url? 753 MinPrice: null, 754 //queryMinParam, get from filter after # in url 755 MaxPrice: null, 756 //queryMaxParam,get from filter after # in url 757 SearchString: '', 758 ClientId: 'secondary-filter', 759 PageIndex: 0, 760 FilterCacheKey: '', 761 FilterIsJson: self.currentPopupFilter !== undefined && self.currentPopupFilter !== null, 762 OpenAttributes: null, 763 OtherContactId: otherContactId 764 }; 765 requestFilterAdded = true; 766 } else if (!requestFilterAdded) { 767 fieldRequestFilter = { 768 NodeId: current.data("node-id"), 769 Url: document.location.pathname + document.location.search, 770 Filter: '', 771 //todo: keep a filter after # in the url? 772 MinPrice: null, 773 //queryMinParam, get from filter after # in url 774 MaxPrice: null, 775 //queryMaxParam,get from filter after # in url 776 SearchString: self.currentSearchKeyword, 777 ClientId: '', 778 PageIndex: 0, 779 FilterCacheKey: '', 780 FilterIsJson: false, 781 OpenAttributes: null, 782 OtherContactId: otherContactId 783 }; 784 if (current.data("filter-id") != null && current.data("filter-id") != undefined && current.data("filter-id").length > 0) { 785 fieldRequestFilter.ClientId = current.data("filter-id"); 786 } 787 requestFilterAdded = true; 788 } 789 if (!onlyUpdateProductList || isProductListField) { 790 var width = self.getFieldWidth(current, isForInstantSearch); 791 var myPlids = null; 792 var myPlidsString = current.data('plids'); 793 if (myPlidsString != undefined && myPlidsString != null) myPlids = myPlidsString; 794 var myPlid = current.data('plid'); 795 if (self.PreviewProduktLagerId != null) { 796 myPlid = self.PreviewProduktLagerId; 797 } 798 if (targetKey != "div.load-later .ajax-field.not-loaded[data-sf='0']" || width > 0) { 799 var fieldData = { 800 Width: width, 801 AreaName: current.data("area-id"), 802 FieldId: current.data("field-id"), 803 NodeId: current.data("node-id"), 804 ClientId: current[0].id, 805 UseSpecificLayoutId: current.data("use-specific-layout"), 806 LayoutId: current.data('layoutid'), 807 ManufacturerId: current.data('manufacturerid'), 808 VariantSorting: current.data('variant-sorting'), 809 Plid: myPlid, 810 PlidList: myPlids, 811 SendFilterOnly: sendFilterOnly, 812 GroupedVariants: current.data('grouped-variants') 813 }; 814 fieldsArray.push(fieldData); 815 } else { 816 current.find("i.icon-spinner").remove(); 817 } 818 } 819 } 820 var skipSorter = getPrevPage; 821 self.PreviewProduktLagerId = null; 822 if (fieldsArray.length > 0) { 823 self.service.PostAction("RenderFields", { 824 Data: fieldsArray, 825 RequestFilter: fieldRequestFilter, 826 SkipFilterRendering: doNotRenderFilter || getNextPage, 827 UseDummyData: useDummyData, 828 DeviceSize: self.deviceSize, 829 GetElementsOnly: getNextPage, 830 SkipSorter: skipSorter, 831 CurrentArticle: self.currentArticleId, 832 PopupFilter: popupFilter 833 }).then(function (result) { 834 if (result != null) { 835 if (isForInstantSearch || self.reloadFromCallbackActive || isInsidePopup || pageIndex > 1) result.AllowDeferred = false;
836 if (getPrevPage) { 837 result.Prepend = true; 838 } else { 839 result.Prepend = false; 840 } 841 if (isForLeftSide) self.updateLeftSideContent(result);else self.updateFieldContent(result); 842 if (result.EmptyFields !== null && result.EmptyFields.length > 0) { 843 for (var i = 0; i < result.EmptyFields.length; i++) { 844 $("#" + result.EmptyFields[i]).html(''); //remove spinner for fields with no content 845 } 846 } 847 848 self.reloadFromCallbackActive = false; 849 if (getNextPage) { 850 pageIndex = nextPageNumber; 851 self.hidePageLoadingIcon(); 852 } 853 if (targetKey.indexOf("div.load-later") >= 0) { 854 if (self.InitialLoadDone == false && window.D4DeferredScripts != undefined) { 855 setTimeout(function () { 856 var parser = new DOMParser(); 857 var dom = parser.parseFromString('<!doctype html><body>' + window.D4DeferredScripts, 'text/html'); 858 var decodedString = dom.body.textContent; 859 if (window.D4SingleScript) { 860 //we only have the path; let's use jquery to load the script 861 jQuery.getScript(decodedString, function (data, textStatus, jqxhr) { 862 //console.log(data); // Data returned 863 console.log(textStatus); // Success 864 console.log(jqxhr.status); // 200 865 console.log("Load was performed."); 866 }); 867 } else { 868 jQuery("body").append(decodedString); 869 } 870 }, 5); 871 } 872 self.setupSubscriptions(); 873 setTimeout(self.postStatistics, 250); 874 } 875 } 876 if (self.fieldsToLoad != undefined && self.fieldsToLoad.length > 0) { 877 self.runUpdateFields(); 878 } else { 879 if (!self.InitialLoadDone) { 880 self.setupSubscriptions(); 881 } 882 } 883 if (isInsidePopup) { 884 PubSub.publish(mcWeb.lightbox.events.contentChanged); 885 } 886 }); 887 } else if (!self.InitialLoadDone) { 888 if (self.fieldsToLoad !== undefined && self.fieldsToLoad.length > 0) { 889 self.runUpdateFields(); 890 } else { 891 if (!self.InitialLoadDone) { 892 self.setupSubscriptions(); 893 } 894 } 895 } 896 }; 897 self.updateLeftSideContent = function (fieldData) { 898 if (!fieldData.Success || fieldData.Data.length == 0) return; 899 self.leftSideFieldsReadyToLoad = fieldData; 900 var myInnerData = fieldData.Data[0]; 901 myInnerData.targetField = $('#' + myInnerData.ClientId); 902 if (_scripts_McUtils__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.isElementInView(myInnerData.targetField)) { 903 //first field in left side is within the view, let's load now 904 self.addFieldContentToPage(fieldData, myInnerData.targetField, myInnerData); 905 myInnerData = fieldData.Data.shift(); 906 } 907 if (myInnerData == null) return; 908 myInnerData.targetField = $('#' + myInnerData.ClientId); 909 self.addScrollObserverForLeftSide(document.getElementById(myInnerData.ClientId)); 910 }; 911 this.addScrollObserverForLeftSide = function (field) { 912 var config = { 913 // If the image gets within 50px in the Y axis, start the download. 914 rootMargin: '0px 0px', 915 threshold: 0.01 916 }; 917 self.leftAreaScrollObserver = new IntersectionObserver(self.onLeftSideIntersection, config); 918 self.leftAreaScrollObserver.observe(field); 919 }; 920 self.onLeftSideIntersection = function (entries) { 921 var entry = null; 922 if (entries.length <= 0) return; 923 var entry = entries[0]; 924 if (entry.intersectionRatio <= 0) return; 925 self.addRemainingLeftSideFieldsToDom(); 926 self.leftAreaScrollObserver.unobserve(entry.target); 927 self.leftAreaScrollObserver = null; 928 }; 929 self.addRemainingLeftSideFieldsToDom = function () { 930 for (var i = 0; i < self.leftSideFieldsReadyToLoad.Data.length; i++) { 931 var myInnerData = self.leftSideFieldsReadyToLoad.Data[i]; 932 myInnerData.targetField = $('#' + myInnerData.ClientId); 933 self.addFieldContentToPage(self.leftSideFieldsReadyToLoad, myInnerData.targetField, myInnerData); 934 } 935 self.leftSideFieldsReadyToLoad = null; 936 }; 937 self.getFieldWidth = function (current, isForInstantSearch) { 938 var width = current.width(); 939 if (width == 0 && isForInstantSearch) { 940 if (self.deviceSize == "sm") width = 200; 941 } else if (width == 0) { 942 var fieldParents = jQuery(current).parents(".web-pub-field.container, .web-pub-field.container-fluid"); 943 for (var parentIndex = 0; parentIndex < fieldParents.length; parentIndex++) { 944 if (fieldParents[parentIndex] != null) { 945 var currentParent = jQuery(fieldParents[parentIndex]); 946 var tmpWidth = currentParent.width(); 947 if (tmpWidth > 0) { 948 width = tmpWidth; 949 break; 950 } 951 } 952 } 953 } 954 if (width <= 0) { 955 var $current = $(current); 956 //if this is a field that will open in a popup, and the popup is not visible yet, the width must be set by the size of the lightbox 957 if ($current.data("popup") > 0) { 958 var lightboxLocator = "#center-popup"; 959 if ($current.data("popup-plc") == 1) { 960 lightboxLocator = "#rhs-popup"; 961 } 962 width = $(lightboxLocator).width(); 963 } 964 } 965 return width; 966 }; 967 self.setupSubscriptions = function () { 968 if (self.subscriptionsInitialised) return; //we've done this already
969 self.subscriptionsInitialised = true; 970 self.disableDoubleClick("ad-buy-button"); 971 PubSub.subscribe(AjaxRenderingEngineEventTypes.onFieldContentChanged, function (data, message) { 972 self.disableDoubleClick("ad-buy-button"); 973 if (self.publishMode) { 974 mcWeb.publisher.checkElementsMarkedInSessionStorage(); 975 } 976 }); 977 PubSub.subscribe(AjaxRenderingEngineEventTypes.onPriceRefreshRequested, function (message, data) { 978 if (data !== undefined && data !== null) { 979 self.updateContentForPreloadedFields(data.Target, false); 980 } else self.updateContentForPreloadedFields("div.ajax-field", false); 981 }); 982 PubSub.subscribe(mcWeb.cartsmall.events.onShowNewItemInCartText, function (message, data) { 983 if (data.favouriteCart != undefined && data.favouriteCart) return; //we don't show this popup when products were added favourite carts 984 985 var lightboxModal = jQuery("#center-popup").data('bs.modal'); 986 if (lightboxModal !== null && lightboxModal !== undefined && lightboxModal.isShown) return; 987 var loadPopupParams2 = { 988 targetKey: "div.ajax-field.not-loaded[data-popup=6]", 989 filterTargetKey: "#AttributeListBox", 990 onlyUpdateProductList: false, 991 doNotRenderFilter: true, 992 useDummyData: false, 993 popupFilter: 6, 994 nextPageNumber: 0 995 }; 996 self.fieldsToLoad.push(loadPopupParams2); 997 self.runUpdateFields(); 998 var loadPopupParams = { 999 targetKey: "div.ajax-field.not-loaded[data-popup=2]", 1000 filterTargetKey: "#AttributeListBox", 1001 onlyUpdateProductList: false, 1002 doNotRenderFilter: true, 1003 useDummyData: false, 1004 popupFilter: 2, 1005 nextPageNumber: 0 1006 }; 1007 self.fieldsToLoad.push(loadPopupParams); 1008 self.runUpdateFields(); 1009 var loadPopupParams3 = { 1010 targetKey: "div.ajax-field.not-loaded[data-popup=3]", 1011 filterTargetKey: "#AttributeListBox", 1012 onlyUpdateProductList: false, 1013 doNotRenderFilter: true, 1014 useDummyData: false, 1015 popupFilter: 3, 1016 nextPageNumber: 0 1017 }; 1018 self.fieldsToLoad.push(loadPopupParams3); 1019 self.runUpdateFields(); 1020 }); 1021 PubSub.subscribe(mcWeb.cart.events.onPopupForProductAssembly, function (message, data) { 1022 var p = { 1023 targetKey: "div.ajax-field.not-loaded[data-popup=8]", 1024 filterTargetKey: "#AttributeListBox", 1025 onlyUpdateProductList: false, 1026 doNotRenderFilter: true, 1027 useDummyData: false, 1028 popupFilter: 8, 1029 nextPageNumber: 0 1030 }; 1031 self.updateFields(p.targetKey, p.filterTargetKey, p.onlyUpdateProductList, p.doNotRenderFilter, p.useDummyData, p.popupFilter, p.nextPageNumber); 1032 }); 1033 PubSub.subscribe(AjaxRenderingEngineEventTypes.onPopupFilterChanged, function (message, data) { 1034 // data contains attribute, attributevalue and the sender 1035 //use this to find the nearest field that should be filtered by the attribute 1036 self.currentPopupFilter = data.FullFilter; 1037 var nextF = jQuery(data.Sender).parent().parent().next(); 1038 if (nextF.length > 0) { 1039 var nextField = jQuery(nextF).find('.ajax-field'); 1040 if (nextField.length > 0) { 1041 //we should now have stored the current filter in self.currentPopupFilter, so now we can ask 1042 //for the field content to be updated 1043 var targetFieldId = nextField[0].id; 1044 var targetFieldPopupRule = jQuery(nextField).data("popup"); 1045 var loadPopupParams = { 1046 targetKey: "#" + targetFieldId, 1047 filterTargetKey: "AttributeListBox", 1048 onlyUpdateProductList: false, 1049 doNotRenderFilter: false, 1050 useDummyData: false, 1051 popupFilter: targetFieldPopupRule, 1052 nextPageNumber: 0 1053 }; 1054 self.fieldsToLoad.push(loadPopupParams); 1055 self.runUpdateFields(); 1056 } 1057 } 1058 }); 1059 PubSub.subscribe(AjaxRenderingEngineEventTypes.onPushProductsIntoField, function (message, data) { 1060 var fieldNode = jQuery(".ajax-field[data-field-id=" + data.FieldId + "]"); 1061 if (fieldNode.length === 0) { 1062 console.log("node not found"); 1063 return; 1064 } 1065 if (data.Plids !== undefined && data.Plids !== null && data.Plids.length > 0) { 1066 jQuery(fieldNode[0]).data("plids", data.Plids); 1067 jQuery(fieldNode[0]).data("filter-id", "secondary-filter"); 1068 var param = { 1069 targetKey: "#" + jQuery(fieldNode[0]).attr("id"), 1070 filterTargetKey: "secondary-filter", 1071 onlyUpdateProductList: false, 1072 doNotRenderFilter: false, 1073 useDummyData: false, 1074 popupFilter: null, 1075 nextPageNumber: 0 1076 }; 1077 if (data.ExtraData !== undefined && data.ExtraData != null) { 1078 self.placeholderDict["extraData" + data.FieldId] = data.ExtraData; 1079 } 1080 self.updateFields(param.targetKey, param.filterTargetKey, param.onlyUpdateProductList, param.doNotRenderFilter, param.useDummyData, param.popupFilter, param.nextPageNumber); 1081 } else { 1082 jQuery(fieldNode[0]).attr("data-Plids", data.Plids); 1083 jQuery(fieldNode[0]).attr("data-filter-id", "secondary-filter"); 1084 jQuery(fieldNode).html(''); 1085 jQuery(".secondary-filter").html(''); 1086 } 1087 }); 1088 mcWeb.ajaxPopup.load(); //sets up subscriptions for event-controlled pop-ups 1089 self.checkForPopupAfterProductInfoVisit(); 1090 self.checkForPopupFirstPageView(); 1091 self.checkForPopupAfterLogin(); 1092 (function () { 1093 if (typeof window.CustomEvent === "function") return false;
1094 function CustomEvent(event, params) { 1095 params = params || { 1096 bubbles: false, 1097 cancelable: false, 1098 detail: null 1099 }; 1100 var evt = document.createEvent('CustomEvent'); 1101 evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); 1102 return evt; 1103 } 1104 window.CustomEvent = CustomEvent; 1105 })(); 1106 var formHead = document.querySelector('head'); 1107 formHead.dispatchEvent(new CustomEvent("readyForGtm", { 1108 bubbles: true, 1109 cancelable: false, 1110 detail: null 1111 })); 1112 self.InitialLoadDone = true; 1113 //todo: her trenger vi starte å prosessere en ny kø med jobber med javascript kall som legges inn av HTMLen som kommer publisert i f.eks. artikler. 1114 }; 1115 1116 self.checkForPopupFirstPageView = function () { 1117 if (!!self.firstPageViewPopup) { 1118 if (jQuery("body.publish-mode").length <= 0) { 1119 var param = self.firstPageViewPopup; 1120 self.firstPageViewPopup = null; 1121 self.updateFields(param.targetKey, param.filterTargetKey, param.onlyUpdateProductList, param.doNotRenderFilter, param.useDummyData, param.popupFilter, param.nextPageNumber); 1122 } else { 1123 self.firstPageViewPopup = null; 1124 } 1125 } 1126 }; 1127 self.disableDoubleClick = function (classToDisable) { 1128 jQuery('.' + classToDisable).on("dblclick", function (e) { 1129 e.preventDefault(); 1130 }); 1131 }; 1132 self.checkForPopupAfterLogin = function () { 1133 var readyForPostLoginPopup = localStorage.getItem('ReadyForPostLoginPopup') === 'true'; 1134 if (!!readyForPostLoginPopup) { 1135 if (jQuery("body.publish-mode").length <= 0) { 1136 var loadPopupParams = { 1137 targetKey: "div.ajax-field.not-loaded[data-popup='9']", 1138 filterTargetKey: "#AttributeListBox", 1139 onlyUpdateProductList: false, 1140 doNotRenderFilter: true, 1141 useDummyData: false, 1142 popupFilter: 9, 1143 nextPageNumber: 0 1144 }; 1145 self.updateFields(loadPopupParams.targetKey, loadPopupParams.filterTargetKey, loadPopupParams.onlyUpdateProductList, loadPopupParams.doNotRenderFilter, loadPopupParams.useDummyData, loadPopupParams.popupFilter, loadPopupParams.nextPageNumber); 1146 } 1147 window.StorageService.localStorage.setItem('ReadyForPostLoginPopup', 'false'); 1148 } 1149 }; 1150 self.checkForPopupAfterProductInfoVisit = function () { 1151 var param = { 1152 NodeId: jQuery("#hidden-nodeid").text() 1153 }; 1154 self.statsService.PostAction("CheckForPopupAfterProductVisit", param).then(function (result) { 1155 if (self.fieldsToLoad == undefined) self.fieldsToLoad = []; 1156 if (result) { 1157 var loadPopupParams = { 1158 targetKey: "div.ajax-field.not-loaded[data-popup='4']", 1159 filterTargetKey: "#AttributeListBox", 1160 onlyUpdateProductList: false, 1161 doNotRenderFilter: true, 1162 useDummyData: false, 1163 popupFilter: 4, 1164 nextPageNumber: 0 1165 }; 1166 self.updateFields(loadPopupParams.targetKey, loadPopupParams.filterTargetKey, loadPopupParams.onlyUpdateProductList, loadPopupParams.doNotRenderFilter, loadPopupParams.useDummyData, loadPopupParams.popupFilter, loadPopupParams.nextPageNumber); 1167 } else { 1168 var loadPopupParams = { 1169 targetKey: "div.ajax-field.not-loaded[data-popup='5']", 1170 filterTargetKey: "#AttributeListBox", 1171 onlyUpdateProductList: false, 1172 doNotRenderFilter: true, 1173 useDummyData: false, 1174 popupFilter: 5, 1175 nextPageNumber: 0 1176 }; 1177 self.updateFields(loadPopupParams.targetKey, loadPopupParams.filterTargetKey, loadPopupParams.onlyUpdateProductList, loadPopupParams.doNotRenderFilter, loadPopupParams.useDummyData, loadPopupParams.popupFilter, loadPopupParams.nextPageNumber); 1178 } 1179 }); 1180 }; 1181 self.addFieldSorterToPage = function (data, $targetField, fieldData) { 1182 if (data.FieldSorterResponse !== null && data.FieldSorterResponse.length > 0 && !fieldData.Prepend) { 1183 //when we prepend the page content, we don't need to update the "go to next page" link 1184 var myFieldContainer = $($targetField.parent()).parent(); 1185 // fjern eksisterende paging før vi legger til den nye 1186 var oldFieldSorter = $(myFieldContainer).find(".FieldSorter"); 1187 oldFieldSorter.remove(); 1188 if (fieldData.PagingMode <= 1 || $("#mmenu").length > 0 || $("body.mc-filter-left").length > 0) { 1189 $(myFieldContainer).prepend(data.FieldSorterResponse); 1190 } 1191 if (data.FieldSorter2Response !== null && data.FieldSorter2Response.length > 0) $(myFieldContainer).append(data.FieldSorter2Response); 1192 var btn = $('#filter-btn'); 1193 btn.show(); 1194 PubSub.publish(mcWeb.MegaMenuResponsive.events.onAddNewFilterButton, null); 1195 } 1196 }; 1197 self.addFieldContentToPage = function (fieldData, targetField, data) { 1198 self.bottomImageToLoad = null; 1199 if (targetField != undefined && !data.added) { 1200 var $targetField = $(targetField); 1201 data.added = true; 1202 self.addFieldSorterToPage(data, $targetField, fieldData); 1203 if (fieldData.FilterCacheKey !== null) 1204 //todo: check how to make this null when page index is not 1 1205 $targetField.attr("data-cachekey", fieldData.FilterCacheKey); //update cache key. Especially useful when filtering is being applied, to allow quick reload of previously used filters 1206 1207 self.registerStatistics(data); 1208 if (data.LoadFilter) { 1209 this.updateFilterContent(data); 1210 } 1211 if (!fieldData.AddToExistingField) { 1212 if (!data.SendFilterOnly) { 1213 //we called this only to get the attribute filter when SendFilterOnly is true 1214 $targetField.html(data.Response); 1215 self.refineInsertedContent(targetField, data); 1216 } 1217 var imageList = $targetField.find(".AddProductImage img"); 1218 var lastImage = imageList.last(); 1219 if (lastImage != null && lastImage.length > 0) { 1220 if (self.containsLoadableImage(lastImage)) self.bottomImageToLoad = lastImage; 1221 } else if (imageList.length <= 0) { 1222 //No images found by looking for them in ads, so check for articles... 1223 if (self.bottomImageToLoad === null || self.bottomImageToLoad === undefined) { 1224 //we might only have articles in the field, let's look for one... 1225 var backgroundImgItems = $targetField.find("div.ArticleWithBackgroun
1225d.D4Standard .inner-content"); 1226 if (backgroundImgItems.length > 0) { 1227 var bgItem = backgroundImgItems.last(); 1228 if (bgItem != null) { 1229 if (self.containsLoadableImage(bgItem)) self.bottomImageToLoad = bgItem; 1230 } 1231 } 1232 } 1233 } 1234 PubSub.publish(AjaxRenderingEngineEventTypes.onFieldContentChanged, data); 1235 } else { 1236 if (fieldData.Prepend) { 1237 $targetField.prepend(data.Response); 1238 PubSub.publish(AjaxRenderingEngineEventTypes.onFieldContentChanged, data); 1239 } else { 1240 $targetField.append(data.Response); 1241 PubSub.publish(AjaxRenderingEngineEventTypes.onFieldContentChanged, data); 1242 } 1243 self.refineInsertedContent(targetField, data); 1244 } 1245 self.initialiseAdLinks(); 1246 if (fieldData.InitializeRoyalSlider) InitializeRoyalSliderInAds("#" + data.ClientId + " .variant-slider"); 1247 self.searchPageArea(data); 1248 if (!data.SendFilterOnly && (data.Response === null || data.Response.length === 0)) { 1249 if (data.AreaName === "CenterContentDynamicAdList") { 1250 //find and hide the Sorter elements for ad-listing 1251 $(".FieldSorter.web-pubfield-sort.CenterContentDynamicAdList").hide(); 1252 } else if (data.AreaName === "CenterContentDynamicProdListAlternate") { 1253 //find and hide the Sorter elements for ad-listing 1254 $(".FieldSorter.web-pubfield-sort.CenterContentDynamicProdListAlternate").hide(); 1255 } 1256 } else { 1257 if (data.AreaName === "CenterContentDynamicAdList") { 1258 //find and hide the Sorter elements for ad-listing 1259 $(".FieldSorter.web-pubfield-sort.CenterContentDynamicAdList").show(); 1260 } else if (data.AreaName === "CenterContentDynamicProdListAlternate") { 1261 //find and hide the Sorter elements for ad-listing 1262 $(".FieldSorter.web-pubfield-sort.CenterContentDynamicProdListAlternate").show(); 1263 } 1264 } 1265 if (fieldData.IsDummyField) { 1266 $targetField.click(self.selectLayoutClick); 1267 $targetField.addClass("wired" + data.ClientId); 1268 } 1269 if (data.LayoutCssClass != null && data.LayoutCssClass != undefined) { 1270 var fieldToUpdateLayout = $targetField.closest('.web-pub-field:not(.' + data.LayoutCssClass + ")"); 1271 $(fieldToUpdateLayout).removeClass(function (index, className) { 1272 return (className.match(/(^|\s)layout-\S+/g) || []).join(' '); 1273 }); 1274 $(fieldToUpdateLayout).addClass(data.LayoutCssClass); 1275 } 1276 } 1277 }; 1278 1279 // Define the IsNoHitSearchPage function 1280 this.searchPageArea = function (data) { 1281 if (data.AreaName !== "CenterContentDynamicAdList" && data.AreaName !== "CenterContentDynamicProdListAlternate") return; 1282 if (data.IsNoHitSearch) { 1283 jQuery(".search-no-result").show(); 1284 self.updateContentForPreloadedFields(".search-no-result div.ajax-field.not-loaded", false); 1285 if (data.ShowInStockOnly || data.ShowInRemoteStockOnly) { 1286 jQuery(".search-no-result-not-instock").show(); 1287 // Hide the lhs filterbutton 1288 } else { 1289 jQuery(".search-no-result-not-instock").hide(); 1290 } 1291 } else if (data.IsProductListing) { 1292 jQuery("body:not(.publish-mode) .search-no-result").hide(); 1293 } 1294 }; 1295 this.containsLoadableImage = function (currImg) { 1296 if (currImg.length !== undefined && currImg.length > 0) { 1297 for (var i = 0; i < currImg.length; i++) { 1298 if (self.containsLoadableImage(currImg[i])) return true; 1299 } 1300 return false; 1301 } 1302 if (currImg != null && currImg.src != undefined && currImg.src != null) return true;else if ($(currImg).hasClass("inner-content")) { 1303 var bg = $(currImg).css('background-image').trim(); 1304 if (bg.length > 0 && bg !== "none") { 1305 return true; 1306 } 1307 } 1308 return false; 1309 }; 1310 this.initializeSlideShow = function ($targetField, slideshowmodel) { 1311 if (slideshowmodel == null || slideshowmodel == undefined) return; 1312 var myParent = $targetField.closest('.web-pub-field'); 1313 if (!$(myParent).hasClass('NoSlide')) return; 1314 $(myParent).addClass('around_slides'); 1315 $(myParent).removeClass('NoSlide'); 1316 $targetField.addClass('royalSlider'); 1317 mcSlide.InitSlideshow(myParent[0].id, slideshowmodel.Play, slideshowmodel.Pause, slideshowmodel.HoverPause, slideshowmodel.GenerateNextPrev, slideshowmodel.GeneratePagination, slideshowmodel.ArrowsNavAutoHide, slideshowmodel.FadeSpeed, slideshowmodel.SlideSpeed, slideshowmodel.Effect, slideshowmodel.CrossFade, slideshowmodel.Orientation, slideshowmodel.ScaleType, slideshowmodel.Randomize, slideshowmodel.Css, slideshowmodel.IsMobileDomain, slideshowmodel.Width, slideshowmodel.Height, true); 1318 }; 1319 this.resolveImagesOnImageLoaded = function (image) { 1320 return new Promise(function (resolve, reject) { 1321 if (image.complete) { 1322 resolve(); 1323 } else { 1324 image.onload = function () { 1325 resolve(); 1326 }; 1327 } 1328 }); 1329 }; 1330 this.getArrayOfArrays = function (inputArray, itemsPerArray) { 1331 var arrayOfArrays = []; 1332 for (var i = 0; i < inputArray.length; i += itemsPerArray) { 1333 arrayOfArrays.push(inputArray.slice(i, i + itemsPerArray)); 1334 } 1335 return arrayOfArrays; 1336 };
1337 this.getSlideshowModel = function ($targetField, data) { 1338 if (data != null && data.SlideShowModel != undefined && data.SlideShowModel != null) return data.SlideShowModel; 1339 if (!$targetField.hasClass("slides_container")) return null; 1340 1341 //may store slideshow in the container field 1342 var parentWithSlideInfo = $targetField.parents(".web-pub-field[data-slideshow]"); 1343 if (parentWithSlideInfo.length <= 0) return null; 1344 return parentWithSlideInfo.data("slideshow"); 1345 }; 1346 this.ensureCorrectImageSizes = function (images, $targetField, data, lazyImg, initialiseSlideshows) { 1347 //Note! Array.from for IE has been added to the McWeb4-standard.js file. 1348 //when images are either not in need of resizing, or the new images have been fetched, we try to set up any slideshow for the field. 1349 1350 if ((images === null || images === undefined || images.length <= 0) && initialiseSlideshows) { 1351 //no need to load images, so let's just see if slideshow must be applied 1352 var slidemodel = self.getSlideshowModel($targetField, data); 1353 if (slidemodel !== null) { 1354 self.initializeSlideShow($targetField, slidemodel); 1355 } 1356 return; 1357 } 1358 var nodeId = jQuery('#hidden-nodeid').text(); 1359 var itemsPerArray = 8; 1360 if (data != null && (data.ImgModuleVer >= 5 || data.SlideShowModel != null && data.SlideShowModel != undefined)) itemsPerArray = images.length; // must keep it down to 1 request for images when dealing with slideshow, or when ImageModulVersion >= 5 1361 1362 var imageLoadedPromises = Array.from(images).map(self.resolveImagesOnImageLoaded); 1363 Promise.all(imageLoadedPromises).then(function () { 1364 var imageList = images.toArray().map(function (i) { 1365 return self.getParamForImage(i, lazyImg, nodeId); 1366 }).filter(function (y) { 1367 return y !== null; 1368 }); 1369 var arrayOfImageArrays = self.getArrayOfArrays(imageList, itemsPerArray); 1370 var requestForImagesSent = false; 1371 for (var arrayId = 0; arrayId < arrayOfImageArrays.length; arrayId++) { 1372 var items = arrayOfImageArrays[arrayId]; 1373 requestForImagesSent = true; 1374 self.imageService.PostAction("ListImageTagsAsync", { 1375 Items: items 1376 }).then(function (result) { 1377 var delaySlideshow = false; 1378 if (result && result.items && result.items.length > 0) { 1379 var items = result.items; 1380 for (var i = 0; i < items.length; i++) { 1381 var item = items[i]; 1382 if (!item.success) continue; 1383 delaySlideshow = true; //slideshow must wait for these new images have loaded 1384 1385 if (item.tag !== "") jQuery('#' + item.targetId).replaceWith(item.tag);else { 1386 var image = jQuery('#' + item.targetId + " img.d4-lazy-thumb"); 1387 image.removeClass("d4-lazy-thumb"); 1388 image.addClass("d4-prod-thumb"); 1389 } 1390 } 1391 } 1392 if (!initialiseSlideshows) return; 1393 var slidemodel = self.getSlideshowModel($targetField, data); 1394 if (slidemodel === null) return; 1395 if (delaySlideshow) { 1396 //need to await the new images have been loaded before we set up slideshow 1397 var newImages = $targetField.find("img.d4-prod-thumb"); 1398 self.initializeSlideShowAfterImagesLoaded($targetField, newImages, slidemodel); 1399 } else self.initializeSlideShow($targetField, slidemodel); 1400 }); 1401 } 1402 if (!initialiseSlideshows) return; 1403 var slidemodel = self.getSlideshowModel($targetField, data); 1404 if (!requestForImagesSent && slidemodel !== null) { 1405 self.initializeSlideShow($targetField, slidemodel); 1406 } 1407 }); 1408 }; 1409 this.getParamForImage = function (image, lazyImg, nodeId) { 1410 var img = jQuery(image); 1411 var parent = img.parent(); 1412 if (parent === null || parent === undefined || parent.length <= 0) return null; 1413 var containerTagType = parent[0].tagName.toLowerCase(); 1414 var includeLink = containerTagType === "a"; 1415 var parentWidth = parent.width(); 1416 var parentHeight = parent.height(); 1417 var myWidth = img.data("width"); 1418 var myHeight = img.data("height"); 1419 var usesAltImg = img.data("altImg") === 1; 1420 var imgStatus = img.data("status"); 1421 var elementId = img.data("elementid"); 1422 var css = img.data("css"); 1423 var autoscale = img.data("autoscale"); 1424 if (usesAltImg || !lazyImg && (imgStatus == undefined || imgStatus.toUpperCase() !== "OK")) return null; 1425 if (!lazyImg && myWidth / parentWidth >= 0.90) return null; //if lazyImg, no image loaded so we must allways load a new image 1426 1427 var aspect = 1; 1428 if (parentWidth > 0 && parentHeight > 0) aspect = parentWidth / parentHeight;else if (myWidth > 0 && myHeight > 0) aspect = myWidth / myHeight; //applies when parent not visible and hence no parent size available 1429 1430 if (aspect < 0.1 || aspect > 2) { 1431 //lazy loading in use, must use different aspect calculation 1432 aspect = myWidth / myHeight; 1433 } 1434 var myId = img[0].id; 1435 if (myId === "") myId = parent[0].id; 1436 var item = { 1437 TargetId: myId, 1438 Plid: img.data("plid"), 1439 Index: img.data("imageIndex"), 1440 Width: parentWidth, 1441 Aspect: aspect, 1442 IncludeLink: includeLink, 1443 UseSecondaryImage: img.data("hassecondaryimg") === 1, 1444 IncludeNotFound: lazyImg, 1445 ElementId: 0, 1446 Css: '', 1447 AutoScale: autoscale, 1448 NodeId: nodeId 1449 }; 1450 if (elementId !== undefined && elementId !== null) item.ElementId = elementId; 1451 if (css !== undefined && css !== null) item.Css = css; 1452 return item; 1453 }; 1454 this.initializeSlideShowAfterImagesLoaded = function ($targetField, images, slidemodel) { 1455 if (images !== null && images !== undefined && images.length > 0) {
1456 var imageLoadedPromises = Array.from(images).map(self.resolveImagesOnImageLoaded); 1457 Promise.all(imageLoadedPromises).then(function () { 1458 if (slidemodel != undefined && slidemodel != null) { 1459 self.initializeSlideShow($targetField, slidemodel); 1460 } 1461 }); 1462 } 1463 }; 1464 this.initialiseAdLinks = function () { 1465 setTimeout(function () { 1466 if (window.D4LinkArraySetup != undefined && window.D4LinkArraySetup != null) { 1467 for (var i = 0; i < window.D4LinkArraySetup.length; i++) { 1468 var current = window.D4LinkArraySetup[i]; 1469 makeAdLinkToProduct(current.elementId, current.productLink); 1470 } 1471 window.D4LinkArraySetup = []; //clearing it 1472 //linker virker ikke enda etter at nye elementer er lagt til 1473 //må debugge dette! 1474 } 1475 }, 5); 1476 }; 1477 self.stats = []; 1478 this.registerStatistics = function (data) { 1479 if (data != undefined && data != null && !self.InitialLoadDone && (data.PopupRule == undefined || data.PopupRule <= 0)) { 1480 // && (data.SlideShowModel == undefined || data.SlideShowModel == null)) { 1481 if (self.CheckStatistics) { 1482 self.stats.push(data); 1483 } 1484 } 1485 }; 1486 this.postStatistics = function () { 1487 try { 1488 if (self.stats != null && self.stats.length > 0) { 1489 var data = self.stats[0]; 1490 var stats = { 1491 DeviceSize: self.deviceSize, 1492 NodeId: data.NodeId, 1493 FieldIds: [], 1494 Note: 'FieldsShownBeforeScroll' 1495 }; 1496 for (var i = 0; i < self.stats.length; i++) { 1497 stats.FieldIds.push(self.stats[i].FieldId); 1498 } 1499 self.service.PostAction("PostStatistics", stats).then(function () { 1500 self.stats = []; 1501 }); 1502 } 1503 } catch (e) {} 1504 }; 1505 this.updateContentForSpecificFields = function (fieldRecognizer) { 1506 self.addRemainingFieldsToDom(); 1507 self.reloadFromCallbackActive = true; 1508 self.updateFields(fieldRecognizer, "#AttributeListBox", false, true, false, 0, 0); 1509 }; 1510 this.updateContentForPreloadedFields = function (fieldRecognizer, includeMegaMenuChildren) { 1511 var recognizer = "div.ajax-field.loaded"; 1512 if (fieldRecognizer !== undefined) { 1513 recognizer = fieldRecognizer; 1514 } 1515 var preloadedFields = jQuery(recognizer); 1516 var fieldItems = []; 1517 for (var j = 0; j < preloadedFields.length; j++) { 1518 var field = jQuery(preloadedFields[j]); 1519 var fieldItem = { 1520 FieldId: field.data('field-id'), 1521 NodeId: field.data('node-id'), 1522 UniqueId: field[0].id 1523 }; 1524 if (!includeMegaMenuChildren && $(field).parents(".dropdown-submenu").length > 0) continue; //fields within mega menu are not to be loaded here, will be done when menu is shown. 1525 1526 var preloadedElements = field.find("div.WebPubElement, div.separator-element[data-separator-level=100]"); 1527 var eItems = []; 1528 for (var i = 0; i < preloadedElements.length; i++) { 1529 var element = jQuery(preloadedElements[i]); 1530 var eItem = { 1531 ElementId: element.data('elementid'), 1532 Plid: element.data('plid') 1533 }; 1534 eItems.push(eItem); 1535 } 1536 fieldItem.Elements = eItems; 1537 fieldItems.push(fieldItem); 1538 } 1539 startParaxify('.d4-article-parallax'); 1540 if (fieldItems.length > 0) { 1541 self.service.PostAction("GetPriceDataAsync", { 1542 Fields: fieldItems 1543 }).then(function (result) { 1544 if (result && result.Success) { 1545 var fields = result.Fields; 1546 for (var i = 0; i < fields.length; i++) { 1547 var fData = fields[i]; 1548 var field = jQuery("#" + fData.UniqueId); 1549 self.refineInsertedContent(field, fData); 1550 } 1551 } 1552 }); 1553 } 1554 self.showSearchSynonymText(); 1555 }; 1556 this.showSearchSynonymText = function () { 1557 if (jQuery(".search-synonyms").length > 0) return; 1558 var alteredSearchResultArea = jQuery(".web-pub-field[data-search-synonyms]"); 1559 if (alteredSearchResultArea.length <= 0) return; 1560 var alteredText = alteredSearchResultArea.data("search-synonyms"); 1561 if (alteredText !== undefined && alteredText !== null && alteredText.length <= 0) return; 1562 var newContent = "<H3 class='search-synonyms'>
1562" + alteredText + "</H3>"; 1563 alteredSearchResultArea.first().before(newContent); 1564 }; 1565 this.applyModelRegisterExtraData = function (targetfield, fieldId) { 1566 if (targetfield === null || targetfield === undefined || fieldId === undefined || fieldId === null) return; 1567 if (self.placeholderDict === null || self.placeholderDict === undefined) return; 1568 var extraData = self.placeholderDict["extraData" + fieldId]; 1569 if (extraData === undefined || extraData === null) return; 1570 for (var i = 0; i < extraData.length; i++) { 1571 var item = extraData[i]; 1572 if (item === null || item.Plid <= 0) continue; 1573 if (item.AccessoriesGroup !== null) { 1574 var accessoriesgroup = $(".mod-reg-ag.mode-reg-id-" + item.Plid); 1575 accessoriesgroup.html(item.AccessoriesGroup); 1576 accessoriesgroup.removeClass("hidden"); 1577 } 1578 if (item.FreeText !== null) { 1579 var freeTextItem = $(".mod-reg-ft.mode-reg-id-" + item.Plid); 1580 freeTextItem.html(item.FreeText); 1581 freeTextItem.removeClass("hidden"); 1582 } 1583 } 1584 }; 1585 this.applyCustomerSpecifics = function (targetfield, data) { 1586 if (data === null) return; 1587 self.applyModelRegisterExtraData(targetfield, data.FieldId); 1588 if (data.PriceData === null || data.PriceData.length <= 0) return; 1589 var $targetField = jQuery(targetfield); 1590 var priceTags = jQuery(targetfield).find(".locate-prices-" + data.FieldId); 1591 for (var i = 0; i < data.PriceData.length; i++) { 1592 jQuery(priceTags).filter("#adprice__" + data.FieldId + "_" + data.PriceData[i].ElementId).each(function (index, item) { 1593 var $item = jQuery(item); 1594 $item.html(data.PriceData[i].Price); 1595 if (data.PriceData[i].Discount !== null && data.PriceData[i].Discount.length > 0) { 1596 $item.addClass("has-discount"); 1597 } 1598 if (data.PriceData[i].NoBuy) { 1599 var myElement = jQuery(jQuery(item).parents("div.WebPubElement")[0]); 1600 myElement.find("a.ad-buy-button").addClass("disabled"); 1601 myElement.find("a.list-buy-button").addClass("disabled"); 1602 } else if (data.PriceData[i].UnlockBuy) { 1603 var myElement = jQuery(jQuery(item).parents("div.WebPubElement")[0]); 1604 myElement.find("a.ad-buy-button").removeClass("disabled"); 1605 myElement.find("a.list-buy-button").removeClass("disabled"); 1606 } 1607 }); 1608 if (data.PriceData[i].BidName !== null && data.PriceData[i].BidName.length > 0) { 1609 var countDown = jQuery(".WebPubElement[data-elementid=" + data.PriceData[i].ElementId + "] .sale-countdown"); 1610 countDown.data('bid-expires', data.PriceData[i].BidExpires); 1611 } 1612 //todo: skriv om slik at vi her først legger expire-tiden inn som et data-element på elemented, og så start en timer som går igjennom alle elementene en etter en. Vi ønsker ikke 1613 //å ha mer enn 1 timer pr felt i hvertfall 1614 1615 if ($targetField.has(".WebPubElement .sale-countdown").length > 0) { 1616 getLibrary("renderEngineExtras").then(function () { 1617 startSaleCountDown($targetField); 1618 }); 1619 } 1620 } 1621 var discountTags = $targetField.find(".locate-yousave-" + data.FieldId); 1622 for (var i = 0; i < data.PriceData.length; i++) { 1623 var line = data.PriceData[i]; 1624 if (line != null && line.Discount != null && line.Discount.length > 0) { 1625 jQuery(discountTags).filter("#adyousave__" + data.FieldId + "_" + line.ElementId).each(function (index, item) { 1626 var jItem = jQuery(item); 1627 jItem.html(line.Discount); 1628 jItem.addClass("show"); 1629 }); 1630 } 1631 } 1632 var oldPriceTags = $targetField.find(".locate-oldprices-" + data.FieldId); 1633 for (var i = 0; i < data.PriceData.length; i++) { 1634 var line = data.PriceData[i]; 1635 if (line.OldPrice != null && line.OldPrice.length > 0) { 1636 jQuery(oldPriceTags).filter("#adoldprice__" + data.FieldId + "_" + line.ElementId).each(function (index, item) { 1637 var jItem = jQuery(item); 1638 jItem.html(line.OldPrice); 1639 jItem.addClass("show"); 1640 jItem.prev().addClass("show"); //must show the prefix also 1641 }); 1642 } 1643 } 1644 1645 var rrpPriceTags = $targetField.find(".locate-rrpprices-" + data.FieldId); 1646 for (var i = 0; i < data.PriceData.length; i++) { 1647 var line = data.PriceData[i]; 1648 if (line.Rrp != null && line.Rrp.length > 0) { 1649 jQuery(rrpPriceTags).filter("#adrrpprice__" + data.FieldId + "_" + line.ElementId).each(function (index, item) { 1650 var jItem = jQuery(item); 1651 jItem.html(line.Rrp); 1652 jItem.addClass("show"); 1653 }); 1654 } 1655 } 1656 var spfTags = $targetField.find(".locate-spf-" + data.FieldId); 1657 for (var i = 0; i < data.PriceData.length; i++) { 1658 var line = data.PriceData[i]; 1659 if (line.SpecialFee != null && line.SpecialFee.length > 0) { 1660 jQuery(spfTags).filter("#adspf__" + data.FieldId + "_" + line.ElementId).each(function (index, item) { 1661 var jItem = jQuery(item); 1662 jItem.html(line.SpecialFee); 1663 jItem.addClass("show"); 1664 }); 1665 } 1666 } 1667 var nordeaprices = $targetField.find(".locate-nordeaprices-" + data.FieldId); 1668 for (var i = 0; i < data.PriceData.length; i++) { 1669 var line = data.PriceData[i]; 1670 if (line.FinancingTxt != null && line.FinancingTxt.length > 0) { 1671 jQuery(nordeaprices).filter("#adnordeaprice__" + data.FieldId + "_" + line.ElementId).each(function (index, item) { 1672 var jItem = jQuery(item); 1673 jItem.html(line.FinancingTxt); 1674 jItem.addClass("show"); 1675 }); 1676 } 1677 } 1678 var backorders = $targetField.find(".locate-adbackorder-" + data.FieldId); 1679 for (var i = 0; i < data.PriceData.length; i++) { 1680 var line = data.PriceData[i]; 1681 if (line.BackorderTxt != null && line.BackorderTxt.length > 0) { 1682 jQuery(backorders).filter("#adbackorder__" + data.FieldId + "_" + line.ElementId).each(function (index, item) { 1683 var jItem = jQuery(item); 1684 jItem.html(line.BackorderTxt); 1685 jItem.addClass("show"); 1686 }); 1687 } 1688 } 1689 $targetField.find('[data-toggle="popover"].backorder-info').each(function () { 1690 if (!$(this).data('bs.popover')) { 1691 $(this).popover({ 1692 sanitize: false 1693 }); 1694 } 1695 }); 1696 }; 1697 this.ensureCorrectImageSizesForField = function (targetfield, data) { 1698 var $field = jQuery(targetfield); 1699 var images = $field.find("img.d4-prod-thumb.lazy-allowed"); 1700 var lazyImages = $field.find("img.d4-lazy-thumb"); 1701 var loadSlideshowForProdThumb = images.length > 0 && lazyImages.length <= 0; //only start slideshow after loading images for d4-prod-thumb if we don't have d4-lazy-thumbs also 1702 var loadSlideshowForLazyThumb = lazyImages.length > 0 || !loadSlideshowForProdThumb; //start slideshow if we didn't start it for d4-prod-thumb or we have d4-lazy-thumb 1703 1704 self.ensureCorrectImageSizes(images, $field, data, false, loadSlideshowForProdThumb); 1705 self.ensureCorrectImageSizes(lazyImages, $field, data, true, loadSlideshowForLazyThumb);
1706 EnableLinksForArticlesWithBackground(); 1707 InitializeAnimationsInArticleWithBackground(); 1708 }; 1709 this.refineInsertedContent = function (targetfield, data) { 1710 self.ensureCorrectImageSizesForField(targetfield, data); 1711 self.applyCustomerSpecifics(targetfield, data); 1712 if (!document.body.classList.contains("publish-mode") && typeof lipscore !== 'undefined') { 1713 lipscore.initWidgets(); 1714 } 1715 self.initModulesInField(targetfield); 1716 }; 1717 self.initModulesInField = function (field) { 1718 jQuery(field).find("script[data-hasRun='false']").each(function (index, item) { 1719 item.setAttribute("data-hasRun", 'true'); 1720 var theNameSpace = eval(item.getAttribute("data-nameSpace")); 1721 loadModule(theNameSpace, item.getAttribute("data-moduleInstanceId"), item.getAttribute("data-uniqueId"), null, null); 1722 }); 1723 }; 1724 self.checkContentHash = function (fieldId, content) { 1725 var contentHash = self.getHash(content); 1726 if (StorageService.localStorage.getItem("PopFieldId" + fieldId) == contentHash) return true;else StorageService.localStorage.setItem("PopFieldId" + fieldId, contentHash); 1727 return false; 1728 }; 1729 self.contentShownBefore = function (fieldData) { 1730 var isShown = true; 1731 for (var i = 0; i < fieldData.Data.length; i++) { 1732 if (!self.checkContentHash(fieldData.Data[i].FieldId, fieldData.Data[i].Response)) isShown = false; 1733 } 1734 return isShown; 1735 }; 1736 self.getHash = function (str) { 1737 var hash = 0; 1738 for (var i = 0; i < str.length; i++) { 1739 var character = str.charCodeAt(i); 1740 hash = (hash << 5) - hash + character; 1741 hash = hash & hash; // Convert to 32bit integer 1742 } 1743 1744 return hash; 1745 }; 1746 self.preparePopup = function (fieldData, lightboxContainer) { 1747 if (fieldData.PopupRule == 1) if (self.contentShownBefore(fieldData)) return; 1748 var isSlideOver = fieldData.PopupPch === "#slideover-placeholder"; 1749 if (isSlideOver && !self.slideOverBoxIsOpen) mcWeb.lightbox.movePopupFieldsToOriginalPlaceholder(lightboxContainer);else if (!isSlideOver && !self.lightBoxIsOpen) mcWeb.lightbox.movePopupFieldsToOriginalPlaceholder(lightboxContainer); 1750 lightboxContainer.empty(); 1751 var dataFound = false; 1752 for (var i = 0; i < fieldData.Data.length; i++) { 1753 var data = fieldData.Data[i]; 1754 if (data.Response.length > 0) { 1755 dataFound = true; 1756 break; 1757 } 1758 } 1759 if (dataFound) { 1760 var popupParam = { 1761 css: "d4-popup d4-popup-rule-" + fieldData.PopupRule + self.getCssClassesForLightbox(fieldData), 1762 dataToApply: fieldData, 1763 callback: function callback() { 1764 self.fillLightboxWithContent(fieldData, lightboxContainer); 1765 self.initialiseAdLinks(); 1766 } 1767 }; 1768 PubSub.publish(fieldData.PopupEvent, popupParam); 1769 PubSub.publish(mcWeb.lightbox.events.contentChanged); 1770 if (isSlideOver) { 1771 PubSub.subscribe(mcWeb.slideOverBox.events.onHideLightbox, function () { 1772 self.slideOverBoxIsOpen = false; 1773 }); 1774 self.slideOverBoxIsOpen = true; 1775 } else { 1776 PubSub.subscribe(mcWeb.lightbox.events.onHideLightbox, function () { 1777 self.lightBoxIsOpen = false; 1778 }); 1779 self.lightBoxIsOpen = true; 1780 } 1781 } 1782 }; 1783 this.updateFieldContent = function (fieldData) { 1784 if (!fieldData.Success) return; 1785 try { 1786 self.fieldUpdateInProgress = true; 1787 self.PagingMode = fieldData.PagingMode; 1788 if (!self.IntersectionObserveAllowed) fieldData.AllowDeferred = false; 1789 if (fieldData.AllowDeferred && fieldData.PopupRule <= 0) { 1790 for (var i = 0; i < fieldData.Data.length; i++) { 1791 var data = fieldData.Data[i]; 1792 data.added = false; 1793 } 1794 } 1795 if (fieldData.PopupRule <= 0 && (!fieldData.AllowDeferred || fieldData.PagesRemaining > 0)) { 1796 self.addRemainingFieldsToDom(); //temporary fix for fields that wouldn't load. Needed when the fields added in the loop below adds content that sits between the fields held in memory and themselves. 1797 1798 for (var i = 0; i < fieldData.Data.length; i++) { 1799 var data = fieldData.Data[i]; 1800 data.targetField = $('#' + data.ClientId); 1801 self.addFieldContentToPage(fieldData, data.targetField, data); 1802 } 1803 } else if (fieldData.PopupRule > 0) { 1804 var lightboxContainer = $(fieldData.PopupPch); 1805 if (fieldData.Data.length > 0 && lightboxContainer !== undefined) self.preparePopup(fieldData, lightboxContainer); 1806 } else { 1807 var skipAdd = self.fieldsReadyToLoad.length > 0; 1808 if (fieldData.Data.length > 0) self.fieldsReadyToLoad.push(fieldData); 1809 if (!skipAdd) { 1810 self.addNextFieldToDom(); 1811 } else { 1812 // Fix for EJ 158200, load all remaning fields if there is anything published on the left side 1813 if (jQuery("#PageColumnLeft > .PublisherContainer .web-pub-field").length > 0) { 1814 self.addRemainingFieldsToDom(); 1815 } 1816 } 1817 } 1818 if (fieldData.InitializeRoyalSlider) { 1819 InitializeRoyalSliderInAds(); 1820 } 1821 if (fieldData.PagesRemaining > 0) { 1822 self.HasMorePages = true; 1823 } else if (data !== null && data !== undefined && data.IsProductListing) { 1824 if (fieldData.PagingMode > 2) { 1825 self.hidePaging(); 1826 } else if (fieldData.PagingMode === 2 && fieldData.Data !== null && fieldData.Data != undefined && fieldData.Data[0] !== null && fieldData.Data[0] !== undefined && fieldData.Data[0].IsProductListing) { 1827 self.hidePaging(); 1828 } 1829 } 1830 1831 //scrolling for paging within a field 1832 if (self.PagingMode >= 3 && !self.scrollEventIsRegistered && fieldData.PagesRemaining > 0) { 1833 self.scrollEventIsRegistered = true; 1834 jQuery(window).on("scroll", null, null, self.handleScroll); 1835 } else if (fieldData.PagesRemaining == 0 && self.PagingMode >= 3 && self.scrollEventIsRegistered && fieldData.Data.length > 0 && !fieldData.AllowDeferred) { 1836 //no more pages, let's remove the scroll registration 1837 jQuery(window).off("scroll", null, self.handleScroll); 1838 self.scrollEventIsRegistered = false;
1839 } 1840 var footerlist = document.querySelectorAll('.copyright-container'); 1841 var footer = null; 1842 if (footerlist.length > 0) footer = footerlist[0]; 1843 1844 //scrolling that causes multiple fields to load 1845 if (footer != null) { 1846 self.addScrollObserver(footer); 1847 } 1848 self.LoadingFromScroll = false; //re-enable auto-scrolling 1849 if (!document.body.classList.contains("publish-mode") && typeof lipscore !== 'undefined') { 1850 lipscore.initWidgets(); 1851 } 1852 if (fieldData.Data.some(function (x) { 1853 return x.IsProductListing; 1854 })) { 1855 self.handleScroll(); 1856 } 1857 } catch (e) { 1858 console.log(e); 1859 } finally { 1860 self.fieldUpdateInProgress = false; 1861 } 1862 }; 1863 self.getCssClassesForLightbox = function (fieldData) { 1864 var classesForFields = ""; 1865 for (var i = 0; i < fieldData.Data.length; i++) { 1866 var data = fieldData.Data[i]; 1867 if (data.Response.length <= 0) { 1868 continue; 1869 } 1870 classesForFields += " popupfield-" + data.FieldId; 1871 } 1872 return classesForFields; 1873 }; 1874 self.fillLightboxWithContent = function (fieldData, lightboxContainer) { 1875 getLibrary("renderEngineExtras").then(function () { 1876 fillLightboxWithContentExtra(self, fieldData, lightboxContainer); 1877 }); 1878 }; 1879 self.handleScroll = function (event) { 1880 getLibrary("renderEngineExtras").then(function () { 1881 handleScrollExtra(self, _scripts_McUtils__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A); 1882 }); 1883 }; 1884 self.resetAutoScrolledPages = function () { 1885 self.AutoScrolledPages = 0; 1886 }; 1887 self.onIntersection = function (entries) { 1888 if (!self.InitialLoadDone) return; 1889 var entry = null; 1890 if (entries.length > 0) entry = entries[0];else { 1891 return; 1892 } 1893 1894 // Are we in viewport? 1895 if (entry.intersectionRatio > 0) { 1896 if (!self.HasMorePages) { 1897 self.addNextFieldToDom(); 1898 } 1899 if (jQuery(".ajax-field.not-loaded").length == 0) { 1900 // No more unloaded areas/fields, so stop observing 1901 self.footerObserver.unobserve(entry.target); 1902 self.scrollEventFooterIsRegistered = false; 1903 self.footerObserver = null; 1904 } 1905 } 1906 }; 1907 self.onFieldIntersection = function (entries) { 1908 var entry = null; 1909 if (entries.length > 0) entry = entries[0];else { 1910 return; 1911 } 1912 1913 // Are we in viewport? 1914 if (entry.intersectionRatio > 0) { 1915 if (!self.HasMorePages || self.PagingMode <= 2) { 1916 // Stop observing 1917 self.fieldScrollObserver.unobserve(entry.target); 1918 self.scrollEventFieldIsRegistered = false; 1919 self.fieldScrollObserver = null; 1920 self.addNextFieldToDom(); 1921 } 1922 } 1923 }; 1924 self.addRemainingFieldsToDom = function () { 1925 self.LoadingFromScroll = true; //pause event-checking on scrolling 1926 1927 if (self.HasMoreFieldsToLoad()) { 1928 while (self.HasMoreFieldsToLoad()) { 1929 var myFieldData = self.fieldsReadyToLoad[0]; 1930 var myInnerData = myFieldData.Data.shift(); 1931 if (myFieldData.Data.length == 0) { 1932 self.fieldsReadyToLoad.shift(); 1933 } 1934 myInnerData.targetField = $('#' + myInnerData.ClientId); 1935 self.addFieldContentToPage(myFieldData, myInnerData.targetField, myInnerData); 1936 } 1937 } 1938 self.LoadingFromScroll = false; 1939 }; 1940 self.addNextFieldToDom = function (skipIfFieldNotInView) { 1941 self.LoadingFromScroll = true; //pause event-checking on scrolling 1942 var fieldWasAdded = false; 1943 var footer = null; 1944 if (self.HasMoreFieldsToLoad()) { 1945 while (self.HasMoreFieldsToLoad()) { 1946 var myFieldData = self.fieldsReadyToLoad[0]; 1947 var myInnerData = myFieldData.Data[0]; 1948 myInnerData.targetField = $('#' + myInnerData.ClientId); 1949 if (!skipIfFieldNotInView || _scripts_McUtils__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.isElementInView(myInnerData.targetField)) { 1950 self.addFieldContentToPage(myFieldData, myInnerData.targetField, myInnerData); 1951 fieldWasAdded = true; 1952 myInnerData = myFieldData.Data.shift(); 1953 if (myFieldData.Data.length == 0) { 1954 self.fieldsReadyToLoad.shift(); 1955 } 1956 } 1957 if (self.bottomImageToLoad != null && self.bottomImageToLoad != undefined && self.bottomImageToLoad.length > 0) { 1958 break; 1959 } 1960 if (footer == null) { 1961 var footerlist = document.querySelectorAll('.copyright-container'); 1962 if (footerlist.length > 0) footer = footerlist[0]; 1963 } 1964 if (skipIfFieldNotInView) { 1965 self.addScrollObservers(footer); 1966 break; 1967 } else if (myInnerData.Response !== null && myInnerData.Response.trim().length > 0 && myInnerData.targetField.height() > 0 && !_scripts_McUtils__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.isElementInView(myInnerData.targetField)) { 1968 if (self.addScrollObservers(footer)) break; 1969 } 1970 } 1971 } else { 1972 self.bottomImageToLoad = null; 1973 } 1974 1975 // Find all fields above the view 1976 if (!self.finishedLoadingFieldsAbove) { 1977 var myFieldData, myInnerData; 1978 var _self$popNextFieldAbo = self.popNextFieldAboveView(); 1979 myFieldData = _self$popNextFieldAbo.myFieldData; 1980 myInnerData = _self$popNextFieldAbo.myInnerData; 1981 while (myFieldData !== null) { 1982 myInnerData.targetField = $('#' + myInnerData.ClientId); 1983 self.addFieldContentToPage(myFieldData, myInnerData.targetField, myInnerData); 1984 fieldWasAdded = true; 1985 var _self$popNextFieldAbo2 = self.popNextFieldAboveView(); 1986 myFieldData = _self$popNextFieldAbo2.myFieldData; 1987 myInnerData = _self$popNextFieldAbo2.myInnerData; 1988 } 1989 self.finishedLoadingFieldsAbove = true; 1990 } 1991 if (fieldWasAdded) { 1992 startParaxify('.d4-article-parallax'); 1993 } 1994 if (self.bottomImageToLoad != undefined && self.bottomImageToLoad != null && self.bottomImageToLoad.length > 0) { 1995 var currImg = self.bottomImageToLoad[0]; 1996 if (currImg != null && currImg.src != undefined && currImg.src != null) { 1997 var currentImgSrc = self.bottomImageToLoad[0].src; 1998 var img = new Image(); 1999 img.onload = self.onBottomImgLoaded(myFieldData); //Set up loading of next fields when this image is loaded 2000 img.onerror = self.onBottomImgLoaded(myFieldData); 2001 img.src = currentImgSrc; 2002 return; 2003 } else if ($(currImg).hasClass("inner-content")) { 2004 var bg = $(currImg).css('background-image').trim(); 2005 if (bg.length > 0 && bg !== "none") { 2006 //set up loading after this background image has loaded 2007 var currentImgSrc = bg.substring(5, bg.length - 2); 2008 var img = new Image(); 2009 img.onload = self.onBottomImgLoaded(myFieldData); 2010 img.onerror = self.onBottomImgLoaded(myFieldData); 2011 img.src = currentImgSrc; 2012 return; 2013 } 2014 } 2015 } 2016 if (!self.HasMoreFieldsToLoad()) { 2017 startParaxify('.d4-article-parallax'); 2018 } 2019 self.LoadingFromScroll = false; //un-pause event-checking on scrolling 2020 }; 2021 2022 //adds scroll observer on the next field, and optionally on the footer 2023 //returns true when footer observer was added 2024 self.addScrollObservers = function (footer) { 2025 var fieldToObserve = self.findNextFieldToObserve(self.fieldsReadyToLoad); 2026 if (fieldToObserve != null) { 2027 var fieldElement = document.getElementById(fieldToObserve.ClientId); 2028 self.addFieldScrollObserver(fieldElement); 2029 } 2030 if (footer == null) return false;
2031 //observe the footer to enable it to trigger adding more content 2032 if (!_scripts_McUtils__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.isElementInView(footer)) { 2033 self.addScrollObserver(footer); 2034 return true; 2035 } 2036 return false; 2037 }; 2038 self.onBottomImgLoaded = function (myFieldData) { 2039 return function () { 2040 var footerlist = document.querySelectorAll('.copyright-container'); 2041 var footer = null; 2042 if (footerlist.length > 0) footer = footerlist[0]; 2043 var loadNextField = false; 2044 if (_scripts_McUtils__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.isElementInView(footer)) { 2045 loadNextField = true; 2046 } 2047 var nextField = self.findNextVisibleField(self.fieldsReadyToLoad); 2048 if (nextField !== null) { 2049 loadNextField = true; 2050 } else { 2051 var fieldToObserve = self.findNextFieldToObserve(self.fieldsReadyToLoad); 2052 if (fieldToObserve != null) { 2053 var fieldElement = document.getElementById(fieldToObserve.ClientId); 2054 self.addFieldScrollObserver(fieldElement); 2055 } 2056 } 2057 if (!loadNextField) { 2058 if (self.CheckStatistics) { 2059 //we have now added the last dynamic field before scrolling, so we log which ones it is so we can learn which fields to load statically later to optimize the page 2060 self.postStatistics(); 2061 self.CheckStatistics = false; 2062 } 2063 self.addScrollObserver(footer); 2064 return; 2065 } 2066 self.addNextFieldToDom(); 2067 }; 2068 }; 2069 self.popNextFieldAboveView = function () { 2070 for (var i = 0; i < self.fieldsReadyToLoad.length; i++) { 2071 var fieldReadyToLoad = self.fieldsReadyToLoad[i]; 2072 for (var n = 0; n < fieldReadyToLoad.Data.length; n++) { 2073 var data = fieldReadyToLoad.Data[n]; 2074 var element = document.getElementById(data.ClientId); 2075 if (element !== null) { 2076 if (_scripts_McUtils__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.isElementAboveView(element)) { 2077 fieldReadyToLoad.Data.splice(n, 1); 2078 if (fieldReadyToLoad.Data.length === 0) self.fieldsReadyToLoad.splice(i, 1); 2079 return { 2080 myFieldData: fieldReadyToLoad, 2081 myInnerData: data 2082 }; 2083 } 2084 } 2085 } 2086 } 2087 return { 2088 myFieldData: null, 2089 myInnerData: null 2090 }; 2091 }; 2092 self.HasMoreFieldsToLoad = function () { 2093 if (self.fieldsReadyToLoad.length == 0 || self.fieldsReadyToLoad[0].Data.length == 0) return false;else return true; 2094 }; 2095 this.findNextVisibleField = function () { 2096 for (var i = 0; i < self.fieldsReadyToLoad.length; i++) { 2097 var fieldReadyToLoad = self.fieldsReadyToLoad[i]; 2098 for (var n = 0; n < fieldReadyToLoad.Data.length; n++) { 2099 var data = fieldReadyToLoad.Data[n]; 2100 var element = document.getElementById(data.ClientId); 2101 if (element !== null) { 2102 if (_scripts_McUtils__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.isElementInView(element)) return data; 2103 } 2104 } 2105 } 2106 return null; 2107 }; 2108 this.findNextFieldToObserve = function () { 2109 for (var i = 0; i < self.fieldsReadyToLoad.length; i++) { 2110 var fieldReadyToLoad = self.fieldsReadyToLoad[i]; 2111 for (var n = 0; n < fieldReadyToLoad.Data.length; n++) { 2112 var data = fieldReadyToLoad.Data[n]; 2113 var element = document.getElementById(data.ClientId); 2114 if (element !== null) { 2115 if (_scripts_McUtils__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.isElementBelowView(element)) return data; 2116 } 2117 } 2118 } 2119 return null; 2120 }; 2121 this.addScrollObserver = function (footer) { 2122 if (!self.scrollEventFooterIsRegistered && (self.HasMorePages || self.HasMoreFieldsToLoad())) { 2123 self.scrollEventFooterIsRegistered = true; 2124 var config = { 2125 // If the image gets within 50px in the Y axis, start the download. 2126 rootMargin: '0px 0px', 2127 threshold: 0.01 2128 }; 2129 2130 // The observer for the images on the page 2131 self.footerObserver = new IntersectionObserver(self.onIntersection, config); 2132 self.footerObserver.observe(footer); 2133 } 2134 }; 2135 this.addFieldScrollObserver = function (field) { 2136 if (!self.scrollEventFieldIsRegistered) { 2137 self.scrollEventFieldIsRegistered = true; 2138 var config = { 2139 // If the image gets within 50px in the Y axis, start the download. 2140 rootMargin: '0px 0px', 2141 threshold: 0.01 2142 }; 2143 2144 // The observer for the images on the page 2145 self.fieldScrollObserver = new IntersectionObserver(self.onFieldIntersection, config); 2146 self.fieldScrollObserver.observe(field); 2147 } 2148 }; 2149 2150 //todo: move to script-block from "RenderFilter", only needed when _app.Setup.GetSettingValue(CategoryName.MulticaseAttributes, SettingName.MaxDefaultVisibleAttributeValues) == "0") 2151 this.toggleIconAttributeValues = function (target) { 2152 $('#AttributeListBox .collapse.event-not-ready').on('shown.bs.collapse', function () { 2153 $(this).parent().find(".glyphicon-plus").removeClass("glyphicon-plus").addClass("glyphicon-minus"); 2154 }).on('hidden.bs.collapse', function () { 2155 $(this).parent().find(".glyphicon-minus").removeClass("glyphicon-minus").addClass("glyphicon-plus"); 2156 }); 2157 $('#AttributeListBox .collapse').removeClass("event-not-ready"); 2158 }; 2159 this.searchAtttributes = function (target) { 2160 getLibrary("renderEngineExtras").then(function () { 2161 searchAtttributesExtra(target); 2162 }); 2163 }; 2164 this.preventDefaultOnEnter = function (event) { 2165 if (event.keyCode == 13) { 2166 event.preventDefault(); 2167 return false;
2168 } 2169 }; 2170 2171 //todo: move to secondary file? 2172 this.updateFilterContent = function (filterData) { 2173 getLibrary("renderEngineExtras").then(function () { 2174 updateFilterContentExtra(self, filterData); 2175 }); 2176 }; 2177 this.urlParamsFilterIsValidFor = null; 2178 this.delayLoadFilterParent = null; 2179 this.delayLoadFilterManufacturerId = 0; 2180 this.delayLoadFilterLoaded = false; 2181 this.unhideProductMenu = function () { 2182 var menu = jQuery("div.ProductMenu"); 2183 if (menu.length > 0) { 2184 menu.removeClass("hidden"); 2185 } 2186 }; 2187 this.selectLayoutClick = function (event) { 2188 var dummyBarn = jQuery(".dummy-element *"); 2189 dummyBarn.prop("onclick", null); 2190 dummyBarn.removeAttr('href'); 2191 dummyBarn.off(); 2192 event.stopImmediatePropagation(); 2193 mcWeb.publisherAdminMenu.callLayoutAction("Select", event); 2194 return false; 2195 }; 2196 this.cancelBubble = function (e) { 2197 var evt = e ? e : window.event; 2198 if (evt.stopPropagation) evt.stopPropagation(); 2199 if (evt.cancelBubble != null) evt.cancelBubble = true; 2200 }; 2201 self.updateVariantMatrix = function (data) { 2202 getLibrary("renderEngineExtras").then(function () { 2203 updateVariantMatrixField(data); 2204 loadLightboxFields(self); 2205 }); 2206 }; 2207 2208 //todo: move to another file, getlibrary call from onClick event in ToggleDefaultKontaktDisplayElement 2209 self.toggleDefaultContact = function (e) { 2210 self.service.GetAction("ToggleDefaultCustomer").then(function (e) { 2211 PubSub.publish(mcWeb.hamburgerMenu.events.onMenuNeedsRefresh); 2212 PubSub.publish(mcWeb.MegaMenuResponsive.events.onMenuNeedsRefresh); 2213 var delayInMilliseconds = 400; 2214 setTimeout(function () { 2215 location.reload(); 2216 }, delayInMilliseconds); 2217 }); 2218 }; 2219 2220 //todo: move to another file, getLibrary call from SelectDefaultKontaktDialog.ascx 2221 self.SetPrimaryOrSecondaryDefaultContact = function (preferSecondaryDefaultContactId) { 2222 self.service.PostAction("SetPrimaryOrSecondaryDefaultContact", { 2223 PreferSecondaryDefaultContactId: preferSecondaryDefaultContactId 2224 }).then(function (result) { 2225 window.localStorage.hideSelectDefaultKontaktPopup = 'true'; 2226 if (result) { 2227 // prefrence was change, we need to reload the page 2228 PubSub.publish(mcWeb.hamburgerMenu.events.onMenuNeedsRefresh); 2229 PubSub.publish(mcWeb.MegaMenuResponsive.events.onMenuNeedsRefresh); 2230 var delayInMilliseconds = 200; 2231 setTimeout(function () { 2232 location.reload(); 2233 }, delayInMilliseconds); 2234 } else { 2235 $('#selectDefaultKontaktPopup').modal('hide'); 2236 } 2237 }); 2238 }; 2239}(jQuery); 2240if (document.observe === undefined) { 2241 document.observe = function (name, myfunction) { 2242 if (name === "dom:loaded") jQuery.ready(myfunction); 2243 // Override document.observe to not give errors from Gaia 2244 }; 2245} 2246 2247jQuery.fn.outerHTML = function () { 2248 return jQuery('<div />').append(this.eq(0).clone()).html(); 2249}; 2250window.mcWeb.ajaxRenderEngine = AjaxRenderingEngine; 2251window.mcWeb.ajaxRenderEngine.events = AjaxRenderingEngineEventTypes; 2252 2253/***/ }), 2254 2255/***/ 4746: 2256/***/ (function(__unused_webpack_module, __webpack_exports__) { 2257 2258"use strict"; 2259function McUtils() {} 2260McUtils.prototype = { 2261 constructor: McUtils, 2262 isElementInView: function isElementInView(element, fullyInView) { 2263 var pageTop = jQuery(window).scrollTop(); 2264 var pageBottom = pageTop + jQuery(window).height(); 2265 var elementTop = jQuery(element).offset().top; 2266 var elementBottom = elementTop + jQuery(element).height(); 2267 if (fullyInView === true) { 2268 return pageTop < elementTop && pageBottom > elementBottom; 2269 } else { 2270 return elementTop <= pageBottom && elementBottom >= pageTop; 2271 } 2272 }, 2273 isElementBelowView: function isElementBelowView(element) { 2274 var pageTop = jQuery(window).scrollTop(); 2275 var pageBottom = pageTop + jQuery(window).height(); 2276 var elementTop = jQuery(element).offset().top; 2277 return elementTop > pageBottom; 2278 }, 2279 isElementAboveView: function isElementAboveView(element) { 2280 var pageTop = jQuery(window).scrollTop(); 2281 var elementTop = jQuery(element).offset().top; 2282 var elementBottom = elementTop + jQuery(element).height(); 2283 return elementBottom < pageTop; 2284 } 2285}; 2286/* harmony default export */ __webpack_exports__.A = (new McUtils()); 2287 2288/***/ }), 2289 2290/***/ 5213: 2291/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { 2292 2293"use strict"; 2294/* harmony import */ var _scripts_ajax_render_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3477); 2295/* harmony import */ var _scripts_ViewModels_variant_ajax_variant_selector_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2673); 2296/* harmony import */ var _scripts_ViewModels_variant_ajax_variant_selector_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_scripts_ViewModels_variant_ajax_variant_selector_js__WEBPACK_IMPORTED_MODULE_1__); 2297 2298 2299/* harmony default export */ __webpack_exports__.A = (new function ($) { 2300 'use strict'; 2301 2302 this.vm = function (id) { 2303 var self = this; 2304 self.id = "#" + id; 2305 self.service = new WebApiService("FieldRenderer"); 2306 self.vs = new mcWeb.ajaxVariantSelector.vm(self);
2307 self.avsInitialised = false; 2308 self.load = function (data, settings) {}; 2309 self.init = function (data) { 2310 self.currentAreaName = data.areaName; 2311 self.currentNodeId = data.nodeId; 2312 self.width = 400; 2313 if (self.id === '#lightbox-placeholder') { 2314 self.popupEvent = mcWeb.lightbox.events.onShowLightbox; 2315 self.currentPlacement = "c"; 2316 } else { 2317 self.popupEvent = mcWeb.slideOverBox.events.onShowLightbox; 2318 self.currentPlacement = "rhs"; 2319 } 2320 }; 2321 self.show = function (plid, manufacturerId) { 2322 var param = { 2323 NodeId: self.currentNodeId, 2324 Width: self.width, 2325 ManufacturerId: manufacturerId, 2326 ActivePlid: plid, 2327 Placement: self.currentPlacement, 2328 AreaName: self.currentAreaName 2329 }; 2330 self.service.PostAction("RenderQuickview", param).then(function (result) { 2331 if (result != null && result.Success) { 2332 var container = $(self.id); 2333 if (container != null && container != undefined) { 2334 container.html(result.Content); 2335 _scripts_ajax_render_engine__WEBPACK_IMPORTED_MODULE_0__/* .AjaxRenderingEngine */ .X.refineInsertedContent(container, result); 2336 //todo: finn riktig klasse å bruke her. avhenger av hvilken popup? 2337 //mangler å kjøre royal-slider for resultatet. Må gjøres for å få fram bilder osv. 2338 var popupParam = { 2339 css: "d4-popup d4-popup-quickview", 2340 callback: function callback() { 2341 var thumbs = { 2342 //todo: get from settings? 2343 spacing: 10, 2344 orientation: 'horizontal', 2345 autoCenter: false 2346 }; 2347 var navigationMethod = 'bullets'; //todo: get from settings? 2348 InitializeRoyalSliderForPreview(null, null, null, 'div.d4-preview', thumbs, navigationMethod); 2349 self.vs.bind(); 2350 self.vs.reinit(); 2351 } 2352 }; 2353 PubSub.publish(self.popupEvent, popupParam); 2354 } 2355 } else { 2356 //hide slideoverbox or lightbox 2357 if (self.currentPlacement == "rhs") { 2358 PubSub.publish("mcWeb.slideOverBox.onHideLightbox"); 2359 } else { 2360 PubSub.publish("mcWeb.lightbox.onHideLightbox"); 2361 } 2362 } 2363 }); 2364 }; 2365 }; //end vm 2366}(jQuery)); 2367function InitializeRoyalSliderForPreview(optionChangesXS, optionChangesSM, optionChangesMD, containerClass, thumbnailSettings, navigationMethod) { 2368 jQuery(function () { 2369 var optionsXS = { 2370 controlNavigation: 'bullets', 2371 keyboardNavEnabled: true, 2372 numImagesToPreload: 1, 2373 navigateByClick: false, 2374 arrowsNav: false, 2375 imageScaleMode: 'fit', 2376 thumbs: false, 2377 video: { 2378 disableCSS3inFF: false 2379 }, 2380 fullscreen: { 2381 enabled: false 2382 } 2383 }; 2384 var optionsSM = { 2385 controlNavigation: 'bullets', 2386 keyboardNavEnabled: true, 2387 numImagesToPreload: 1, 2388 navigateByClick: false, 2389 imageScaleMode: 'fit', 2390 thumbs: false, 2391 video: { 2392 disableCSS3inFF: false 2393 }, 2394 fullscreen: { 2395 enabled: false 2396 } 2397 }; 2398 var thumbs = { 2399 spacing: 10, 2400 orientation: 'vertical', 2401 autoCenter: false 2402 }; 2403 if (thumbnailSettings != undefined && thumbnailSettings != null) { 2404 thumbs = thumbnailSettings; 2405 } 2406 var controlNavigation = 'thumbnails'; 2407 if (navigationMethod != undefined && navigationMethod != null) { 2408 controlNavigation = navigationMethod; 2409 } 2410 var optionsMD = { 2411 controlNavigation: controlNavigation, 2412 keyboardNavEnabled: true, 2413 numImagesToPreload: 1, 2414 navigateByClick: false, 2415 imageScaleMode: 'fit', 2416 thumbs: thumbs, 2417 video: { 2418 disableCSS3inFF: false 2419 }, 2420 fullscreen: { 2421 enabled: false 2422 } 2423 }; 2424 jQuery.extend(optionsXS, optionChangesXS); 2425 jQuery.extend(optionsSM, optionChangesSM); 2426 jQuery.extend(optionsMD, optionChangesMD); 2427 var options = {}; 2428 switch (mcWeb.responsive.getScreenSize()) { 2429 case 'xs': 2430 options = optionsXS; 2431 break; 2432 case 'sm': 2433 options = optionsSM; 2434 break; 2435 default: 2436 options = optionsMD; 2437 break; 2438 } 2439 var slider = jQuery(containerClass + " .prod-image-slider"); 2440 var rs = slider.royalSlider(options).data('royalSlider');
2441 slider.prepend(slider.find('.rsNav')); 2442 }); 2443} 2444 2445////Bind viewmodel for two quickviews, one for center and one for rhs 2446//loadModule(mcWeb.quickview, 'slideover-placeholder', 'slideover-placeholder', null, null,true); 2447//loadModule(mcWeb.quickview, 'lightbox-placeholder', 'lightbox-placeholder', null, null,true); 2448 2449/***/ }) 2450 2451}]); 2452//# sourceMappingURL=313.8478e91eb0f6d996378d.js.map
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.