1"use strict"; 2 3(function($) { 4 5$.fn.megadropdown = function(options, callback) { 6 7 var settings = $.extend({ 8 retrieveHeaderMegaDropdownURL: '', 9 showOnlineShopMegaDropdown: true 10 }, options); 11 12 function getResponse(url) { 13 $.ajax({ 14 type: 'GET', 15 url: url, 16 xhrFields: { 17 withCredentials: true 18 }, 19 dataType: 'json', 20 contentType: 'application/json', 21 success: function (data) { 22 createDropdownMenu(data); 23 if (jQuery.isFunction(callback)) { 24 25 callback(); 26 } 27 }, 28 error: function(XMLHttpRequest, textStatus, errorThrow) { 29 console.log(errorThrow); 30 } 31 }); 32}; 33 34function createDropdownMenu(data) { 35 if (data.categoryEntries.length > 0) { 36 var columns = 4; 37 var guiItems = createCategorySections(data, columns); 38 $(".row.shop").append(guiItems); 39 } else { 40 hideOnlineShopSubMenu(); 41 } 42}; 43 44 function createCategorySections(data, columns) { 45 var categoryAmount = calculateCategoryAmount(data); 46 var itemsCount = 1; 47 var columnCount = 1; 48 var guiItems = ''; 49 var itemsPerColumn = 0; 50 51 $.each(data.categoryEntries, function(index, value) { 52 if (itemsCount == 1) { 53 guiItems += '<div class="col-md-6 col-lg-3"><ul class="nav flex-column">'; 54 var remainingCategories = categoryAmount - (index); 55 itemsPerColumn = calculateItemPerColumn(remainingCategories, columns, columnCount); 56 } 57 58 guiItems += createListItem(value); 59 60 if (itemsCount == itemsPerColumn || categoryAmount-1 == index) { 61 guiItems += '</ul></div>'; 62 itemsCount = 1; 63 columnCount++; 64 } 65 else { itemsCount++; } 66 }) 67 return guiItems; 68}; 69 70 function createListItem(category) { 71 return '<li><a class="icon" href="' + category.link 72 + '"><i class="icon-' 73 + category.iconClass 74 + '"></i>' + category.name 75 + '</a></li>'; 76}; 77 78 function calculateCategoryAmount(data) { 79 var categoryAmount = 0; 80 for (var property in data.categoryEntries) { 81 if (data.categoryEntries.hasOwnProperty(property)) { 82 categoryAmount++; 83 } 84 } 85 return categoryAmount; 86}; 87 88 function calculateItemPerColumn(remainingCategories, amountColumns, currentColumn) { 89 var remainingColumns = amountColumns-currentColumn+1; 90 var itemAmount = Math.ceil(remainingCategories / remainingColumns); 91 return itemAmount; 92}; 93 94 function hideOnlineShopSubMenu() { 95 $("#nav_shop").parent().removeClass("navItem"); 96 var $navArrow = $("#nav_shop").next(); 97 var $navContent = $navArrow.next(); 98 $navArrow.remove(); 99 $navContent.remove(); 100 101 }; 102 103 if (settings.showOnlineShopMegaDropdown) { 104 getResponse(settings.retrieveHeaderMegaDropdownURL); 105 } else { 106 hideOnlineShopSubMenu(); 107 callback(); 108 } 109 110}; 111 112 }(jQuery));
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.