MediaWiki:ListNav.js: Unterschied zwischen den Versionen

Aus Stadtsprachen
Wechseln zu:Navigation, Suche
Die Seite wurde neu angelegt: „! 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()…“
 
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
/*! 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);
* jQuery listnav plugin
* Copyright (c) 2009 iHwy, Inc.
* Author: Jack Killpatrick
*
* Version 2.1 (08/09/2009)
* Requires jQuery 1.3.2, jquery 1.2.6 or jquery 1.2.x plus the jquery dimensions plugin
*
* Visit http://www.ihwy.com/labs/jquery-listnav-plugin.aspx for more information.
*
* Dual licensed under the MIT and GPL licenses:
*  http://www.opensource.org/licenses/mit-license.php
*  http://www.gnu.org/licenses/gpl.html
*
*/
 
(function($) {
$.fn.listnav = function(options) {
var opts = $.extend({}, $.fn.listnav.defaults, options);
var 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', '-'];
var firstClick = false;
opts.prefixes = $.map(opts.prefixes, function(n) { return n.toLowerCase(); });
 
return this.each(function() {
var $wrapper, list, $list, $letters, $letterCount, id;
id = this.id;
$wrapper = $('#' + id + '-nav'); // user must abide by the convention: <ul id="myList"> for list and <div id="myList-nav"> for nav wrapper
$list = $(this);
 
var counts = {}, allCount = 0, isAll = true, numCount = 0, prevLetter = '';
 
function init() {
$wrapper.append(createLettersHtml());
 
$letters = $('.ln-letters', $wrapper).slice(0, 1); // will always be a single item
if (opts.showCounts) $letterCount = $('.ln-letter-count', $wrapper).slice(0, 1); // will always be a single item
 
addClasses();
addNoMatchLI();
if (opts.flagDisabled) addDisabledClass();
bindHandlers();
 
if (!opts.includeAll) $list.show(); // show the list in case the recommendation for includeAll=false was taken
 
// remove nav items we don't need
//
if (!opts.includeAll) $('.all', $letters).remove();
if (!opts.includeNums) $('._', $letters).remove();
if (!opts.includeOther) $('.-', $letters).remove();
 
$(':last', $letters).addClass('ln-last'); // allows for styling a case where last item needs right border set (because items before that only have top, left and bottom so that border between items isn't doubled)
 
if ($.cookie && (opts.cookieName !== null)) {
var cookieLetter = $.cookie(opts.cookieName);
if (cookieLetter !== null) opts.initLetter = cookieLetter;
}
 
// decide what to show first
//
if (opts.initLetter !== '') {
firstClick = true;
$('.' + opts.initLetter.toLowerCase(), $letters).slice(0, 1).click(); // click the initLetter if there was one
}
else {
if (opts.includeAll) $('.all', $letters).addClass('ln-selected'); // showing all: we don't need to click this: the whole list is already loaded
else { // ALL link is hidden, click the first letter that will display LI's
for (var i = ((opts.includeNums) ? 0 : 1); i < letters.length; i++) {
if (counts[letters[i]] > 0) {
firstClick = true;
$('.' + letters[i], $letters).slice(0, 1).click();
break;
}
}
}
}
}
 
// positions the letter count div above the letter links (so we only have to do it once: after this we just change it's left position via mouseover)
//
function setLetterCountTop() {
$letterCount.css({ top: $('.a', $letters).slice(0, 1).offset({ margin: false, border: true }).top - $letterCount.outerHeight({ margin: true }) }); // note: don't set top based on '.all': it might not be visible
}
 
// adds a class to each LI that has text content inside of it (ie, inside an <a>, a <div>, nested DOM nodes, etc)
//
function addClasses() {
var str, firstChar, firstWord, spl, $this, hasPrefixes = (opts.prefixes.length > 0);
$($list).children().each(function() {
$this = $(this), firstChar = '', str = $.trim($this.text()).toLowerCase();
if (str !== '') {
if (hasPrefixes) {
spl = str.split(' ');
if ((spl.length > 1) && ($.inArray(spl[0], opts.prefixes) > -1)) {
firstChar = spl[1].charAt(0);
addLetterClass(firstChar, $this, true);
}
}
firstChar = str.charAt(0);
addLetterClass(firstChar, $this);
}
});
}
 
function addLetterClass(firstChar, $el, isPrefix) {
// Deployed with SRF 1.9 to recognize the data-sortkey
var sortKey = String( $el.data( 'sortkey' ) );
if ( sortKey !== 'undefined' ){
firstChar = sortKey.toLowerCase();
} else {
if (/\W/.test(firstChar)) firstChar = '-'; // not A-Z, a-z or 0-9, so considered "other"
if (!isNaN(firstChar)) firstChar = '_'; // use '_' if the first char is a number
}
 
$el.addClass('ln-' + firstChar);
 
if (counts[firstChar] === undefined) counts[firstChar] = 0;
counts[firstChar]++;
if (!isPrefix) allCount++;
}
 
function addDisabledClass() {
for (var i = 0; i < letters.length; i++) {
if (counts[letters[i]] === undefined) $('.' + letters[i], $letters).addClass('ln-disabled');
}
}
 
function addNoMatchLI() {
$list.append('<li class="ln-no-match" style="display:none">' + opts.noMatchText + '</li>');
}
 
function getLetterCount(el) {
if ($(el).hasClass('all')) return allCount;
else {
var count = counts[$(el).attr('class').split(' ')[0]];
return (count !== undefined) ? count : 0; // some letters may not have a count in the hash
}
}
 
function bindHandlers() {
 
// sets the top position of the count div in case something above it on the page has resized
//
if (opts.showCounts) {
$wrapper.mouseover(function() {
setLetterCountTop();
});
}
 
// mouseover for each letter: shows the count above the letter
//
if (opts.showCounts) {
$('a', $letters).mouseover(function() {
var left = $(this).position().left;
var width = ($(this).outerWidth({ margin: true }) - 1) + 'px'; // the -1 is to tweak the width a bit due to a seeming inaccuracy in jquery ui/dimensions outerWidth (same result in FF2 and IE6/7)
var count = getLetterCount(this);
$letterCount.css({ left: left, width: width }).text(count).show(); // set left position and width of letter count, set count text and show it
});
 
// mouseout for each letter: hide the count
//
$('a', $letters).mouseout(function() {
$letterCount.hide();
});
}
 
// click handler for letters: shows/hides relevant LI's
//
$('a', $letters).click(function() {
$('a.ln-selected', $letters).removeClass('ln-selected');
 
var letter = $(this).attr('class').split(' ')[0];
 
if (letter == 'all') {
$list.children().show();
$list.children('.ln-no-match').hide();
isAll = true;
} else {
if (isAll) {
$list.children().hide();
isAll = false;
} else if (prevLetter !== '') $list.children('.ln-' + prevLetter).hide();
 
var count = getLetterCount(this);
if (count > 0) {
$list.children('.ln-no-match').hide(); // in case it's showing
$list.children('.ln-' + letter).show();
}
else $list.children('.ln-no-match').show();
 
prevLetter = letter;
}
 
if ($.cookie && (opts.cookieName !== null)) $.cookie(opts.cookieName, letter);
 
 
$(this).addClass('ln-selected');
$(this).blur();
if (!firstClick && (opts.onClick !== null)) opts.onClick(letter);
else firstClick = false;
return false;
});
}
 
// creates the HTML for the letter links
//
function createLettersHtml() {
var html = [];
for (var i = 1; i < letters.length; i++) {
if (html.length === 0) html.push('<a class="all" href="#">ALL</a><a class="_" href="#">0-9</a>');
html.push('<a class="' + letters[i] + '" href="#">' + ((letters[i] == '-') ? '...' : letters[i].toUpperCase()) + '</a>');
}
return '<div class="ln-letters">' + html.join('') + '</div>' + ((opts.showCounts) ? '<div class="ln-letter-count" style="display:none; position:absolute; top:0; left:0; width:20px;">0</div>' : ''); // the styling for ln-letter-count is to give us a starting point for the element, which will be repositioned when made visible (ie, should not need to be styled by the user)
}
 
init();
});
};
 
$.fn.listnav.defaults = {
initLetter: '',
includeAll: true,
incudeOther: false,
includeNums: true,
flagDisabled: true,
noMatchText: 'No matching entries',
showCounts: true,
cookieName: null,
onClick: null,
prefixes: []
};
})(jQuery);

