This repository has been archived by the owner on Oct 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
/
jquery-listnav.min.js
4 lines (3 loc) · 4.47 KB
/
jquery-listnav.min.js
1
2
3
4
/*! jQuery ListNav - v3.1.0 - 04/26/2021
Copyright Eric Steinborn - https://github.com/esteinborn/jquery-listnav */
!function(e){e.fn.listnav=function(t){var l=e.extend({},e.fn.listnav.defaults,t),i=!1,s="";return s=null!==document.ontouchstart?"click":"touchend click",l.prefixes=e.map(l.prefixes,function(e){return e.toLowerCase()}),this.each(function(){function t(){var t=C.outerHeight();C.css({top:e("a:first",h).slice(0,1).position().top-t})}function n(){var t,i,s="",n=l.prefixes.length>0,o=l.filterSelector.length>0;e(w).children().each(function(){if(i=e(this),""!==(t=o?e.trim(i.find(l.filterSelector).text()).toLowerCase():e.trim(i.text()).toLowerCase())){if(n){var r=e.map(l.prefixes,function(e){return e.indexOf(" ")<=0?e+" ":e}),d=e.grep(r,function(e){return 0===t.indexOf(e)});if(d.length>0){var c=t.toLowerCase().split(d[0])[1];return s=null!==c?e.trim(c).charAt(0):t.charAt(0),void a(s,i,!0)}}a(s=t.charAt(0),i)}})}function a(e,t,l){/\wW/.test(e)&&(e="-"),isNaN(e)||(e="_"),t.addClass("ln-"+e),void 0===x[e]&&(x[e]=0),x[e]++,l||H++}function o(){for(var t=0;t<l.letters.length;t++)void 0===x[l.letters[t]]&&e("."+l.letters[t],f).addClass("ln-disabled")}function r(){w.append('<li class="ln-no-match listNavHide">'+l.noMatchText+"</li>")}function d(){w.append('<li class="ln-init-hidden listNavHide">'+l.initHiddenText+"</li>")}function c(t){return e(t).hasClass("all")?k=l.dontCount?H-w.find(l.dontCount).length:H:(t=".ln-"+e(t).attr("class").split(" ")[0],void 0!==(p=l.dontCount?w.find(t).not(l.dontCount).length:w.find(t).length)?p:0)}function u(){l.showCounts&&(h.mouseover(function(){t()}),e(".ln-letters a",h).mouseover(function(){m=e(this).position().left,N=e(this).outerWidth()+"px",p=c(this),C.css({left:m,width:N}).text(p).addClass("letterCountShow").removeClass("listNavHide")}).mouseout(function(){C.addClass("listNavHide").removeClass("letterCountShow")})),e("a",f).on(s,function(t){t.preventDefault();var s=e(this),n=s.attr("class").split(" ")[0],a=w.children(".ln-no-match");l.initHidden&&w.children(".ln-init-hidden").remove(),b!==n&&(e("a.ln-selected",f).removeClass("ln-selected"),"all"===n?(w.children().addClass("listNavShow").removeClass("listNavHide"),a.addClass("listNavHide").removeClass("listNavShow"),S=!0):(S?(w.children().addClass("listNavHide").removeClass("listNavShow"),S=!1):""!==b&&w.children(".ln-"+b).addClass("listNavHide").removeClass("listNavShow"),c(this)>0?(w.children(".ln-"+n).addClass("listNavShow").removeClass("listNavHide"),a.addClass("listNavHide").removeClass("listNavShow")):a.addClass("listNavShow").removeClass("listNavHide")),b=n,e.cookie&&null!==l.cookieName&&e.cookie(l.cookieName,n,{expires:999}),s.addClass("ln-selected"),s.blur(),i||null===l.onClick?i=!1:l.onClick(n))})}function v(){for(var e=[],t=1;t<l.letters.length;t++)0===e.length&&e.push('<a class="all" href="#">'+l.allText+'</a><a class="_" href="#">0-9</a>'),e.push('<a class="'+l.letters[t]+'" href="#">'+("-"===l.letters[t]?"...":l.letters[t].toUpperCase())+"</a>");return'<div class="ln-letters">'+e.join("")+"</div>"+(l.showCounts?'<div class="ln-letter-count listNavHide">0</div>':"")}var h,f,C,m,N,p,g=this.id,w=e(this),x={},H=0,k=0,S=!0,b="";e("#"+g+"-nav").length||e('<div id="'+g+'-nav" class="listNav"/>').insertBefore(w),h=e("#"+g+"-nav"),function(){if(h.append(v()),f=e(".ln-letters",h).slice(0,1),l.showCounts&&(C=e(".ln-letter-count",h).slice(0,1)),n(),r(),u(),l.flagDisabled&&o(),l.includeAll||e(".all",f).remove(),l.includeNums||e("._",f).remove(),l.includeOther||e(".-",f).remove(),l.removeDisabled&&e(".ln-disabled",f).remove(),e(":last",f).addClass("ln-last"),e.cookie&&null!==l.cookieName){var t=e.cookie(l.cookieName);null!==t&&void 0!==t&&(l.initLetter=t)}if(""!==l.initLetter)i=!0,e("."+l.initLetter.toLowerCase(),f).slice(0,1).trigger("click");else if(l.initHidden)d(),w.children().addClass("listNavHide"),w.children(".ln-init-hidden").removeClass("listNavHide");else if(l.includeAll)e(".all",f).addClass("ln-selected");else for(var s=l.includeNums?0:1;s<l.letters.length;s++)if(x[l.letters[s]]>0){i=!0,e("."+l.letters[s],f).slice(0,1).trigger("click");break}}()})},e.fn.listnav.defaults={allText:"All",cookieName:null,dontCount:"",filterSelector:"",flagDisabled:!0,includeAll:!0,includeNums:!0,includeOther:!1,initHidden:!1,initHiddenText:"Tap a letter above to view matching items",initLetter:"",letters:["_","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","-"],noMatchText:"No matching entries",onClick:null,prefixes:[],removeDisabled:!1,showCounts:!0}}(jQuery);