require(['domReady', 'jquery'], function (domReady, $) {
    domReady(function () {
        // -------------------
        // NEW SIDE MENU CODE
        // -------------------

        $('.page-nav-toggle').on('click', function() {
            if ($(this).hasClass('categories-toggle')) {
                $('.page_content').toggleClass('open-categories-menu').removeClass('open-options-menu');
            } else {
                $('.page_content').toggleClass('open-options-menu').removeClass('open-categories-menu');
            }
        });

        //close side menus when clicking outside
        $('html').on('click', function(e) {
            if($('.page_content').hasClass('open-categories-menu')
                && !$(e.target).closest('.page-nav-toggle').length
                && !$(e.target).closest('.js-info-panel').length){
                $('.page_content').toggleClass('open-categories-menu')
            };
            if($('.page_content').hasClass('open-options-menu')
                && !$(e.target).closest('.page-nav-toggle').length
                && !$(e.target).closest('.js-side-panel').length){
                $('.page_content').toggleClass('open-options-menu')
            };
        });

        // -------------------
        // DROPDOWN MENU CODE
        // -------------------
        $('.btn-toggle').on('click', function() {
            $(this).parents('.btn-group-collapsable').toggleClass('open');
        });
        $(window).click(function() {
            $('.btn-group-collapsable').removeClass('open');
        });
        $('.btn-group-collapsable').click(function(event){
            event.stopPropagation();
        });
    })
});
