Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
Add exclude option from count
Browse files Browse the repository at this point in the history
  • Loading branch information
esteinborn committed Oct 7, 2014
1 parent 97a748d commit 38c3fdc
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 23 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<pre><code>&lt;ul id="myList"&gt;...&lt;/ul&gt;</code></pre>

#### Insert before &lt;/body&gt;:
<pre><code>&lt;script src="jquery-listnav-2.4.min.js"&gt;&lt;/script>
<pre><code>&lt;script src="jquery-listnav.min.js"&gt;&lt;/script>
&lt;script&gt;
$("#myList").listnav();
&lt;/script&gt;</code></pre>
Expand All @@ -31,6 +31,7 @@
removeDisabled: false, // Remove those 'ln-disabled' nav items (flagDisabled must be set to true for this to function)
noMatchText: 'No matching entries', // set custom text for nav items with no content to show
showCounts: true, // Show the number of list items that match that letter above the mouse
dontCount: '' // A comma separated list of selectors you want to exclude from the count function (numbers on top of navigation)
cookieName: null, // Set this to a string to remember the last clicked navigation item requires jQuery Cookie Plugin ('myCookieName')
onClick: null, // Set a function that fires when you click a nav item. see Demo 5
prefixes: [], // Set an array of prefixes that should be counted for the prefix and the first word after the prefix ex: ['the', 'a', 'my']
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery-listnav",
"version": "2.4.5",
"version": "2.4.6",
"dependencies": {
"jquery": ">=1.3.2"
},
Expand Down
23 changes: 15 additions & 8 deletions demo/js/jquery-listnav.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* Version 2.4.3 (02/11/14)
* Version 2.4.6 (10/07/14)
* Author: Eric Steinborn
* Compatibility: jQuery 1.3.x through 1.11.0 and jQuery 2
* Browser Compatibility: IE6+, FF, Chrome & Safari
Expand All @@ -23,7 +23,7 @@
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', '-'],
firstClick = false,
//detect if you are on a touch device easily.
clickEventType=((document.ontouchstart!==null)?'click':'touchstart');
clickEventType=((document.ontouchstart!==null)?'click':'touchend');

opts.prefixes = $.map(opts.prefixes, function (n) {

Expand All @@ -33,7 +33,7 @@

return this.each(function () {

var $wrapper, $letters, $letterCount,
var $wrapper, $letters, $letterCount, left, width, count,
id = this.id,
$list = $(this),
counts = {},
Expand Down Expand Up @@ -276,7 +276,13 @@
if ($(el).hasClass('all')) {
return allCount;
} else {
var count = counts[$(el).attr('class').split(' ')[0]];
el = '.ln-' + $(el).attr('class');

if (opts.dontCount) {
count = $list.find(el).not(opts.dontCount).length;
} else {
count = $list.find(el).length;
}
return (count !== undefined) ? count : 0; // some letters may not have a count in the hash
}
}
Expand All @@ -292,9 +298,9 @@
//shows the count above the letter
//
$('.ln-letters a', $wrapper).mouseover(function () {
var left = $(this).position().left,
width = ($(this).outerWidth()) + 'px',
count = getLetterCount(this);
left = $(this).position().left;
width = ($(this).outerWidth()) + 'px';
count = getLetterCount(this);

$letterCount.css({
left: left,
Expand Down Expand Up @@ -412,9 +418,10 @@
removeDisabled: false,
noMatchText: 'No matching entries',
showCounts: true,
dontCount: '',
cookieName: null,
onClick: null,
prefixes: [],
filterSelector: ''
};
})(jQuery);
})(jQuery);
2 changes: 1 addition & 1 deletion gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module.exports = function(grunt) {
interrupt: true
},
files: [
'listnav.js'
'jquery-listnav.js'
],
tasks: [
'jshint',
Expand Down
23 changes: 15 additions & 8 deletions jquery-listnav.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* Version 2.4.3 (02/11/14)
* Version 2.4.6 (10/07/14)
* Author: Eric Steinborn
* Compatibility: jQuery 1.3.x through 1.11.0 and jQuery 2
* Browser Compatibility: IE6+, FF, Chrome & Safari
Expand All @@ -23,7 +23,7 @@
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', '-'],
firstClick = false,
//detect if you are on a touch device easily.
clickEventType=((document.ontouchstart!==null)?'click':'touchstart');
clickEventType=((document.ontouchstart!==null)?'click':'touchend');

opts.prefixes = $.map(opts.prefixes, function (n) {

Expand All @@ -33,7 +33,7 @@

return this.each(function () {

var $wrapper, $letters, $letterCount,
var $wrapper, $letters, $letterCount, left, width, count,
id = this.id,
$list = $(this),
counts = {},
Expand Down Expand Up @@ -276,7 +276,13 @@
if ($(el).hasClass('all')) {
return allCount;
} else {
var count = counts[$(el).attr('class').split(' ')[0]];
el = '.ln-' + $(el).attr('class');

if (opts.dontCount) {
count = $list.find(el).not(opts.dontCount).length;
} else {
count = $list.find(el).length;
}
return (count !== undefined) ? count : 0; // some letters may not have a count in the hash
}
}
Expand All @@ -292,9 +298,9 @@
//shows the count above the letter
//
$('.ln-letters a', $wrapper).mouseover(function () {
var left = $(this).position().left,
width = ($(this).outerWidth()) + 'px',
count = getLetterCount(this);
left = $(this).position().left;
width = ($(this).outerWidth()) + 'px';
count = getLetterCount(this);

$letterCount.css({
left: left,
Expand Down Expand Up @@ -412,9 +418,10 @@
removeDisabled: false,
noMatchText: 'No matching entries',
showCounts: true,
dontCount: '',
cookieName: null,
onClick: null,
prefixes: [],
filterSelector: ''
};
})(jQuery);
})(jQuery);
4 changes: 2 additions & 2 deletions jquery-listnav.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion listnav.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"navigation",
"filter"
],
"version": "2.4.5",
"version": "2.4.6",
"author": {
"name": "Eric Steinborn",
"email": "esteinborn@gmail.com"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jquery-listnav",
"title": "jQuery ListNav",
"version": "2.4.5",
"version": "2.4.6",
"author": "Eric Steinborn",
"description": "Add a slick \"letter-based\" navigation bar to all of your lists. Click a letter to quicky filter the list to items that match that letter. Updated for better compatibility with future jQuery versions.",
"demo": "http://esteinborn.github.io/jquery-listnav",
Expand Down

0 comments on commit 38c3fdc

Please sign in to comment.