1815 Lun Strikk

1815 Lun Strikk

Pris
kr 70,00

0) { // Create content var dimensionsInStockText = _.map(availableDimProducts, function (dimProduct) { return dimProduct.dimensions[0].STPD_SysName; }).join(', '); $dimensionsStockContent = $('

' + labels.dimensionsInStock + '
' + dimensionsInStockText + ''); } else { $dimensionsStockContent = $('
' + labels.dimensionsOutOfStock + '
'); } // Place it in own container if ($currentDimensionsInStockContainer.length === 1) { $currentDimensionsInStockContainer.prepend($dimensionsStockContent).addClass('show'); } }); }) .fail(function () { console.error('Failed to load available dimensions'); }); } function setupDimensionChoices() { var $prodContainer; var $mainImage; var mainImageURL; var dimImageUrl; $('.' + classes.dimItem).hover( function () { $prodContainer = $(this).closest('.' + classes.prodItem); $mainImage = $prodContainer.find('.' + classes.mainImage); mainImageURL = $prodContainer.find('.' + classes.mainImage).attr('src'); dimImageUrl = $(this).data('main-img-src'); if ($mainImage.length && dimImageUrl) { $mainImage.attr('src', dimImageUrl); } }, function () { $mainImage.attr('src', mainImageURL); } ); } function onQuantityChanged() { if (vars.multPriceByQuantity) { var $prodContainer = $(this).closest('.' + classes.prodItem); var productId = $prodContainer.data('productid'); var quantity = getSelectedProductQuantity($prodContainer); var cacheKey = 'quantityPrices_' + productId + '_' + quantity; if (cacheKey in dataCache) { var productListItem = dataCache[cacheKey]; updateDisplayedPrices($prodContainer, productListItem); } else { blockUI(); var query = { action: 'GetProductQuantityPrice', controlId: currentControlState.controlId, pageId: root.BasePageID, productId: productId, quantity: quantity }; $.get(productsHandlerUrl, query) .done(function (productListItem) { dataCache[cacheKey] = productListItem; updateDisplayedPrices($prodContainer, productListItem); }) .fail(function (errResp) { var message; if (typeof (errResp) === 'object') { // Extract error message var responseObj = JSON.parse(errResp.responseText); message = responseObj.Message ? responseObj.Message : errResp.statusText; } else { message = errResp; } notify(labels.failedToLoadProductList + '
' + message, 'error'); }) .always(unblockUI); } } function updateDisplayedPrices($prodContainer, productListItem) { if (productListItem.DiscountPrice) { $prodContainer.find('.DiscountPriceRow .DiscountPrice.Value').text(productListItem.DiscountPriceString); } if (productListItem.Price) { if (productListItem.OriginalPrice) { $prodContainer.find('.PriceRow .OriginalPrice.Value').text(productListItem.OriginalPriceString); } $prodContainer.find('.PriceRow .Price').not('.WithVAT,.WithoutVAT').text(productListItem.PriceString); } if (productListItem.PriceWithoutVAT) { if (productListItem.OriginalPrice) { $prodContainer.find('.PriceRow .OriginalPrice.Value').text(productListItem.OriginalPriceString); } $prodContainer.find('.PriceRow .Price.WithoutVAT').text(productListItem.PriceWithoutVATString); } if (productListItem.PriceWithVAT) { if (productListItem.OriginalPrice) { $prodContainer.find('.PriceRow .OriginalPrice.Value').text(productListItem.OriginalPriceString); } $prodContainer.find('.PriceRow .Price.WithVAT').text(productListItem.PriceWithVATString); } if (productListItem.Price2) { $prodContainer.find('.Price2Row .Price2.Value').text(productListItem.Price2String); } if (productListItem.Price3) { $prodContainer.find('.Price3Row .Price3.Value').text(productListItem.Price3String); } } } var $searchBtn = $('.js-product-list-search').find('.js-product-list-search-btn'); $searchBtn.unbind().on('click', function (e) { e.preventDefault(); var term = $.trim($searchInput.val()); if (term) { search(term); } }); $searchInput.autocomplete({ minLength: 3, source: function () { $searchBtn.trigger('click'); } }).one('keypress', function (e) { var term = $.trim($searchInput.val()); if (e.keyCode == 13) { e.preventDefault(); search(term); } }); $searchInput.keyup(function () { if (!this.value) { $productListContainer.html($(document.createElement('h3')).text(labels.enterSearchQuery).addClass(currentControlState.controlId.toString().toLowerCase() + ' __no-products-msg')); $pagingControls.find('.ProductListPager').remove(); } else if (this.value.length < 3) { $productListContainer.html($(document.createElement('h3')).text(labels.noProductsFound).addClass(currentControlState.controlId.toString().toLowerCase() + ' __no-products-msg')); $pagingControls.find('.ProductListPager').remove(); } }); }; function search(term) { if ($timer) { window.clearTimeout($timer); $timer = null; } $timer = window.setTimeout(function() { searchTerm = term; refreshProductList(false, true, false, true); }, 500); } function refresh(callback, needPublish, dontBlockUi) { if (!dontBlockUi) blockUI(); var query = { action: 'GetProductList', pageId: root.BasePageID, itemId: root.BaseItemID, orderId: orderId, controlId: currentControlState.controlId, perPage: currentControlState.perPage, page: currentControlState.page, sort: currentControlState.sort, filteredItemIds: JSON.stringify(currentControlState.filteredItemIds), filteredCategoryIDs: JSON.stringify(currentControlState.filteredCategoryIDs), s: searchTerm, isProductPage: currentControlState.isProductPage, showOnlyInStock: currentControlState.showOnlyInStock }; $.post(productsHandlerUrl, query) .done(function (productListData) { //note: total items count may change when 'show only in stock' is changed currentControlState.totalItems = productListData.totalItemsCount; if (productListData.totalItemsCount > 0) { $productListContainer.html(productListData.productListHtml); } else { $productListContainer.html($(document.createElement('h3')).text(labels.noProductsFound).addClass(currentControlState.controlId.toString().toLowerCase() + ' __no-products-msg')); } initProductControls(); if(callback && typeof (callback) === 'function') { callback.apply(this); } if (needPublish) { pubSub.publish(refreshChannelPrefix, { showOnlyInStock: currentControlState.showOnlyInStock }); } }) .fail(function(errResp) { var message; if (typeof (errResp) === 'object') { // Extract error message var responseObj = JSON.parse(errResp.responseText); message = responseObj.Message ? responseObj.Message : errResp.statusText; } else { message = errResp; } notify(labels.failedToLoadProductList + '
' + message, 'error'); }) .always(unblockUI); } function setupPaging() { if($pagingControls.length > 0) { var perPage = currentControlState.perPage; var totalItems = currentControlState.totalItems; // This will re-init paging controls $pagingControls.find('.ProductListPager').remove(); $pagingControls.html('
    '); if (perPage > 0 && totalItems > perPage) { var $listPager = $pagingControls.find('.ProductListPager'); $listPager.twbsPagination({ totalPages: Math.ceil(totalItems / perPage), visiblePages: shownPages, startPage: currentControlState.page, first: labels.first, next: labels.next, prev: labels.prev, last: labels.last, onPageClick: pagingChangedCallback }); var $viewAllItem = $('
  • ' + labels.viewAll + '
  • '); $viewAllItem.click(viewAllClicked); $listPager.append($viewAllItem); } } function pagingChangedCallback(event, page) { //note: re-adding ViewAll item because it is removed by pagination plugin on page change var $viewAllItem = $('
  • ' + labels.viewAll + '
  • '); $viewAllItem.click(viewAllClicked); $pagingControls.find('.ProductListPager').append($viewAllItem); currentControlState.page = page; refreshProductList(true, false, true); } function viewAllClicked() { currentControlState.perPage = -1; // Reset current page index currentControlState.page = 1; refreshProductList(true, true, true); } } function onUpdateHistory() { // Update history if(enableHistoryState && root.history && typeof (root.history.pushState) !== 'undefined') { var newStateUrl = location.href.split('#')[0]; var state = currentControlState; if(state.sort) { newStateUrl = $.setQueryStringParam(newStateUrl, 'sort_' + state.controlId, state.sort); } if (state.page) { newStateUrl = $.setQueryStringParam(newStateUrl, 'page_' + state.controlId, state.page); } if(state.perPage) { newStateUrl = $.setQueryStringParam(newStateUrl, 'perpage_' + state.controlId, state.perPage); } if (state.showOnlyInStock == true) { newStateUrl = $.setQueryStringParam(newStateUrl, 'instockonly_' + state.controlId, 'true'); } else { newStateUrl = $.removeQueryStringParam(newStateUrl, 'instockonly_' + state.controlId); } if(!_.isEmpty(state.appliedFilters)) { newStateUrl += '#' + JSON.stringify(state.appliedFilters); } if (newStateUrl != location.href) { root.history.pushState(currentControlState, '', newStateUrl); } } } function errorCallback(dataContract) { if (dataContract.status.toLowerCase() === 'unauthorized') { pubSub.publish('notification.warning', { text: labels.availableToRegisteredOnly + '
    ' + labels.loginToContinue + '', layout: 'center', killer: true, modal: true, timeout: false }); } else if(dataContract.result){ _.each(dataContract.result.items, function (prod) { notify(prod.message, 'error'); }); } } function refreshProductList(updateHistory, updatePagers, needPublish, dontBlockUi) { refresh(function() { $viewSettings.show(); if (updatePagers) { setupPaging(); } if(updateHistory) { onUpdateHistory(); } }, needPublish, dontBlockUi); } //#region Helpers function getSelectedProductQuantity($prodContainer) { return $prodContainer.find('.QuantityTxb,.QuantityDrp').val(); } function getAddToCartContract($prodContainer) { var customFields = {}; $prodContainer.find('.customFieldsCont .customField').each(function(idx, elem) { var $elem = $(elem); var customFieldId = $elem.attr('customFieldId'); //Special handling for checkbox because they are wrapped in a span if($elem.find('input').length > 0) { $elem = $elem.find('input'); } if(customFieldId) { var cfValue = $elem.is(':checkbox') ? $elem.is(':checked').toString() : $elem.val(); customFields[customFieldId] = cfValue; } }); return { productId: $prodContainer.data('productid'), imageId: $prodContainer.data('imageid'), quantity: getSelectedProductQuantity($prodContainer), fraction: $prodContainer.find('.js-uc193-fraction').val(), customFields: customFields, }; } function notify(message, type) { var notificationChannel = typeof (type) === 'string' && type ? 'notification.' + type : 'notification'; pubSub.publish(notificationChannel, message); } function blockUI() { if (typeof ($.blockUI) === 'function') { $.blockUI({ message: null }); } } function unblockUI() { if (typeof ($.unblockUI) === 'function') { $.unblockUI(); } } //#endregion $(function() { initProductControls(); var initialTerm = $.trim($searchInput.val()); if (initialTerm && initialTerm.length >= 3) { search(initialTerm); } // Subscribe to removeFromCart event and hide shopCart icon root.PublicEStore.subscribe('estore.callback.shopcart.removefromcart', removeFromCartCallback); root.PublicEStore.subscribe('estore.callback.shopcart.emptycart', emptyCartCallback); root.PublicEStore.subscribe('estore.callback.shopcart.addtocart', addToCartGlobalCallback); setupViewSettings(); if ($mainPanel.find('.js-fragment-container.Campaign').length > 0) { // Hide paging and sorting for campaigns. Campaigns should be valid for the initial load only. $viewSettings.hide(); } else { $viewSettings.show(); setupPaging(); } // Filters pubSub.subscribe(filtersChannelPrefix + '.apply', filterCallback); pubSub.subscribe(staticfilterChannelPrefix + '.apply', function (topic, data) { currentControlState.page = 1; currentControlState.totalItems = data.itemsCount; currentControlState.filteredCategoryIDs = data.selectedIds; refreshProductList(false, true, false); }); pubSub.subscribe(staticfilterChannelPrefix + '.reset', function () { currentControlState.page = 1; currentControlState.totalItems = 0; currentControlState.filteredCategoryIDs = null; refreshProductList(false, true, false); }); if (enableHistoryState) { // Set initial state root.history.replaceState(currentControlState, '', null); // Subscribe to popstate event $(root).on('popstate', onHistoryPopState); } function filterCallback(topic, filterState) { var totalItemsAfterFiltersApplied = typeof(filterState.filteredItemIds) !== 'undefined' && filterState.filteredItemIds !== null ? filterState.filteredItemIds.length : totalItemsInDataSource; // reset paging if (!filterState.isRestoring) { currentControlState.page = 1; } currentControlState.totalItems = totalItemsAfterFiltersApplied; // apply filters currentControlState.filteredItemIds = filterState.filteredItemIds; currentControlState.appliedFilters = filterState.appliedFilters; refreshProductList(true, true, true); } function removeFromCartCallback(topic, dataContract) { _.each(dataContract.result.items, function (prod) { if (prod.status.toLowerCase() === 'ok') { $productContainers.filter('[data-productid="' + prod.productID + '"]').find(' .js-add-to-cart').hide(); } }); } function emptyCartCallback(topic, dataContract) { if (dataContract.status.toLowerCase() === 'ok') { $productListContainer.find('.js-add-to-cart').hide(); } } function addToCartGlobalCallback(topic, contract) { _.each(contract.result.items, function (prod) { if (prod.status.toLowerCase() === 'ok') { // Update total product's count for the current temp order line var prodContainer = $productContainers.filter('[data-productId="' + prod.productID + '"]'); var orderLineQuantityContainer = prodContainer.find('.js-prod-count'); orderLineQuantityContainer.show(); orderLineQuantityContainer.text(prod.totalQuantityInTempOrderLine); // Animate action var addToCartIconContainer = prodContainer.find('.js-add-to-cart'); if (addToCartIconContainer.length > 0) { addToCartIconContainer.show(); prodContainer.effect('transfer', { to: addToCartIconContainer }, 500, function () { addToCartIconContainer.effect('bounce', null, 500); }); } } }); } function setupViewSettings() { // Setup sorting if ($sortingControls.length > 0) { currentControlState.sort = $sortingControls.val(); $sortingControls.change(function () { sortingChangedCallback(this.value); }); } function sortingChangedCallback(sortBy) { currentControlState.sort = sortBy; refreshProductList(true, false, true); } // Setup items per page changes $perPageItems.change(function (evt) { currentControlState.perPage = parseInt(evt.target.value); // Reset current page index currentControlState.page = 1; refreshProductList(true, true, true); }); //Setup show only in stock change if ($cbxShowOnlyInStock.length) { $cbxShowOnlyInStock.prop('checked', currentControlState.showOnlyInStock === true); $cbxShowOnlyInStock.change(function () { currentControlState.page = 1; currentControlState.showOnlyInStock = $cbxShowOnlyInStock.prop('checked'); refreshProductList(true, true, true); }); } } function onHistoryPopState(evt) { var state = evt.originalEvent.state; if (state && state.controlId == currentControlState.controlId) { // Restore target state currentControlState = state; if ($cbxShowOnlyInStock.length) { $cbxShowOnlyInStock.prop('checked', currentControlState.showOnlyInStock === true); } refreshProductList(false, true, true); } } }); })(jQuery, _, window);
    Din nettleser er utdatert!

    For å kunne bruke alle funksjoner på nettsiden må du oppdatere nettleseren. Oppdater min nettleser nå

    ×