-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.togglemenu.min.js
9 lines (9 loc) · 2.26 KB
/
jquery.togglemenu.min.js
1
2
3
4
5
6
7
8
9
/*
* jquery.togglemenu.js 1.0
*
* Copyright 2017, Gevorg Mkrtchyan
* Released under the GPL v3 License
*
* Date: Mart 29, 2017
*/
(function(b,a){b.fn.togglemenu=b.fn.toggleMenu=function(c){var e=b.extend({breakpoint:960,title:"Меню",selector:"ul.menu",burger:'<i class="toggle-menu-burger"></i>',burgerStyles:{},jsHide:true,appendItems:false,appendBlock:{},burgerParent:false},c);var d={};d.hide=function(f){if(e.jsHide){f.hide()}else{f.addClass("toggle-menu-hide")}};d.show=function(f){if(e.jsHide){f.show()}else{f.removeClass("toggle-menu-hide")}};d.check=function(h,g){var f=e.breakpoint;if(g<f){e.body.addClass("toggle-menu-is-mobile");e.body.removeClass("toggle-menu-is-desktop");d.hide(h);d.show(e.burgerObject)}else{e.body.removeClass("toggle-menu-is-mobile");e.body.addClass("toggle-menu-is-desktop");d.show(h);d.hide(e.burgerObject)}};d.append=function(f,g){if(typeof g==="string"){f.append(g)}else{if(typeof g==="object"){b.each(g,function(j,h){f.append(h)})}}};return this.each(function(){var j=b(this);e.body=b("body");e.body.addClass("toggle-menu-inited");var g=b(e.selector,j).clone();if(e.appendItems){d.append(g,e.appendItems)}e.burgerObject=b(e.burger);if(!b.isEmptyObject(e.burgerStyles)){e.burgerObject.css(e.burgerStyles)}d.hide(e.burgerObject);if(!e.burgerParent){j.after(e.burgerObject)}else{e.burgerObject.appendTo(b(e.burgerParent))}j.addClass("toggle-menu-wrap");var i=b("<div />").addClass("toggle-menu-mobile");var f=b('<div id="toggle-menu-content"></div>');i.append('<div class="toggle-menu-title">'+e.title+"</div>");var h=b('<a href="#close-menu" class="toggle-menu-close"><span>Закрыть</span></a>');f.append(g);if(!b.isEmptyObject(e.appendBlock)){f.append(e.appendBlock)}i.append(h).append(f);i.addClass("toggle-menu-mobile").addClass("toggle-menu-mobile-hide").appendTo(e.body);e.body.removeClass("toggle-menu-opened");var k=b(a);k.resize(function(){var l=k.width();d.check(j,k.width());i.addClass("toggle-menu-mobile-hide");e.body.removeClass("toggle-menu-opened")}).resize();e.burgerObject.on("click",function(l){l.preventDefault();i.toggleClass("toggle-menu-mobile-hide");e.body.toggleClass("toggle-menu-opened")});h.on("click",function(l){l.preventDefault();i.addClass("toggle-menu-mobile-hide");e.body.removeClass("toggle-menu-opened")})})}})(jQuery,window);