-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathjquery-listnav.min.js
3 lines (3 loc) · 4.07 KB
/
jquery-listnav.min.js
1
2
3
/*! jQuery ListNav - v2.4.10 - 2015-09
Copyright Eric Steinborn - https://github.com/esteinborn/jquery-listnav */
!function(a){a.fn.listnav=function(b){var c=a.extend({},a.fn.listnav.defaults,b),d=["_","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","-"],e=!1,f="";return f=null!==document.ontouchstart?"click":"touchend click",c.prefixes=a.map(c.prefixes,function(a){return a.toLowerCase()}),this.each(function(){function b(){if(o.append(n()),p=a(".ln-letters",o).slice(0,1),c.showCounts&&(q=a(".ln-letter-count",o).slice(0,1)),h(),k(),m(),c.flagDisabled&&j(),c.includeAll||a(".all",p).remove(),c.includeNums||a("._",p).remove(),c.includeOther||a(".-",p).remove(),c.removeDisabled&&a(".ln-disabled",p).remove(),a(":last",p).addClass("ln-last"),a.cookie&&null!==c.cookieName){var b=a.cookie(c.cookieName);null!==b&&"undefined"!=typeof b&&(c.initLetter=b)}if(""!==c.initLetter)e=!0,a("."+c.initLetter.toLowerCase(),p).slice(0,1).trigger(f);else if(c.includeAll)a(".all",p).addClass("ln-selected");else for(var g=c.includeNums?0:1;g<d.length;g++)if(w[d[g]]>0){e=!0,a("."+d[g],p).slice(0,1).trigger(f);break}}function g(){var b=q.outerHeight();q.css({top:a("a:first",o).slice(0,1).position().top-b})}function h(){var b,d,e="",f=c.prefixes.length>0,g=c.filterSelector.length>0;a(v).children().each(function(){if(d=a(this),b=g?a.trim(d.find(c.filterSelector).text()).toLowerCase():a.trim(d.text()).toLowerCase(),""!==b){if(f){var h=a.map(c.prefixes,function(a){return a.indexOf(" ")<=0?a+" ":a}),j=a.grep(h,function(a){return 0===b.indexOf(a)});if(j.length>0){var k=b.toLowerCase().split(j[0])[1];return e=null!==k?a.trim(k).charAt(0):b.charAt(0),void i(e,d,!0)}}e=b.charAt(0),i(e,d)}})}function i(a,b,c){/\W/.test(a)&&(a="-"),isNaN(a)||(a="_"),b.addClass("ln-"+a),void 0===w[a]&&(w[a]=0),w[a]++,c||x++}function j(){for(var b=0;b<d.length;b++)void 0===w[d[b]]&&a("."+d[b],p).addClass("ln-disabled")}function k(){v.append('<li class="ln-no-match listNavHide">'+c.noMatchText+"</li>")}function l(b){return a(b).hasClass("all")?y=c.dontCount?x-v.find(c.dontCount).length:x:(b=".ln-"+a(b).attr("class").split(" ")[0],t=c.dontCount?v.find(b).not(c.dontCount).length:v.find(b).length,void 0!==t?t:0)}function m(){c.showCounts&&(o.mouseover(function(){g()}),a(".ln-letters a",o).mouseover(function(){r=a(this).position().left,s=a(this).outerWidth()+"px",t=l(this),q.css({left:r,width:s}).text(t).addClass("letterCountShow").removeClass("listNavHide")}).mouseout(function(){q.addClass("listNavHide").removeClass("letterCountShow")})),a("a",p).bind(f,function(b){b.preventDefault();var d=a(this),f=d.attr("class").split(" ")[0],g=v.children(".ln-no-match");if(A!==f){if(a("a.ln-selected",p).removeClass("ln-selected"),"all"===f)v.children().addClass("listNavShow").removeClass("listNavHide"),g.addClass("listNavHide").removeClass("listNavShow"),z=!0;else{z?(v.children().addClass("listNavHide").removeClass("listNavShow"),z=!1):""!==A&&v.children(".ln-"+A).addClass("listNavHide").removeClass("listNavShow");var h=l(this);h>0?(v.children(".ln-"+f).addClass("listNavShow").removeClass("listNavHide"),g.addClass("listNavHide").removeClass("listNavShow")):g.addClass("listNavShow").removeClass("listNavHide")}A=f,a.cookie&&null!==c.cookieName&&a.cookie(c.cookieName,f,{expires:999}),d.addClass("ln-selected"),d.blur(),e||null===c.onClick?e=!1:c.onClick(f)}})}function n(){for(var a=[],b=1;b<d.length;b++)0===a.length&&a.push('<a class="all" href="#">'+c.allText+'</a><a class="_" href="#">0-9</a>'),a.push('<a class="'+d[b]+'" href="#">'+("-"===d[b]?"...":d[b].toUpperCase())+"</a>");return'<div class="ln-letters">'+a.join("")+"</div>"+(c.showCounts?'<div class="ln-letter-count listNavHide">0</div>':"")}var o,p,q,r,s,t,u=this.id,v=a(this),w={},x=0,y=0,z=!0,A="";a("#"+u+"-nav").length||a('<div id="'+u+'-nav" class="listNav"/>').insertBefore(v),o=a("#"+u+"-nav"),b()})},a.fn.listnav.defaults={initLetter:"",includeAll:!0,allText:"All",includeOther:!1,includeNums:!0,flagDisabled:!0,removeDisabled:!1,noMatchText:"No matching entries",showCounts:!0,dontCount:"",cookieName:null,onClick:null,prefixes:[],filterSelector:""}}(jQuery);