Version vom 6. Februar 2025, 13:45 Uhr

/*
*
* jQuery listnav plugin
* Copyright (c) 2009 iHwy, Inc.
* Author: Jack Killpatrick
*
* Version 2.1 (08/09/2009)
* Requires jQuery 1.3.2, jquery 1.2.6 or jquery 1.2.x plus the jquery dimensions plugin
*
* Visit http://www.ihwy.com/labs/jquery-listnav-plugin.aspx for more information.
*
* Dual licensed under the MIT and GPL licenses:
*   http://www.opensource.org/licenses/mit-license.php
*   http://www.gnu.org/licenses/gpl.html
*
*/

(function($) {
	$.fn.listnav = function(options) {
		var opts = $.extend({}, $.fn.listnav.defaults, options);
		var 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', '-'];
		var firstClick = false;
		opts.prefixes = $.map(opts.prefixes, function(n) { return n.toLowerCase(); });

		return this.each(function() {
			var $wrapper, list, $list, $letters, $letterCount, id;
			id = this.id;
			$wrapper = $('#' + id + '-nav'); // user must abide by the convention: <ul id="myList"> for list and <div id="myList-nav"> for nav wrapper
			$list = $(this);

			var counts = {}, allCount = 0, isAll = true, numCount = 0, prevLetter = '';

			function init() {
				$wrapper.append(createLettersHtml());

				$letters = $('.ln-letters', $wrapper).slice(0, 1); // will always be a single item
				if (opts.showCounts) $letterCount = $('.ln-letter-count', $wrapper).slice(0, 1); // will always be a single item

				addClasses();
				addNoMatchLI();
				if (opts.flagDisabled) addDisabledClass();
				bindHandlers();

				if (!opts.includeAll) $list.show(); // show the list in case the recommendation for includeAll=false was taken

				// remove nav items we don't need
				//
				if (!opts.includeAll) $('.all', $letters).remove();
				if (!opts.includeNums) $('._', $letters).remove();
				if (!opts.includeOther) $('.-', $letters).remove();

				$(':last', $letters).addClass('ln-last'); // allows for styling a case where last item needs right border set (because items before that only have top, left and bottom so that border between items isn't doubled)

				if ($.cookie && (opts.cookieName !== null)) {
					var cookieLetter = $.cookie(opts.cookieName);
					if (cookieLetter !== null) opts.initLetter = cookieLetter;
				}

				// decide what to show first
				//
				if (opts.initLetter !== '') {
					firstClick = true;
					$('.' + opts.initLetter.toLowerCase(), $letters).slice(0, 1).click(); // click the initLetter if there was one
				}
				else {
					if (opts.includeAll) $('.all', $letters).addClass('ln-selected'); // showing all: we don't need to click this: the whole list is already loaded
					else { // ALL link is hidden, click the first letter that will display LI's
						for (var i = ((opts.includeNums) ? 0 : 1); i < letters.length; i++) {
							if (counts[letters[i]] > 0) {
								firstClick = true;
								$('.' + letters[i], $letters).slice(0, 1).click();
								break;
							}
						}
					}
				}
			}

			// positions the letter count div above the letter links (so we only have to do it once: after this we just change it's left position via mouseover)
			//
			function setLetterCountTop() {
				$letterCount.css({ top: $('.a', $letters).slice(0, 1).offset({ margin: false, border: true }).top - $letterCount.outerHeight({ margin: true }) }); // note: don't set top based on '.all': it might not be visible
			}

			// adds a class to each LI that has text content inside of it (ie, inside an <a>, a <div>, nested DOM nodes, etc)
			//
			function addClasses() {
				var str, firstChar, firstWord, spl, $this, hasPrefixes = (opts.prefixes.length > 0);
				$($list).children().each(function() {
					$this = $(this), firstChar = '', str = $.trim($this.text()).toLowerCase();
					if (str !== '') {
						if (hasPrefixes) {
							spl = str.split(' ');
							if ((spl.length > 1) && ($.inArray(spl[0], opts.prefixes) > -1)) {
								firstChar = spl[1].charAt(0);
								addLetterClass(firstChar, $this, true);
							}
						}
						firstChar = str.charAt(0);
						addLetterClass(firstChar, $this);
					}
				});
			}

			function addLetterClass(firstChar, $el, isPrefix) {
				// Deployed with SRF 1.9 to recognize the data-sortkey
				var sortKey = String( $el.data( 'sortkey' ) );
				if ( sortKey !== 'undefined' ){
					firstChar = sortKey.toLowerCase();
				} else {
					if (/\W/.test(firstChar)) firstChar = '-'; // not A-Z, a-z or 0-9, so considered "other"
					if (!isNaN(firstChar)) firstChar = '_'; // use '_' if the first char is a number
				}

				$el.addClass('ln-' + firstChar);

				if (counts[firstChar] === undefined) counts[firstChar] = 0;
				counts[firstChar]++;
				if (!isPrefix) allCount++;
			}

			function addDisabledClass() {
				for (var i = 0; i < letters.length; i++) {
					if (counts[letters[i]] === undefined) $('.' + letters[i], $letters).addClass('ln-disabled');
				}
			}

			function addNoMatchLI() {
				$list.append('<li class="ln-no-match" style="display:none">' + opts.noMatchText + '</li>');
			}

			function getLetterCount(el) {
				if ($(el).hasClass('all')) return allCount;
				else {
					var count = counts[$(el).attr('class').split(' ')[0]];
					return (count !== undefined) ? count : 0; // some letters may not have a count in the hash
				}
			}

			function bindHandlers() {

				// sets the top position of the count div in case something above it on the page has resized
				//
				if (opts.showCounts) {
					$wrapper.mouseover(function() {
						setLetterCountTop();
					});
				}

				// mouseover for each letter: shows the count above the letter
				//
				if (opts.showCounts) {
					$('a', $letters).mouseover(function() {
						var left = $(this).position().left;
						var width = ($(this).outerWidth({ margin: true }) - 1) + 'px'; // the -1 is to tweak the width a bit due to a seeming inaccuracy in jquery ui/dimensions outerWidth (same result in FF2 and IE6/7)
						var count = getLetterCount(this);
						$letterCount.css({ left: left, width: width }).text(count).show(); // set left position and width of letter count, set count text and show it
					});

					// mouseout for each letter: hide the count
					//
					$('a', $letters).mouseout(function() {
						$letterCount.hide();
					});
				}

				// click handler for letters: shows/hides relevant LI's
				//
				$('a', $letters).click(function() {
					$('a.ln-selected', $letters).removeClass('ln-selected');

					var letter = $(this).attr('class').split(' ')[0];

					if (letter == 'all') {
						$list.children().show();
						$list.children('.ln-no-match').hide();
						isAll = true;
					} else {
						if (isAll) {
							$list.children().hide();
							isAll = false;
						} else if (prevLetter !== '') $list.children('.ln-' + prevLetter).hide();

						var count = getLetterCount(this);
						if (count > 0) {
							$list.children('.ln-no-match').hide(); // in case it's showing
							$list.children('.ln-' + letter).show();
						}
						else $list.children('.ln-no-match').show();

						prevLetter = letter;
					}

					if ($.cookie && (opts.cookieName !== null)) $.cookie(opts.cookieName, letter);


					$(this).addClass('ln-selected');
					$(this).blur();
					if (!firstClick && (opts.onClick !== null)) opts.onClick(letter);
					else firstClick = false;
					return false;
				});
			}

			// creates the HTML for the letter links
			//
			function createLettersHtml() {
				var html = [];
				for (var i = 1; i < letters.length; i++) {
					if (html.length === 0) html.push('<a class="all" href="#">ALL</a><a class="_" href="#">0-9</a>');
					html.push('<a class="' + letters[i] + '" href="#">' + ((letters[i] == '-') ? '...' : letters[i].toUpperCase()) + '</a>');
				}
				return '<div class="ln-letters">' + html.join('') + '</div>' + ((opts.showCounts) ? '<div class="ln-letter-count" style="display:none; position:absolute; top:0; left:0; width:20px;">0</div>' : ''); // the styling for ln-letter-count is to give us a starting point for the element, which will be repositioned when made visible (ie, should not need to be styled by the user)
			}

			init();
		});
	};

	$.fn.listnav.defaults = {
		initLetter: '',
		includeAll: true,
		incudeOther: false,
		includeNums: true,
		flagDisabled: true,
		noMatchText: 'No matching entries',
		showCounts: true,
		cookieName: null,
		onClick: null,
		prefixes: []
	};
})(jQuery);