forked from 352Media/flexMenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflexmenu.min.js
6 lines (5 loc) · 2.32 KB
/
flexmenu.min.js
1
2
3
4
5
6
/* jQuery.flexMenu 1.1.1
https://github.com/352Media/flexMenu
Description: If a list is too long for all items to fit on one line, display a popup menu instead.
Dependencies: jQuery, Modernizr (optional). Without Modernizr, the menu can only be shown on click (not hover). */
(function(e){function r(){e(t).each(function(){e(this).flexMenu({undo:true}).flexMenu(this.options)})}function i(t){var n,r;n=e("li.flexMenu-viewMore.active");r=n.not(t);r.removeClass("active").find("> ul").hide()}var t=[],n;e(window).resize(function(){clearTimeout(n);n=setTimeout(function(){r()},200)});e.fn.flexMenu=function(n){var r,s=e.extend({threshold:2,cutoff:2,linkText:"More",linkTitle:"View More",linkTextAll:"Menu",linkTitleAll:"Open/Close Menu",showOnHover:true,popupAbsolute:true,undo:false},n);this.options=s;r=e.inArray(this,t);if(r>=0){t.splice(r,1)}else{t.push(this)}return this.each(function(){function b(e){var t=Math.ceil(e.offset().top)>=f+l?true:false;return t}var t=e(this),n=t.find("> li"),r=t,o=n.first(),u=n.last(),a=t.find("li").length,f=Math.floor(o.offset().top),l=Math.floor(o.outerHeight(true)),c,h,p,d,v,m=false,g,y;if(b(u)&&a>s.threshold&&!s.undo&&t.is(":visible")){var w=e('<ul class="flexMenu-popup" style="display:none;'+(s.popupAbsolute?" position: absolute;":"")+'"></ul>'),E=o.offset().top;for(y=a;y>1;y--){c=t.find("> li:last-child");h=b(c);c.appendTo(w);if(y-1<=s.cutoff){e(t.children().get().reverse()).appendTo(w);m=true;break}if(!h){break}}if(m){t.append('<li class="flexMenu-viewMore flexMenu-allInPopup"><a href="#" title="'+s.linkTitleAll+'">'+s.linkTextAll+"</a></li>")}else{t.append('<li class="flexMenu-viewMore"><a href="#" title="'+s.linkTitle+'">'+s.linkText+"</a></li>")}p=t.find("> li.flexMenu-viewMore");if(b(p)){t.find("> li:nth-last-child(2)").appendTo(w)}w.children().each(function(e,t){w.prepend(t)});p.append(w);d=t.find("> li.flexMenu-viewMore > a");d.click(function(e){i(p);w.toggle();p.toggleClass("active");e.preventDefault()});if(s.showOnHover&&typeof Modernizr!=="undefined"&&!Modernizr.touch){p.hover(function(){w.show();e(this).addClass("active")},function(){w.hide();e(this).removeClass("active")})}}else if(s.undo&&t.find("ul.flexMenu-popup")){g=t.find("ul.flexMenu-popup");v=g.find("li").length;for(y=1;y<=v;y++){g.find("> li:first-child").appendTo(t)}g.remove();t.find("> li.flexMenu-viewMore").remove()}})}})(jQuery)