//Initial creation of ElgigantenScript object if(ElgigantenScript === undefined) { var ElgigantenScript = {}; } // ==== Function for moving elements ==== // Created by : Fredrik Frederiksen // Version : 1.1 // Update Date : 03/07-2019 // ==== ==== // containerClass = Area that should be used to look for the elements // elementClass = Class ofthe element to bemoved // targetClass = Class of the location where the element should be prepended to // searchTerm = Used to check if element contains text, leave as "" to move all matching elements // cssArray = A multidimentional array that contains css to be assigned the element after it has been moved ex(cssArray = [["font-size","14px"],["padding","2px 10px 2px 10px"]] ElgigantenScript.PrependElement = function (containerClass, elementClass, targetClass, searchTerm, cssArray) { $('.' + containerClass).each(function () { if ($(this).find('.' + elementClass + ':contains(\'' + searchTerm + '\')').length) { $(this).find('.' + elementClass + ':contains(\'' + searchTerm + '\')').detach().prependTo($(this).find('.' + targetClass)); }; }); if (Array.isArray(cssArray)) { $('.' + targetClass).css('margin-top', function (index, curValue) { return parseInt(curValue, 10) + 10 + 'px'; }); var cssI; for (cssI = 0; cssI < cssArray.length; cssI++) { var cssName = cssArray[cssI][0]; var cssValue = cssArray[cssI][1]; $('.' + containerClass + ' .' + targetClass + ' .' + elementClass + ':contains(\'' + searchTerm + '\')').css(cssName, cssValue); }; }; }; /* example of use $(document).ready(function(){ var cssArray = [ ["font-size","14px"], ["padding","2px 10px 2px 10px"], ["height","18px"], ["line-height","16px"], ["margin", "auto"], ["right", "auto"], ["left", "50%"], ["transform", "translate(-50%, 0)"], ["white-space", "nowrap"] ]; ElgigantenScript.PrependElement( "mini-product", "sales-point", "product-price", "SPAR", cssArray ); }); */ // ==== Function for creating submenues on page ==== // Created by : Fredrik Frederiksen // Version : 1.2 // Update Date : 03/07-2019 // ==== ==== // buttonClass = Class assigned to the buttons used in the menu // displayAreaClass = Class that will be assigned to the areas that the menu controls // menuDisplayAreaClassArray = Array containing ElgigantenScript.MenuInitialize = function (buttonClass, displayAreaClass, menuDisplayAreaClassArray) { var mdaI; for (mdaI = 0; mdaI < menuDisplayAreaClassArray.length; mdaI++) { var bcI = 1; $('.' + menuDisplayAreaClassArray[mdaI]).each(function () { $(this).attr('name', buttonClass + bcI); $(this).addClass(displayAreaClass); $(this).find('h2').hide(); bcI++; }); }; var button = ''; if (window.location.hash) { button = window.location.hash.substr(1); $('.' + buttonClass + '[name=\'' + button + '\']').addClass('active'); } else { $('.' + buttonClass + ':first').addClass('active'); button = $('.' + buttonClass + '.active').attr('name'); } $('.' + displayAreaClass + ':not([name=\'' + button + '\'])').hide(); $('.' + displayAreaClass + '[name=\'' + button + '\']').show(); $('.' + displayAreaClass + '[name=\'' + button + '\']:has(div.empty)').hide(); $('.' + buttonClass).click(function () { var button = $(this).attr('name'); $('.' + buttonClass).removeClass('active'); $(this).addClass('active'); $('.' + displayAreaClass + ':not([name=\'' + button + '\'])').hide(); $('.' + displayAreaClass + '[name=\'' + button + '\']').show(); $('.' + displayAreaClass + '[name=\'' + button + '\']:has(div.empty)').hide(); bLazy.revalidate(); }); $('.' + buttonClass).each(function(){ $('.' + displayAreaClass + '[name=\'' + $(this).attr('name') + '\']').first().prepend(''); }); }; /* example of use $(document).ready(function(){ var classArray = ["article-banner", "el-dm-wrapper"]; ElgigantenScript.MenuInitialize("big-subsektorknap", "displayAreaSub", classArray); }); */ // ==== Function for getting json data from a googlesheet ==== // Created by : Fredrik Frederiksen // Version : 1.1 // Update Date : 04/07-2019 // ==== ==== // spreadsheetId = Id of the google sheet you wish to access // sheet must be puublished // sheet share link -> https://docs.google.com/spreadsheets/d/ /edit?usp=sharing // functionToRun = Function that will run with the json data it must recieve the data as the only parameter ElgigantenScript.GetGoogleSheetJson = function (spreadsheetId, functionToRun, sheet) { if (sheet === undefined || isNaN(sheet)) { sheet = 1; } var url = "https://spreadsheets.google.com/feeds/list/" + spreadsheetId + "/" + sheet + "/public/values?alt=json&callback=?"; $.getJSON(url, function (data) { functionToRun(data.feed.entry); }); }; /* example of use function testFunction(sheetJson){ $(sheetJson).each(function(){ console.log(this); $('#displayArea1').prepend('

