2015-03-28 20:03:50 +00:00
|
|
|
/*! Parser: ignoreArticles - updated 9/15/2014 (v2.17.8) *//*
|
2015-07-23 04:29:51 +00:00
|
|
|
* This parser will remove 'The', 'A' and 'An' from the beginning of a book
|
2013-03-28 21:57:38 +00:00
|
|
|
* or movie title, so it sorts by the second word or number
|
|
|
|
* Demo: http://jsfiddle.net/Mottie/abkNM/5/
|
|
|
|
*/
|
2014-09-16 00:44:03 +00:00
|
|
|
/*jshint browser: true, jquery:true, unused:false */
|
2018-03-17 20:30:25 +00:00
|
|
|
;(function($) {
|
2015-07-23 04:29:51 +00:00
|
|
|
'use strict';
|
2013-03-28 21:57:38 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
var ts = $.tablesorter;
|
2014-09-07 03:30:53 +00:00
|
|
|
|
2013-03-28 21:57:38 +00:00
|
|
|
// basic list from http://en.wikipedia.org/wiki/Article_%28grammar%29
|
2014-09-07 03:30:53 +00:00
|
|
|
ts.ignoreArticles = {
|
2015-07-23 04:29:51 +00:00
|
|
|
'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'
|
2013-03-28 21:57:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// To add a custom parser, define:
|
2015-07-23 04:29:51 +00:00
|
|
|
// $.tablesorter.ignoreArticles['xx'] = 'A, B, C';
|
2013-03-28 21:57:38 +00:00
|
|
|
// and then set the language id 'xx' in the headers option
|
|
|
|
// ignoreArticles : 'xx'
|
|
|
|
|
2014-09-07 03:30:53 +00:00
|
|
|
ts.addParser({
|
2013-03-28 21:57:38 +00:00
|
|
|
id: 'ignoreArticles',
|
|
|
|
is: function() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
format: function(s, table, cell, cellIndex) {
|
2014-09-07 03:30:53 +00:00
|
|
|
var art, ignore, lang,
|
|
|
|
c = table.config,
|
|
|
|
str = s || '';
|
2013-03-28 21:57:38 +00:00
|
|
|
if ( !(c.headers && c.headers[cellIndex] && c.headers[cellIndex].ignoreArticlesRegex) ) {
|
2014-09-07 03:30:53 +00:00
|
|
|
// initialize - save regex in c.headers[cellIndex].ignoreArticlesRegex
|
2013-03-28 21:57:38 +00:00
|
|
|
if (!c.headers) { c.headers = {}; }
|
|
|
|
if (!c.headers[cellIndex]) { c.headers[cellIndex] = {}; }
|
2014-09-07 03:30:53 +00:00
|
|
|
lang = ts.getData( c.$headers.eq(cellIndex), ts.getColumnData( table, c.headers, cellIndex ), 'ignoreArticles' );
|
2015-07-23 04:29:51 +00:00
|
|
|
art = (ts.ignoreArticles[lang] || 'the, a, an' ) + '';
|
|
|
|
c.headers[cellIndex].ignoreArticlesRegex = new RegExp('^(' + $.trim( art.split(/\s*\,\s*/).join('\\s|') + '\\s' ).replace('_\\s', '') + ')', 'i');
|
2014-09-07 03:30:53 +00:00
|
|
|
// exception regex stored in c.headers[cellIndex].ignoreArticlesRegex2
|
|
|
|
ignore = ts.getData( c.$headers.eq(cellIndex), ts.getColumnData( table, c.headers, cellIndex ), 'ignoreArticlesExcept' );
|
2015-07-23 04:29:51 +00:00
|
|
|
c.headers[cellIndex].ignoreArticlesRegex2 = ignore !== '' ? new RegExp('^(' + ignore.replace(/\s/g, '\\s') + ')', 'i') : '';
|
2014-09-07 03:30:53 +00:00
|
|
|
}
|
|
|
|
art = c.headers[cellIndex].ignoreArticlesRegex;
|
|
|
|
if (art.test(str)) {
|
|
|
|
ignore = c.headers[cellIndex].ignoreArticlesRegex2;
|
|
|
|
if ( !(ignore && ignore.test(str)) ) {
|
|
|
|
return str.replace(art, '');
|
|
|
|
}
|
2013-03-28 21:57:38 +00:00
|
|
|
}
|
2014-09-07 03:30:53 +00:00
|
|
|
return str;
|
2013-03-28 21:57:38 +00:00
|
|
|
},
|
|
|
|
type: 'text'
|
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery);
|