-
Notifications
You must be signed in to change notification settings - Fork 6
/
priority-navigation.min.js
executable file
·1 lines (1 loc) · 2 KB
/
priority-navigation.min.js
1
!function(t){t.fn.prioritize=function(e){function i(i,d){var n=0;if(t(i).children().not(".demoted").outerWidth(function(t,e){n+=e}),t(i).css("display").indexOf("table")>-1)var s=t(i).parent().outerWidth();else var s=t(i).outerWidth();n>s&&(t('li[data-priority="more"]',i).length||t(i).append('<li data-priority="more"><a href="#">'+o.more+'</a></li><li data-priority="less"><a href="#">'+o.less+"</a></li>"),a(i,e,d),r(i))}function r(e,r){t('li[data-priority="more"] a',e).on("click",function(e){e.preventDefault(),t(this).parents("ul").addClass("opened")}),t('li[data-priority="less"] a',e).on("click",function(a){a.preventDefault(),t(this).parents("ul").removeClass("truncated opened"),t('li[data-priority="more"], li[data-priority="less"]',e).remove(),t('li:not([data-priority="0"])',e).removeClass("demoted"),i(e,r)})}function a(e){t(e).children(':not(.demoted):not([data-priority="more"]):not([data-priority="less"])').length<2?t('[data-priority="more"]',e).addClass("menu").children().text(o.menu):t('[data-priority="more"]',e).removeClass("menu"),t(e).addClass("truncated");var r=0;t("*:not(.demoted)",e).each(function(){t.isNumeric(t(this).data("priority"))&&parseInt(t(this).data("priority"),10)>r&&(r=parseInt(t(this).data("priority"),10),console.log("highest: "+r))}),t('[data-priority="'+r+'"]',e).addClass("demoted"),i(e)}t.fn.prioritize.defaults={more:"More…",less:"Less…",menu:"Menu"};var o=t.extend({},t.fn.prioritize.defaults,e);return this.each(function(){var e=this;t(e).addClass("prioritized"),t('li[data-priority="0"]',e).addClass("demoted");t(e).children(':not(.demoted):not([data-priority="more"]):not([data-priority="less"]):not([data-priority="0"])').length;i(e),t(window).resize(function(){var r=t(e).children(':not([data-priority="more"]):not([data-priority="less"]):not([data-priority="0"])').length;t(e).hasClass("opened")||(t(e).removeClass("truncated"),t('li[data-priority="more"], li[data-priority="less"]',e).remove(),t('li:not([data-priority="0"])',e).removeClass("demoted"),i(e,r))})})}}(jQuery);