Sha256: 5ef3f0059c6811b8b0ecbed41273828b2df0996a3245a318e900bb8cd026bb40

Contents?: true

Size: 1.74 KB

Versions: 20

Compression:

Stored size: 1.74 KB

Contents

/*! Title parser
 * This parser will remove "The", "A" and "An" from the beginning of a book
 * or movie title, so it sorts by the second word or number
 * Demo: http://jsfiddle.net/Mottie/abkNM/5/
 */
/*global jQuery: false */
;(function($){
"use strict";

	// basic list from http://en.wikipedia.org/wiki/Article_%28grammar%29
	$.tablesorter.ignoreArticles = {
		"en" : "the, a, an",
		"de" : "der, die, das, des, dem, den, ein, eine, einer, eines, einem, einen",
		"nl" : "de, het, de, een",
		"es" : "el, la, lo, los, las, un, una, unos, unas",
		"pt" : "o, a, os, as, um, uma, uns, umas",
		"fr" : "le, la, l'_, les, un, une, des",
		"it" : "il, lo, la, l'_, i, gli, le, un', uno, una, un",
		"hu" : "a, az, egy"
	};

	// To add a custom parser, define:
	// $.tablesorter.ignoreArticles['xx'] = "A, B, C";
	// and then set the language id 'xx' in the headers option
	// ignoreArticles : 'xx'

	$.tablesorter.addParser({
		id: 'ignoreArticles',
		is: function() {
			return false;
		},
		format: function(s, table, cell, cellIndex) {
			var c = table.config, art, lang;
			if ( !(c.headers && c.headers[cellIndex] && c.headers[cellIndex].ignoreArticlesRegex) ) {
				// initialize - save regex in c.headers[cellIndex].ignoreArticles
				if (!c.headers) { c.headers = {}; }
				if (!c.headers[cellIndex]) { c.headers[cellIndex] = {}; }
				lang = $.tablesorter.getData(c.$headers.eq(cellIndex), c.headers[cellIndex], 'ignoreArticles');
				art = ($.tablesorter.ignoreArticles[lang] || "the, a, an" ) + "";
				c.headers[cellIndex].ignoreArticlesRegex = new RegExp('^(' + $.trim( art.split(/\s*\,\s*/).join('\\s|') + "\\s" ).replace("_\\s","") + ')', 'i');
			}
			return (s || '').replace(c.headers[cellIndex].ignoreArticlesRegex, '');
		},
		type: 'text'
	});

})(jQuery);

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
jquery-tablesorter-1.12.7 vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ignore-articles.js
jquery-tablesorter-1.12.6 vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ignore-articles.js
jquery-tablesorter-1.12.5 vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ignore-articles.js
jquery-tablesorter-1.12.4 vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ignore-articles.js
jquery-tablesorter-1.12.3 vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ignore-articles.js
jquery-tablesorter-1.12.2 vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ignore-articles.js
jquery-tablesorter-1.12.1 vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ignore-articles.js
jquery-tablesorter-1.12.0 vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ignore-articles.js
jquery-tablesorter-1.11.2 vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ignore-articles.js
jquery-tablesorter-1.11.1 vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ignore-articles.js
jquery-tablesorter-1.11.0 vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ignore-articles.js
jquery-tablesorter-1.10.10 vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ignore-articles.js
jquery-tablesorter-1.10.9 vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ignore-articles.js
jquery-tablesorter-1.10.8 vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ignore-articles.js
jquery-tablesorter-1.10.7 vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ignore-articles.js
jquery-tablesorter-1.10.6 vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ignore-articles.js
jquery-tablesorter-1.10.5 vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ignore-articles.js
jquery-tablesorter-1.10.4 vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ignore-articles.js
jquery-tablesorter-1.10.3 vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ignore-articles.js
jquery-tablesorter-rails4-0.0.1 app/assets/javascripts/jquery_tablesorter/parsers/parser-ignore-articles.js