I'm trying to add a JavaScript in Drupal for a mobile navigation for the Zen 7.x-5.x theme. The JavaScript I'm trying to add can be found on http://codepen.io/micahgodbolt/pen/czwer
I understand that I need to use the JavaScript like described here: https://stackoverflow.com/a/14526812
But being new to JavaScript I can't get it to work. My latest try gives "undefined is not a function" on row 18 in the following (where the adjustMenu variable is declared):
(function($) {
Drupal.behaviors.mybehavior = {
attach: function () {
var ww = $(window).width();
$(document).ready(function() {
$(".nav li a").each(function() {
if ($(this).next().length > 0) {
$(this).addClass("parent");
};
})
$(".toggleMenu").click(function(e) {
e.preventDefault();
$(this).toggleClass("active");
$(".nav").toggle();
});
adjustMenu();
})
$(window).bind('resize orientationchange', function() {
ww = $(window).width();
adjustMenu();
});
var adjustMenu = function() {
if (ww < 768) {
// if "more" link not in DOM, add it
if (!$(".more")[0]) {
$('<div class="more"> </div>').insertBefore($('.parent'));
}
$(".toggleMenu").css("display", "inline-block");
if (!$(".toggleMenu").hasClass("active")) {
$(".nav").hide();
} else {
$(".nav").show();
}
$(".nav li").unbind('mouseenter mouseleave');
$(".nav li a.parent").unbind('click');
$(".nav li .more").unbind('click').bind('click', function() {
$(this).parent("li").toggleClass("hover");
});
}
else if (ww >= 768) {
// remove .more link in desktop view
$('.more').remove();
$(".toggleMenu").css("display", "none");
$(".nav").show();
$(".nav li").removeClass("hover");
$(".nav li a").unbind('click');
$(".nav li").unbind('mouseenter mouseleave').bind('mouseenter mouseleave', function() {
// must be attached to li so that mouseleave is not triggered when hover over submenu
$(this).toggleClass('hover');
});
}
}
}
};
})(jQuery);
I would really appreciate any help, as there is no mobile navigation in the Zen 7.x-5.x theme by default, and adding a JavaScript that is not written for Drupal is not very easy.