mirror of
https://github.com/friendica/friendica
synced 2024-12-23 20:00:16 +00:00
6 lines
2.4 KiB
JavaScript
6 lines
2.4 KiB
JavaScript
/* jQuery.flexMenu 1.3
|
|
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"==typeof define&&define.amd?define(["jquery"],e):e(jQuery)}(function(e){function i(){e(o).each(function(){e(this).flexMenu({undo:!0}).flexMenu(this.options)})}function n(i){var n,l;n=e("li.flexMenu-viewMore.active"),l=n.not(i),l.removeClass("active").find("> ul").hide()}var l,o=[];e(window).resize(function(){clearTimeout(l),l=setTimeout(function(){i()},200)}),e.fn.flexMenu=function(i){var l,t=e.extend({threshold:2,cutoff:2,linkText:"More",linkTitle:"View More",linkTextAll:"Menu",linkTitleAll:"Open/Close Menu",showOnHover:!0,popupAbsolute:!0,popupClass:"",undo:!1},i);return this.options=t,l=e.inArray(this,o),l>=0?o.splice(l,1):o.push(this),this.each(function(){function i(e){var i=Math.ceil(e.offset().top)>=v+x?!0:!1;return i}var l,o,f,u,s,r,a,p=e(this),d=p.find("> li"),c=d.first(),h=d.last(),M=p.find("li").length,v=Math.floor(c.offset().top),x=Math.floor(c.outerHeight(!0)),T=!1;if(i(h)&&M>t.threshold&&!t.undo&&p.is(":visible")){var w=e('<ul class="flexMenu-popup" style="display:none;'+(t.popupAbsolute?" position: absolute;":"")+'"></ul>');c.offset().top;for(w.addClass(t.popupClass),a=M;a>1;a--){if(l=p.find("> li:last-child"),o=i(l),l.appendTo(w),a-1<=t.cutoff){e(p.children().get().reverse()).appendTo(w),T=!0;break}if(!o)break}T?p.append('<li class="flexMenu-viewMore flexMenu-allInPopup"><a href="#" title="'+t.linkTitleAll+'">'+t.linkTextAll+"</a></li>"):p.append('<li class="flexMenu-viewMore"><a href="#" title="'+t.linkTitle+'">'+t.linkText+"</a></li>"),f=p.find("> li.flexMenu-viewMore"),i(f)&&p.find("> li:nth-last-child(2)").appendTo(w),w.children().each(function(e,i){w.prepend(i)}),f.append(w),u=p.find("> li.flexMenu-viewMore > a"),u.click(function(e){n(f),w.toggle(),f.toggleClass("active"),e.preventDefault()}),t.showOnHover&&"undefined"!=typeof Modernizr&&!Modernizr.touch&&f.hover(function(){w.show(),e(this).addClass("active")},function(){w.hide(),e(this).removeClass("active")})}else if(t.undo&&p.find("ul.flexMenu-popup")){for(r=p.find("ul.flexMenu-popup"),s=r.find("li").length,a=1;s>=a;a++)r.find("> li:first-child").appendTo(p);r.remove(),p.find("> li.flexMenu-viewMore").remove()}})}});
|