Permalink
Browse files

minified version works again & lots of other fixes

  • Loading branch information...
1 parent 5d0224d commit d24ccca7d0a3df15283b8a5e3cd04819db53fb7b @Mottie committed May 9, 2012
View
Binary file not shown.
View
@@ -553,6 +553,14 @@
});
});</pre>
+ Individual columns can be modified by adding the following, set in order of priority <span class="tip"><em>Modified!</em></span> v2.3.1:
+ <ul>
+ <li>jQuery data <code class="hilight">data-dateFormat="mmddyyyy"</code>.</li>
+ <li>metadata <code class="hilight">class="{ dateFormat: 'mmddyyyy'}"</code>. This requires the metadata plugin.</li>
+ <li>headers option <code class="hilight">headers : { 0 : { dateFormat : 'mmddyyyy' } }</code>.</li>
+ <li>header class name <code class="hilight">class="dateFormat-mmddyyyy"</code>.</li>
+ <li>Overall <code class="hilight">dateFormat</code> option.</li>
+ </ul>
</div>
</td>
<td><a href="example-option-date-format.html">Example</a></td>
@@ -632,12 +640,12 @@
0: { sorter: false },
// See example 2: Sort column numerically &amp; treat any text as if its value is:
- 1: { sorter: "digit" }, // zero
- 2: { sorter: "digit", string: "max+" }, // maximum positive value
- 3: { sorter: "digit", string: "max-" }, // maximum negative value
+ 1: { sorter: "digit", empty: "top" }, // zero; sort empty cells to the top
+ 2: { sorter: "digit", string: "max" }, // maximum positive value
+ 3: { sorter: "digit", string: "min" }, // maximum negative value
- // Sort the fifth column by date (e.g. mm/dd/yyyy if the date format is "us")
- 4: { sorter: "shortDate" },
+ // Sort the fifth column by date &amp; set the format
+ 4: { sorter: "shortDate", dateFormat: "yyyymmdd" } // year first format
// See example 3: lock the sort order
// this option will not work if added as metadata
@@ -773,7 +781,13 @@
<td>Use to add an initial sort to the table.
<div class="collapsible">
<br>
- The value contains an array of instructions for per-column sorting and direction in the format: <code class="hilight">[[columnIndex, sortDirection], ... ]</code> where columnIndex is a zero-based index for your columns left-to-right and sortDirection is 0 for Ascending and 1 for Descending. A valid argument that sorts ascending first by column 1 and then column 2 looks like: <code class="hilight">[[0,0],[1,0]]</code>. Please see <a href="#sortforce"><code class="hilight">sortForce</code></a> for more details on other sort order options.
+ The value contains an array of instructions for per-column sorting and direction in the format: <code class="hilight">[[columnIndex, sortDirection], ... ]</code> where columnIndex is a zero-based index for your columns left-to-right and sortDirection is 0 for Ascending and 1 for Descending. A valid argument that sorts ascending first by column 1 and then column 2 looks like: <code class="hilight">[[0,0],[1,0]]</code>. Please see <a href="#sortforce"><code class="hilight">sortForce</code></a> for more details on other sort order options.<br>
+ <br>
+ This option can also be set using jQuery data (<span class="tip"><em>New!</em></span> v2.3.1) or metadata on the table:
+ <table class="info"><tbody>
+ <tr><th>jQuery data</th><td><code>&lt;table data-sortlist="[[0,0],[4,0]]"&gt;</code></td></tr>
+ <tr><th>Meta data</th><td><code>&lt;table class="tablesorter {sortlist: [[0,0],[4,0]]}"&gt;</code></td></tr>
+ </tbody></table>
</div>
</td>
<td><a href="example-option-sort-list.html">Example</a></td>
@@ -795,12 +809,24 @@
</tr>
<tr id="sortinitialorder">
- <td><span class="permalink">sortInitialOrder</span></td>
+ <td><a href="#" class="toggle2">sortInitialOrder</a></td>
<td>String</td>
<td>"asc"</td>
<td>
- When clicking the header for the first time, the direction it sorts. Valid arguments are <code class="hilight">"asc"</code> for Ascending or <code class="hilight">"desc"</code> for Descending.<br>
- This order can also be set by desired column using the <a href="#headers"><code class="hilight">headers</code></a> option (Added in v2.0.8).
+ The direction a column sorts when clicking the header for the first time. Valid arguments are <code class="hilight">"asc"</code> for Ascending or <code class="hilight">"desc"</code> for Descending.<br>
+ <div class="collapsible">
+ <br>
+ This order can also be set by desired column using the <a href="#headers"><code class="hilight">headers</code></a> option (Added in v2.0.8).<br>
+ <br>
+ Individual columns can be modified by adding the following, set in order of priority <span class="tip"><em>Modified!</em></span> v2.3.1:
+ <ul>
+ <li>jQuery data <code class="hilight">data-sortInitialOrder="asc"</code>.</li>
+ <li>metadata <code class="hilight">class="{ sortInitialOrder: 'asc'}"</code>. This requires the metadata plugin.</li>
+ <li>headers option <code class="hilight">headers : { 0 : { sortInitialOrder : 'asc' } }</code>.</li>
+ <li>header class name <code class="hilight">class="sortInitialOrder-asc"</code>.</li>
+ <li>Overall <code class="hilight">sortInitialOrder</code> option.</li>
+ </ul>
+ </div>
</td>
<td>Ex:<a href="example-option-sort-order.html">1</a> <a href="example-options-headers-order.html">2</a></td>
</tr>
View
@@ -1,5 +1,5 @@
/*!
-* TableSorter 2.3 - Client-side table sorting with ease!
+* TableSorter 2.3.1 - Client-side table sorting with ease!
* @requires jQuery v1.2.6+
*
* Copyright (c) 2007 Christian Bach
@@ -18,9 +18,9 @@
$.extend({
tablesorter: new function() {
- this.version = "2.3";
+ this.version = "2.3.1";
- var parsers = [], widgets = [];
+ var parsers = [], widgets = [];
this.defaults = {
// appearance
@@ -156,29 +156,9 @@
return parsers[0];
}
- // get sorter, string and empty options for each column from
- // metadata, header option or header class name ("sorter-false")
- // priority = jQuery data > meta > headers option > header class name
- function getData(h, ch, key) {
- var val = '',
- m = $.metadata ? h.metadata() : false,
- cl = h.attr('class') || '';
- if (h.data() && typeof h.data(key) !== 'undefined'){
- val += h.data(key);
- } else if (m && m[key]) {
- val = m[key];
- } else if (ch && ch[key]) {
- val = ch[key];
- } else if (cl && cl.match(key + '-')) {
- // include sorter class name "sorter-text", etc
- val = cl.match( new RegExp(key + '-(\\w+)') )[1] || '';
- }
- return $.trim(val);
- }
-
function buildParserCache(table, $headers) {
if (table.tBodies.length === 0) { return; } // In the case of empty tables
- var c = table.config, rows = table.tBodies[0].rows,
+ var c = table.config, rows = table.tBodies[0].rows, ts = $.tablesorter,
list, l, i, h, m, ch, cl, p, parsersDebug = "";
if (rows[0]) {
list = [];
@@ -187,11 +167,11 @@
h = $headers.filter(':not([colspan])[data-column="'+i+'"]:last');
ch = c.headers[i];
// get column parser
- p = getParserById( getData(h, ch, 'sorter') );
+ p = getParserById( ts.getData(h, ch, 'sorter') );
// empty cells behaviour - keeping emptyToBottom for backwards compatibility.
- c.empties[i] = getData(h, ch, 'empty') || c.emptyTo || (c.emptyToBottom ? 'bottom' : 'top' );
+ c.empties[i] = ts.getData(h, ch, 'empty') || c.emptyTo || (c.emptyToBottom ? 'bottom' : 'top' );
// text strings behaviour in numerical sorts
- c.strings[i] = getData(h, ch, 'string') || c.stringTo || 'max';
+ c.strings[i] = ts.getData(h, ch, 'string') || c.stringTo || 'max';
if (!p) {
p = detectParserForColumn(table, rows, -1, i);
}
@@ -382,31 +362,33 @@
function buildHeaders(table) {
var meta = ($.metadata) ? true : false,
- header_index = computeTableHeaderCellIndexes(table),
- $th, lock, time, $tableHeaders, c = table.config;
+ header_index = computeTableHeaderCellIndexes(table), ch, $t,
+ $th, lock, time, $tableHeaders, c = table.config, ts = $.tablesorter;
c.headerList = [];
if (c.debug) {
time = new Date();
}
$tableHeaders = $(c.selectorHeaders, table)
.wrapInner("<div class='tablesorter-header-inner' />")
.each(function(index) {
+ $t = $(this);
+ ch = c.headers[index];
this.column = header_index[this.parentNode.rowIndex + "-" + this.cellIndex];
- this.order = formatSortingOrder( (c.headers[index] && c.headers[index].sortInitialOrder) ? c.headers[index].sortInitialOrder : c.sortInitialOrder ) ? [1,0,2] : [0,1,2];
+ this.order = formatSortingOrder( ts.getData($t, ch, 'sortInitialOrder') || c.sortInitialOrder ) ? [1,0,2] : [0,1,2];
this.count = -1; // set to -1 because clicking on the header automatically adds one
- if (getData($(this), c.headers[index], 'sorter') === 'false') { this.sortDisabled = true; }
+ if (ts.getData($t, ch, 'sorter') === 'false') { this.sortDisabled = true; }
this.lockedOrder = false;
- lock = (c.headers[index] && c.headers[index].lockedOrder !== null) ? c.headers[index].lockedOrder : false;
+ lock = ts.getData($t, ch, 'lockedOrder') || false;
if (typeof(lock) !== 'undefined' && lock !== false) {
this.order = this.lockedOrder = formatSortingOrder(lock) ? [1,1,1] : [0,0,0];
}
if (!this.sortDisabled) {
- $th = $(this).addClass(c.cssHeader);
+ $th = $t.addClass(c.cssHeader);
if (c.onRenderHeader) { c.onRenderHeader.apply($th, [index]); }
}
// add cell to headerList
c.headerList[index] = this;
- $(this).parent().addClass(c.cssHeader);
+ $t.parent().addClass(c.cssHeader);
});
if (c.debug) {
benchmark("Built headers", time);
@@ -612,7 +594,8 @@
if (!this.tHead || this.tBodies.length === 0) { return; }
// declare
var $headers, $cell, totalRows, $this,
- config, c, i, j, k, a, s, o;
+ config, c, i, j, k, a, s, o,
+ m = $.metadata;
// new blank config object
this.config = {};
// merge and extend.
@@ -799,9 +782,11 @@
applyWidget(this);
});
- // get sort list from metadata
- if ($.metadata && ($(this).metadata() && $(this).metadata().sortlist)) {
- c.sortList = $(this).metadata().sortlist;
+ // get sort list from jQuery data or metadata
+ if ($this.data() && typeof $this.data().sortlist !== 'undefined') {
+ c.sortList = $this.data().sortlist;
+ } else if (m && ($this.metadata() && $this.metadata().sortlist)) {
+ c.sortList = $this.metadata().sortlist;
}
// apply widget init code
applyWidget(this, true);
@@ -834,8 +819,9 @@
this.addWidget = function(widget) {
widgets.push(widget);
};
+
this.formatFloat = function(s, table) {
- if (typeof(s) !== 'string') { return s; }
+ if (typeof(s) !== 'string' || s === '') { return s; }
if (table.config.usNumberFormat !== false) {
// US Format - 1,234,567.89 -> 1234567.89
s = s.replace(/,/g,'');
@@ -855,6 +841,7 @@
// replace all unwanted chars and match.
return (/^[\-+(]?\d*[)]?$/).test($.trim(s.replace(/[,.'\s]/g, '')));
};
+
// regex used in natural sort
this.regex = [
/(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi, // chunk/tokenize numbers & letters
@@ -889,21 +876,42 @@
}
return s;
};
+
+ // get sorter, string, empty, etc options for each column from
+ // metadata, header option or header class name ("sorter-false")
+ // priority = jQuery data > meta > headers option > header class name
+ this.getData = function(h, ch, key) {
+ var val = '',
+ m = $.metadata ? h.metadata() : false,
+ cl = h.attr('class') || '';
+ if (h.data() && typeof h.data(key) !== 'undefined'){
+ val += h.data(key);
+ } else if (m && typeof m[key] !== 'undefined') {
+ val += m[key];
+ } else if (ch && typeof ch[key] !== 'undefined') {
+ val += ch[key];
+ } else if (cl && cl.match(key + '-')) {
+ // include sorter class name "sorter-text", etc
+ val = cl.match( new RegExp(key + '-(\\w+)') )[1] || '';
+ }
+ return $.trim(val);
+ };
+
this.clearTableBody = function(table) {
$(table.tBodies).filter(':not(.' + table.config.cssInfoBlock + ')').empty();
};
}
})();
+ // make shortcut
+ var ts = $.tablesorter;
+
// extend plugin scope
$.fn.extend({
- tablesorter: $.tablesorter.construct
+ tablesorter: ts.construct
});
- // make shortcut
- var ts = $.tablesorter;
-
// add default parsers
ts.addParser({
id: "text",
@@ -913,7 +921,7 @@
format: function(s, table, cell, cellIndex) {
var c = table.config;
s = $.trim( c.ignoreCase ? s.toLocaleLowerCase() : s );
- return c.sortLocaleCompare ? $.tablesorter.replaceAccents(s) : s;
+ return c.sortLocaleCompare ? ts.replaceAccents(s) : s;
},
type: "text"
});
@@ -924,7 +932,7 @@
return (/^\(?[\u00a3$\u20ac\u00a4\u00a5\u00a2?.]/).test(s); // #$ $%"?.
},
format: function(s, table) {
- return $.tablesorter.formatFloat(s.replace(/[^\w,. \-()]/g, ""), table);
+ return ts.formatFloat(s.replace(/[^\w,. \-()]/g, ""), table);
},
type: "numeric"
});
@@ -946,7 +954,7 @@
r += item;
}
}
- return $.tablesorter.formatFloat(r, table);
+ return ts.formatFloat(r, table);
},
type: "numeric"
});
@@ -968,7 +976,7 @@
return (/^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}$/).test(s);
},
format: function(s, table) {
- return $.tablesorter.formatFloat((s !== "") ? new Date(s.replace(/-/g, "/")).getTime() : "", table);
+ return ts.formatFloat((s !== "") ? (new Date(s.replace(/-/g, "/")).getTime() || "") : "", table);
},
type: "numeric"
});
@@ -979,7 +987,7 @@
return (/\%\)?$/).test($.trim(s));
},
format: function(s, table) {
- return $.tablesorter.formatFloat(s.replace(/%/g, ""), table);
+ return ts.formatFloat(s.replace(/%/g, ""), table);
},
type: "numeric"
});
@@ -990,7 +998,7 @@
return s.match(/^[A-Za-z]{3,10}\.? [0-9]{1,2}, ([0-9]{4}|'?[0-9]{2}) (([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(AM|PM)))$/);
},
format: function(s, table) {
- return $.tablesorter.formatFloat(new Date(s).getTime(), table);
+ return ts.formatFloat( (new Date(s).getTime() || ''), table);
},
type: "numeric"
});
@@ -1003,7 +1011,7 @@
},
format: function(s, table, cell, cellIndex) {
var c = table.config,
- format = (c.headers && c.headers[cellIndex]) ? c.headers[cellIndex].dateFormat || c.dateFormat : c.dateFormat; // get dateFormat from header or config
+ format = ts.getData($(cell), c.headers[cellIndex], 'dateFormat') || c.dateFormat;
s = s.replace(/\s+/g," ").replace(/[\-|\.|\,]/g, "/");
if (format === "mmddyyyy") {
s = s.replace(/(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{4})/, "$3/$1/$2");
@@ -1012,7 +1020,7 @@
} else if (format === "yyyymmdd") {
s = s.replace(/(\d{4})[\/\s](\d{1,2})[\/\s](\d{1,2})/, "$1/$2/$3");
}
- return $.tablesorter.formatFloat(new Date(s).getTime(), table);
+ return ts.formatFloat( (new Date(s).getTime() || ''), table);
},
type: "numeric"
});
@@ -1023,18 +1031,18 @@
return (/^(([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(am|pm)))$/).test(s);
},
format: function(s, table) {
- return $.tablesorter.formatFloat(new Date("2000/01/01 " + s).getTime(), table);
+ return ts.formatFloat( (new Date("2000/01/01 " + s).getTime() || ''), table);
},
type: "numeric"
});
ts.addParser({
id: "digit",
is: function(s) {
- return $.tablesorter.isDigit(s);
+ return ts.isDigit(s);
},
format: function(s, table) {
- return $.tablesorter.formatFloat(s.replace(/[^\w,. \-()]/g, ""), table);
+ return ts.formatFloat(s.replace(/[^\w,. \-()]/g, ""), table);
},
type: "numeric"
});
@@ -1084,7 +1092,7 @@
}
}
if (c.debug) {
- $.tablesorter.benchmark("Applying Zebra widget", time);
+ ts.benchmark("Applying Zebra widget", time);
}
}
});
Oops, something went wrong.
@@ -1,4 +1,4 @@
-/*! tableSorter 2.3 widgets - updated 5/8/2012
+/*! tableSorter 2.3 widgets - updated 5/9/2012
*
* jQuery UI Theme
* Column Styles
@@ -186,7 +186,7 @@ $.tablesorter.addWidget({
for (i=0; i < cols; i++){
fr += '<td><input type="search" data-col="' + i + '" class="' + css;
// use header option - headers: { 1: { filter: false } } OR add class="filter-false"
- fr += ((c.headers[i] && c.headers[i].hasOwnProperty('filter') && c.headers[i].filter === false) || $(c.headerList[i]).is('.filter-false') ) ? ' disabled" disabled' : '"';
+ fr += $.tablesorter.getData(c.headerList[i], c.headers[i], 'filter') === 'false' ? ' disabled" disabled' : '"';
fr += '></td>';
}
$t
Oops, something went wrong.

0 comments on commit d24ccca

Please sign in to comment.