'+this.gsx$linkheading.$t+'

'+this.gsx$linkdescription.$t+'

'); }); }; $(document).ready(function(){ var spreadsheetId = "1JJydou8KY6OPtc4QxlUBtWl6DDI9y3miJn3ygvrwnpM"; ElgigantenScript.GetGoogleSheetJson(spreadsheetId, testFunction); }); */ // ==== Function to transfrom $('.mini-product') ==== // Created by : Fredrik Frederiksen // Version : 1.4 // Update Date : 13/11-2019 // ==== ==== // Can change | price | salespoint | ammount of offer | imageLayer | recommendedProduct | additionalInfo | additionalText // products = An object containing all the product objects and specifications for their transformations (se example for demo) // you only need to add the fields you wish to overwrite on specific products // if you just wish to use the egab price design, run function without input // productPrice -> overwrites current price // salesPoint -> overwrites the sales point // amountOfOffers -> overwrites the ammount of offers field // imageLayer -> can be used to set the bundle-icon (the little image over the product image) // recommendedProduct -> used to set set the green recommended box / icon - set this value to true. // additionalInfo -> adds more lines to the grey additional info box. // additionalText -> adds text to the bottom of the mini product box accepts html. ElgigantenScript.TransformMiniProduct = function (products) { if(!products){products = {};}; var defaultProduct = {}; if (products && products['DEFAULT']) { defaultProduct = products['DEFAULT']; } var overRuleProduct = {}; if (products && products['OVERRULE']) { overRuleProduct = products['OVERRULE']; } $('.mini-product').each(function () { var $this = $(this), id = $this.find('.product-number.sku').text().trim(), currentProduct = products[id]; if (currentProduct || defaultProduct || overRuleProduct) { var salesPoint = $this.find('.sales-point').text(); if (currentProduct && currentProduct['salesPoint']) { salesPoint = currentProduct['salesPoint']; } else if (currentProduct && currentProduct['salesPoint'] === null) {} else if (overRuleProduct && overRuleProduct['salesPoint']) { salesPoint = overRuleProduct['salesPoint']; } else if (salesPoint === '' && defaultProduct && defaultProduct['salesPoint']) { salesPoint = defaultProduct['salesPoint']; } $this.find('.sales-point').remove(); var amountOfOffers = $this.find('.amount-of-offers').text(); if (currentProduct && currentProduct['amountOfOffers']) { amountOfOffers = currentProduct['amountOfOffers']; } else if (currentProduct && currentProduct['amountOfOffers'] === null) {} else if (overRuleProduct && overRuleProduct['amountOfOffers']) { amountOfOffers = overRuleProduct['amountOfOffers']; } else if ($.trim(amountOfOffers) == '' && defaultProduct && defaultProduct['amountOfOffers']) { amountOfOffers = defaultProduct['amountOfOffers']; } $this.find('.amount-of-offers').remove(); var productPriceSub = ''; firstLoop = true; $this.find('.product-price').children().each(function(){ if(firstLoop){ firstLoop = false; } else { productPriceSub += '
'; } productPriceSub += $(this).text(); $(this).remove(); }); productPriceSub += '
'; var productPrice = $this.find('.product-price').text(); if (currentProduct && currentProduct['productPrice']) { productPrice = currentProduct['productPrice']; } else if (currentProduct && currentProduct['productPrice'] === null) {} else if (overRuleProduct && overRuleProduct['productPrice']) { productPrice = overRuleProduct['productPrice']; } else if (productPrice === '' && defaultProduct && defaultProduct['productPrice']) { productPrice = defaultProduct['productPrice']; } $this.find('.product-price').empty().append('\n' + salesPoint + '\n
' + productPrice + '
\n
\n ' + amountOfOffers + '\n
\n'); $(this).find('.egab-save:empty').css('background-color', 'transparent'); $this.find('.product-price .amount-of-offers').append(productPriceSub); var imageLayer = $this.find('.product-image-link img.bundle-icon').length; if (currentProduct && currentProduct['imageLayer']) { imageLayer = currentProduct['imageLayer']; } else if (currentProduct && currentProduct['imageLayer'] === null) {} else if (overRuleProduct && overRuleProduct['imageLayer']) { imageLayer = overRuleProduct['imageLayer']; } else if (imageLayer === 0 && defaultProduct && defaultProduct['imageLayer']) { imageLayer = defaultProduct['imageLayer']; } if (imageLayer != 0 && imageLayer != 1) { $(this).find('.product-image-link .bundle-icon').remove(); $(this).find('.product-image-link').append(''); } if (currentProduct && currentProduct['recommendedProduct']) { $this.addClass('is-recommended'); } var additionalInfo = null; if (currentProduct && currentProduct['additionalInfo']) { additionalInfo = currentProduct['additionalInfo']; } else if (currentProduct && currentProduct['additionalInfo'] === null) {} else if (overRuleProduct && overRuleProduct['additionalInfo'] && overRuleProduct['additionalInfo'] !== null) { additionalInfo = overRuleProduct['additionalInfo'];$(this).find('.more-info .additional-info').remove(); } else if (defaultProduct && defaultProduct['additionalInfo']) { additionalInfo = defaultProduct['additionalInfo']; } if (additionalInfo !== null && additionalInfo !== '') { if ($(this).find('.more-info .additional-info').length === 0) { $(this).find('.more-info').append(''); } $(this).find('.more-info .additional-info').append('' + additionalInfo + ''); } var additionalText = ''; if (currentProduct && currentProduct['additionalText']) { additionalText = currentProduct['additionalText']; } else if (overRuleProduct && overRuleProduct['additionalText']) { additionalText = overRuleProduct['additionalText']; } else if (defaultProduct && defaultProduct['additionalText']) { additionalText = defaultProduct['additionalText']; } if (additionalText !== '') { $(this).find('.product-info-wrap').last().parent().append('\n
' + additionalText + '
\n'); } } }); }; /* example of use var products = { 'HP15CX0812NO': {'productPrice': null, 'salesPoint': 'Gul Pris! SPAR 2029238437! = 2020200%', 'imageLayer': '/content/DK/img/yellow-deals-image-layer-27062019-1dk.png', 'additionalInfo': 'you really need this product!', 'additionalText': '
test link'}, 'QE55Q6FNATXXC': {'recommendedProduct': true}, 'DEFAULT': {'additionalInfo': 'additional info goes here...', 'imageLayer': '/is/image/tubby/black-friday-2018-elgiganten-26112017DK.png'}, 'OVERRULE': {'productPrice': 'XXXX', 'salesPoint': 'Black Friday!', 'amountOfOffers': ''} //'SKU': {'productPrice': null, 'salesPoint': 'Groenne Priser!', 'amountOfOffers': '', 'imageLayer': '/content/DK/img/yellow-deals-image-layer-27062019-1dk.png'}, //'DEFAULT': {'productPrice': 'XXXX', 'imageLayer': '/is/image/tubby/black-friday-2018-elgiganten-26112017DK.png'}, //'OVERRULE': {'salesPoint': 'Black Friday!', 'amountOfOffers': ''} }; $(document).ready(function () { ElgigantenScript.TransformMiniProduct(products); }); */ // ==== Function to create top menu ==== // Created by : Fredrik Frederiksen // Version : 1.2 // Update Date : 25/11-2019 // ==== ==== // menuSettings = An object containing settings for the menu // menuClass -> class for menu // tagetLocationClass -> class where you wish item to be appended into // menuItemClass -> class for items in menu // design -> select style of the menu currently available -> // 'green' -> '/content/DK/scripts/ep-topmenu-green.css' // menuItems -> array with elements (see demo) one per button // text -> text on the button // icon -> icon for the button // link -> link for the button ElgigantenScript.CreateTopMenu = function (menuSettings) { $('.' + menuSettings['tagetLocationClass']).append('\n\n\n\n'); for (i = 0; i < menuSettings['menuItems'].length; i++) { $('.' + menuSettings['menuClass'] + ' ul').append('\n
  • \n \n
    \n
    ' + menuSettings['menuItems'][i]['text'] + '
    \n
    \n
  • \n'); } var path = window.location.pathname; if (path.charAt(path.length - 1) == "/") { path = path.substring(0, path.length - 1); } $('a.ep-tm-link[href*=\'' + path + '\']').addClass("ep-tm-active").removeAttr('href'); $('.ep-tm-mb-wrap .ep-tm-active').parent().addClass('remover'); $('.ep-tm-mb-wrap .ep-tm-active').detach().appendTo('.ep-tm-mb-wrap label'); $('.ep-tm-mb-wrap .ep-tm-item.remover').remove(); if(menuSettings['color'] !== undefined){ var cssColor = $('', { rel: 'stylesheet', type: 'text/css', href: menuSettings['color'] }); cssColor.appendTo('head'); } var cssElement = $('', { rel: 'stylesheet', type: 'text/css', href: menuSettings['design'] }); cssElement.appendTo('head'); }; /* example of use // designs available // 'green' -> '/content/DK/scripts/ep-topmenu-green.css' var menuSettings = { 'menuClass': 'customTopMenu', 'tagetLocationClass': 'elkjop.giganten-subheading', 'menuItemClass': '', 'design': '/content/DK/scripts/ep-topmenu-green.css', 'menuItems': [ {'text': 'Computer, tablet og foto', 'icon': '/content/DK/img/computing-tilbud-computing-ikon-14062019-1dk.png', 'link': '/cms/aktuelle-tilbud-pc-mac-tablet-og-computer/aktuelle-tilbud-rabat-pa-computer'}, {'text': 'Fredrik test 3', 'icon': '/content/DK/img/menu-tilbud-gaming-ikon-14062019-3dk.png', 'link': '/cms/hidpag-frederik-tester-v3/frederik-tester-v3'}, {'text': 'Fredrik test 2', 'icon': '/content/DK/img/menu-tilbud-mobil-ikon-14062019-5dk.png', 'link': '/cms/hidpag-frederik-tester-v2/frederik-tester-v2'}, {'text': 'Hvidevarer', 'icon': '/content/DK/img/tilbud-mda-ikon-14062019-2dk.png', 'link': '/cms/aktuelle-hvidevarer-tilbud/tilbud-fra-denne-uges-avis-hvidevarer'} ] }; $(document).ready(function () { ElgigantenScript.CreateTopMenu(menuSettings); }); */ // ==== Function to create sub menu ==== // Created by : Fredrik Frederiksen // Version : 1.2 // Update Date : 25/11-2019 // ==== ==== // menuSettings = An object containing settings for the menu // menuClass -> class for menu // tagetLocationClass -> class where you wish item to be appended into // menuItemClass -> class for items in menu // design -> select style of the menu currently available -> // 'green' -> '/content/DK/scripts/ep-submenu-green.css' // menuItems -> array with elements (see demo) one per button // text -> text on the button // icon -> icon for the button // link -> link for the button - only set a link if you need toredirect to other pages, and always place redirect links last // // use ElgigantenScript.MenuInitialize to activate the menu ElgigantenScript.CreateSubMenu = function (menuSettings) { $('.' + menuSettings['tagetLocationClass']).append('\n\n
    \n'); for (i = 0; i < menuSettings['menuItems'].length; i++) { var widthClass = 'ep-sm-item-' + (menuSettings['menuItems'].length > 6 ? 6 : menuSettings['menuItems'].length) + 'b'; var itemLink = menuSettings['menuItems'][i]['link']; if (!itemLink) { itemLink = '#' + menuSettings['menuItemClass'] + (i + 1); }; $('.' + menuSettings['menuClass'] + ' ul').append('\n\n'); } if(menuSettings['color'] !== undefined){ var cssColor = $('', { rel: 'stylesheet', type: 'text/css', href: menuSettings['color'] }); cssColor.appendTo('head'); } var cssElement = $('', { rel: 'stylesheet', type: 'text/css', href: menuSettings['design'] }); cssElement.appendTo('head'); }; /* example of use // designs available // 'green' -> '/content/DK/scripts/ep-submenu-green.css' var menuSettingsSub = { 'menuClass': 'customSubMenu', 'tagetLocationClass': 'elkjop.giganten-subheading', 'menuItemClass': 'customSubMenuItem', 'design': '/content/DK/scripts/ep-submenu-green.css', 'menuItems': [ {'text': 'Vaskemaskiner og tørretumblere', 'icon': '/content/DK/img/tilbud-mda-ikon-14062019-2dk.png'}, {'text': 'Opvask', 'icon': '/content/DK/img/opvask-tilbud-mda-ikon-14062019-2dk.png'}, {'text': 'Ovne, kogeplader og komfurer', 'icon': '/content/DK/img/ovn-tilbud-mda-ikon-14062019-2dk.png'}, {'text': 'Køl og frys', 'icon': '/content/DK/img/koel-tilbud-mda-ikon-14062019-2dk.png'}, {'text': 'Køkkentilbehør', 'icon': '/content/DK/img/epoq-tilbud-mda-ikon-14062019-2dk.png'}, {'text': 'Rest salg', 'icon': '/content/DK/layers/restsalg-layer-2018-2dk.png', 'link': '/cms/aktuelle-hvidevarer-tilbud/tilbud-fra-denne-uges-avis-hvidevarer'} ] }; $(document).ready(function () { ElgigantenScript.CreateSubMenu(menuSettingsSub); }); */ ElgigantenScript.CreateFullMenu = function(menuSettings) { var ep_mb_sm_is_mobile = window.matchMedia("only screen and (max-width: 760px)").matches; targetLocation = $('.'+menuSettings['tagetLocationClass']); $(targetLocation).css('position', 'relative'); if(menuSettings['topMenuItems']){ htmlAppend = ''; htmlAppend += ''; htmlAppend += '
    '; htmlAppend += '
    '; htmlAppend += ''; htmlAppend += '
    '; $(targetLocation).append(htmlAppend); path = window.location.pathname; if (path.charAt(path.length - 1) == "/") { path = path.substring(0, path.length - 1); } $('a.ep-tm-link[href*=\'' + path + '\']').removeAttr('href').addClass("ep-tm-active"); if (ep_mb_sm_is_mobile == true) { $('.ep-tm-wrapper .ep-tm-active').parent().detach().prependTo('.ep-tm-wrapper .ep-tm-list'); } } if(menuSettings['subMenuItems']){ widthClass = 'ep-sm-item-' + (menuSettings['subMenuItems'].length > 6 ? 6 : menuSettings['subMenuItems'].length) + 'b'; htmlAppend = ''; htmlAppend += '
    '; htmlAppend += '
    '; if(menuSettings['submenuHeader']) { htmlAppend += '
    '+menuSettings['submenuHeader']+'
    '; } htmlAppend += '
    '; $(targetLocation).append(htmlAppend); if (ep_mb_sm_is_mobile == true) { var position = $(window).scrollTop(); $('.ep-sm-filler').show(); $(window).scroll(function() { var scroll = $(window).scrollTop(); if (scroll > position) { ElgigantenScript.ScrollFullMenuHide(); } else { if($('.ep-sm-filler').isAboveViewport()){ ElgigantenScript.ScrollFullMenuHide(); } else{ ElgigantenScript.ScrollFullMenuShow(); } } position = scroll; }); } } if(menuSettings['color'] !== undefined){ var cssColor = $('', { rel: 'stylesheet', type: 'text/css', href: menuSettings['color'] }); cssColor.appendTo('head'); } var cssElement = $('', { rel: 'stylesheet', type: 'text/css', href: menuSettings['design'] }); cssElement.appendTo('head'); } ElgigantenScript.ScrollFullMenuShow = function() { if(!$('.ep-sm-wrapper').isInViewport()){ $('.ep-sm-filler').css('height', $('.ep-sm-wrapper').css('height')); $('.ep-sm-wrapper').css({ 'position':'fixed', 'top':'-132px', 'left': '5px', 'z-index': '201', 'background-color': '#fff', 'width':'calc(100% - 10px)', 'border-radius':'0px 0px 10px 10px', 'transition':'transform 0.8s ease' }).children('ul.ep-sm-list').css({'border-radius':'0px 0px 10px 10px', 'border-color':'#ccc'}); $('.ep-sm-wrapper').css({ 'transform': 'translateY(185px)' }); } }; ElgigantenScript.ScrollFullMenuHide = function() { $('.ep-sm-filler').css('height', '0px'); $('.ep-sm-wrapper').removeAttr('style').children('ul.ep-sm-list').removeAttr('style'); }; // ==== Function to activate the scroll up menu popin for submenu ==== // Created by : Fredrik Frederiksen // Version : 1.1 // Update Date : 09/10-2019 // ==== ==== // activate on window load and after submenu has been created. ElgigantenScript.ScrollSubMenuActivate = function(){ var ep_mb_sm_is_mobile = window.matchMedia("only screen and (max-width: 760px)").matches; if (ep_mb_sm_is_mobile == true) { var position = $(window).scrollTop(); $('.ep-sm-fs-ph').show(); $(window).scroll(function() { var scroll = $(window).scrollTop(); if (scroll > position) { ElgigantenScript.ScrollSubMenuHide(); } else { if($('.ep-sm-fs-ph').isAboveViewport()){ ElgigantenScript.ScrollSubMenuHide(); } else{ ElgigantenScript.ScrollSubMenuShow(); } } position = scroll; }); } }; /* example of use $(document).ready(function () { ElgigantenScript.CreateSubMenu(menuSettingsSub); $(window).on("load", function() { ElgigantenScript.ScrollSubMenuActivate(); }); }); */ // ==== Internal function to show the scroll up menu popin for submenu ==== // Created by : Fredrik Frederiksen // Version : 1.1 // Update Date : 09/10-2019 // ==== ==== // called internally by ElgigantenScript.ScrollSubMenuActivate ElgigantenScript.ScrollSubMenuShow = function() { if(!$('.ep-sm-fs-wrap').isInViewport()){ $('.ep-sm-fs-ph').css('height', $('.ep-sm-fs-wrap').css('height')); $('.ep-sm-fs-wrap').css({ 'position':'fixed', 'top':'-132px', 'left': '5px', 'z-index': '201', 'background-color': '#fff', 'width':'calc(100% - 10px)', 'border-radius':'0px 0px 10px 10px', 'transition':'transform 0.8s ease' }).children('ul.ep-sm-list').css({'border-radius':'0px 0px 10px 10px', 'border-color':'#ccc'}); $('.ep-sm-fs-wrap').css({ 'transform': 'translateY(185px)' }); } }; // ==== Internal function to hide the scroll up menu popin for submenu ==== // Created by : Fredrik Frederiksen // Version : 1.1 // Update Date : 09/10-2019 // ==== ==== // called internally by ElgigantenScript.ScrollSubMenuActivate ElgigantenScript.ScrollSubMenuHide = function() { $('.ep-sm-fs-ph').css('height', '0px'); $('.ep-sm-fs-wrap').removeAttr('style').children('ul.ep-sm-list').removeAttr('style'); }; // ==== Function to transform look for club prices ==== // Created by : Fredrik Frederiksen // Version : 1.0 // Update Date : 23/10-2019 // ==== ==== // run after ElgigantenScript.TransformMiniProduct() in your script ElgigantenScript.TransformClubOffers = function(wordDetection, originalPriceHeader){ $('.mini-product').each(function () { if($(this).find('.egab-save').text().includes(wordDetection)) { var ogPrice = $(this).find('.egab-price').text(); var ogSalesPoint = $(this).find('.egab-save').text(); var splitSalesPoints = ogSalesPoint.split(' '); klubHtml = ''; if(originalPriceHeader !== undefined && originalPriceHeader !== ''){ klubHtml += originalPriceHeader } klubHtml += ogPrice + ''; $(this).find('.amount-of-offers').empty().append(klubHtml); $(this).find('.egab-save').text(splitSalesPoints[0]); $(this).find('.egab-price').text(splitSalesPoints[1]); } }); }; /* example of use $(document).ready(function () { ElgigantenScript.TransformMiniProduct(); ElgigantenScript.TransformClubOffers('Klubpris ', 'normal pris
    '); }); */ // ==== Function to change imagelayer based on a search in sales point ==== // Created by : Fredrik Frederiksen // Latest Version : 1.1 // Update Date : 18/11-2019 // ==== ==== // run after ElgigantenScript.TransformMiniProduct() in your script ElgigantenScript.TransformImageLayer = function(wordDetection, imageLayerLink){ $('.mini-product').each(function () { if($(this).find('.egab-save').text().includes(wordDetection)) { $(this).find('.product-image-link .bundle-icon').remove(); $(this).find('.product-image-link').append(''); } }); }; /* example of use $(document).ready(function () { ElgigantenScript.TransformMiniProduct(); ElgigantenScript.TransformImageLayer('Black deal!', '/content/DK/layers/BF2019-300x300-BlackTag-dk.png'); }); */ // ==== Function to transform miniproduct of outlet products ==== // Created by : Fredrik Frederiksen // Latest Version : 1.4 // Update Date : 18/11-2019 // ==== ==== // may have conflicts with ElgigantenScript.TransformMiniProduct() ElgigantenScript.TransformOutlet = function(input){ var a = 0; $(input.elements).each(function () { searchTester = false; if(Array.isArray(input.searchTerm)){ for(i = 0; i < input.searchTerm.length; i++){ if($(this).is(':contains('+input.searchTerm[i]+')')){ searchTester = true; } } } else { if($(this).is(':contains('+input.searchTerm+')')){ searchTester = true; } } if(searchTester){ $(this).addClass('outlet-mini-product'); if(input.hideSalesPoint){ $(this).find('.sales-point').remove(); } $(this).find('.items-in-stock').remove(); if($(this).find('.product-price .state-of-b-items').length){ t = $(this).find('.product-price .state-of-b-items').text(); $(this).find('.product-price .state-of-b-items').remove(); p = $(this).find('.product-price').text(); $(this).find('.product-price').text(t); $(this).find('.product-price').append('
    '+p+'
    '); } else { if($(this).find('.product-price span.discontinued').length === 0){ $(this).find('.product-price') .prepend(input.prePriceText); } $(this).find('.a-item-plp-text') .css({ 'background-color': input.boxColor }); l = $(this).find('a.product-image-link').attr('href'); l = l.replace("https://www.elgiganten.dk/product/", "https://www.elgiganten.dk/outlet/"); $(this).find('a.product-image-link').attr('href', l); $(this).find('a.product-name').attr('href', l); divContent = ''; $(this).find('.product-price-button > div').each(function (){ divContent = $(this).html(); $(this).replaceWith(''); }); $(this).find('.product-price-button > a').each(function (){ $(this).attr('href', l); $(this).addClass('button el-button cta normal-btn see-more no-min-width'); $(this).html(divContent); }); } if(input.imageLayer !== undefined) { $(this).find('.outlet-icon.b-item').remove(); if($(this).find('.bundle-icon').length > 0){ $(this).find('.bundle-icon').attr('src', input.imageLayer+'?$layer_small$'); } else { $(this).find('.product-image-link').append('outlet') } } } }); }; /* example of use $(document).ready(function(){ var outletData = { elements: '.box.recommended-products .mini-product', searchTerm: ['Outlet-pris', 'Som ny - '], prePriceText: 'Nypris: ', boxColor: '#f9e300', hideSalesPoint: true, imageLayer: '/content/cnm/155860/outlet-icon-155860-500x500.png' } ElgigantenScript.TransformOutlet(outletData); }); */ // ==== Function to transform miniproduct of outlet products ==== // Created by : Fredrik Frederiksen // Latest Version : 1.0 // Update Date : 09/03-2020 // ==== ==== // may have conflicts with ElgigantenScript.TransformMiniProduct() ElgigantenScript.RemoveItemFromElements = function(input){ $(input.elements).each(function () { $(this).find(input.item).remove(); }); }; /* example of use $(document).ready(function(){ var removeData = { elements: '.mini-product', item: '.outlet-icon.b-item' }; ElgigantenScript.RemoveItemFromElements(removeData); }); */ $.fn.isInViewport = function() { var elementTop = $(this).offset().top; var elementBottom = elementTop + $(this).outerHeight(); var viewportTop = $(window).scrollTop(); var viewportBottom = viewportTop + $(window).height(); return elementBottom > viewportTop && elementTop < viewportBottom; }; $.fn.isAboveViewport = function() { var elementTop = $(this).offset().top; var elementBottom = elementTop + $(this).outerHeight(); var viewportTop = $(window).scrollTop(); return elementBottom > viewportTop; }; ElgigantenScript.AddVideoPlayer = function(targetId, source, type, userConfig = {}){ defaultConfig = { 'fluid': true, controls: true, preload: "metadata", muted: false, autoplay: false, loop: false }; if(userConfig != {}){ $.extend(defaultConfig, userConfig); if(defaultConfig.autoplay) defaultConfig.muted = defaultConfig.autoplay; } console.log(defaultConfig.autoplay); $('#'+targetId).append(''); $('#'+targetId+'_videoPlayer').addClass('video-js vjs-default-skin vjs-elgiganten'); videojs(targetId+'_videoPlayer', defaultConfig ).src([ {type: type, src: source, } ]); player = videojs(targetId+'_videoPlayer'); player.on('touchstart', function() { if (player.paused()) { player.play(); } else { player.pause(); } }); }