jQuery(function($){ /* Function cleanAttributes * This is a custom basic jQuery plugin that strips ID, class and style * attributes from jQuery object. * */ $.fn.cleanAttributes = function() { this.removeAttr("id").removeAttr("class").removeAttr("style"); return this; } /* Function buildResponsiveNav * This is where all magic happen, when you need to convert your navigation * to a dropdown menu with toggle button on small screens. * */ function buildResponsiveNav() { // Prepare new placeholder for responsive navigation. var $responsiveNav = $('
'); // Get the current navigation block. var $nav = $("#navigation > ul"); // And clone it, so the original will stay unchanged. var $clone = $nav.clone(); // Now, in cloned object, find all child tags and clean default attributes. // The list of child tags is hardcoded, based on manually inspected values. $clone.find("ul, li, a, div, span").cleanAttributes(); // Find all div tags, because they are sub-menu holders. var $nestedNav = $clone.find("div"); // Get their content appended to parent element, then remove them. $nestedNav.each(function() { var $this = $(this); $this.parent().append($this.html()); $this.remove(); }); // Now, our clone object is clean and with valid syntax, // so we can add it to responsive navigation. $responsiveNav.find("ul").append($clone.html()); // Add newly created responsive navigation to the top of page. $("body").find("#custom-responsive-nav").remove(); $("body").prepend($responsiveNav); // Finally, assign a click event to open dropdown when clicking on button. $("#custom-responsive-nav > button").click(function(){ $("#custom-responsive-nav > ul").slideToggle(500); $("#custom-responsive-nav > ul").toggleClass("show"); }); // Remove unwanted arrows. $("#custom-responsive-nav > ul").find("span").each(function(){ if ($(this).text() === ">") { $(this).remove(); } }); } /* DOCUMENT.READY -------------------------------------------------- */ $(function() { // Turn on your responsive navigation! buildResponsiveNav(); // CART HACK var checkCartCounter = 0; var checkCartCounterLimit = 10; // How many times to check if cart is set? var checkCartCounterInterval = 1000; // Interval = 1 second // Start checking if cart exists var checkCart = setInterval(function(){ var url = $('.wsite-mini-cart > div.wsite-cart-bottom a').attr('href'); if (typeof url !== 'undefined') { clearInterval(checkCart); var cart = '
  • Cart
  • '; $("#custom-responsive-nav > ul").append(cart); } else if (checkCartCounter > checkCartCounterLimit) { clearInterval(checkCart); } else { checkCartCounter++; } }, checkCartCounterInterval); });/* DOCUMENT.READY */ });