Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the way that we do debugging #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 61 additions & 66 deletions jquery.tablesorter.js
Original file line number Diff line number Diff line change
@@ -1,103 +1,105 @@
/*
*
*
* TableSorter 2.0 - Client-side table sorting with ease!
* Version 2.0.5b
* Version 2.0.6
* @requires jQuery v1.2.3
*
*
* Copyright (c) 2007 Christian Bach
* Contributions in 2014 by:
* Robert Fischer
* Examples and docs at: http://tablesorter.com
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*
*/
/**
*
*
* @description Create a sortable table with multi-column sorting capabilitys
*
*
* @example $('table').tablesorter();
* @desc Create a simple tablesorter interface.
*
*
* @example $('table').tablesorter({ sortList:[[0,0],[1,0]] });
* @desc Create a tablesorter interface and sort on the first and secound column column headers.
*
*
* @example $('table').tablesorter({ headers: { 0: { sorter: false}, 1: {sorter: false} } });
*
*
* @desc Create a tablesorter interface and disableing the first and second column headers.
*
*
*
*
* @example $('table').tablesorter({ headers: { 0: {sorter:"integer"}, 1: {sorter:"currency"} } });
*
*
* @desc Create a tablesorter interface and set a column parser for the first
* and second column.
*
*
*
*
* @param Object
* settings An object literal containing key/value pairs to provide
* optional settings.
*
*
*
*
* @option String cssHeader (optional) A string of the class name to be appended
* to sortable tr elements in the thead of the table. Default value:
* "header"
*
*
* @option String cssAsc (optional) A string of the class name to be appended to
* sortable tr elements in the thead on a ascending sort. Default value:
* "headerSortUp"
*
*
* @option String cssDesc (optional) A string of the class name to be appended
* to sortable tr elements in the thead on a descending sort. Default
* value: "headerSortDown"
*
*
* @option String sortInitialOrder (optional) A string of the inital sorting
* order can be asc or desc. Default value: "asc"
*
*
* @option String sortMultisortKey (optional) A string of the multi-column sort
* key. Default value: "shiftKey"
*
*
* @option String textExtraction (optional) A string of the text-extraction
* method to use. For complex html structures inside td cell set this
* option to "complex", on large tables the complex option can be slow.
* Default value: "simple"
*
*
* @option Object headers (optional) An array containing the forces sorting
* rules. This option let's you specify a default sorting rule. Default
* value: null
*
*
* @option Array sortList (optional) An array containing the forces sorting
* rules. This option let's you specify a default sorting rule. Default
* value: null
*
*
* @option Array sortForce (optional) An array containing forced sorting rules.
* This option let's you specify a default sorting rule, which is
* prepended to user-selected rules. Default value: null
*
*
* @option Boolean sortLocaleCompare (optional) Boolean flag indicating whatever
* to use String.localeCampare method or not. Default set to true.
*
*
*
*
* @option Array sortAppend (optional) An array containing forced sorting rules.
* This option let's you specify a default sorting rule, which is
* appended to user-selected rules. Default value: null
*
*
* @option Boolean widthFixed (optional) Boolean flag indicating if tablesorter
* should apply fixed widths to the table columns. This is usefull when
* using the pager companion plugin. This options requires the dimension
* jquery plugin. Default value: false
*
*
* @option Boolean cancelSelection (optional) Boolean flag indicating if
* tablesorter should cancel selection of the table headers text.
* Default value: true
*
*
* @option Boolean debug (optional) Boolean flag indicating if tablesorter
* should display debuging information usefull for development.
*
*
* @type jQuery
*
*
* @name tablesorter
*
*
* @cat Plugins/Tablesorter
*
*
* @author Christian Bach/christian.bach@polyester.se
*/

Expand Down Expand Up @@ -135,20 +137,17 @@
};

/* debuging utils */

function benchmark(s, d) {
log(s + "," + (new Date().getTime() - d.getTime()) + "ms");
}

this.benchmark = benchmark;

function log(s) {
if (typeof console != "undefined" && typeof console.debug != "undefined") {
console.log(s);
} else {
alert(s);
}
if(typeof(console) === 'undefined') console = {};
if(!console.debug) {
if(console.info) {
console.debug = console.info;
} else {
console.debug = alert;
}
}
var benchmark = function(s,d) {
console.debug(s + "," + (new Date().getTime() - d.getTime()) + "ms");
};

/* parsers utils */

Expand Down Expand Up @@ -192,9 +191,7 @@
}
}

if (table.config.debug) {
log(parsersDebug);
}
if (table.config.debug) console.debug(parsersDebug);

return list;
};
Expand All @@ -209,9 +206,7 @@
if (rows[rowIndex]) {
node = getNodeFromRowAndCellIndex(rows, rowIndex, cellIndex);
nodeValue = trimAndGetNodeText(table.config, node);
if (table.config.debug) {
log('Checking if value was empty on row:' + rowIndex);
}
if (table.config.debug) console.debug('Checking if value was empty on row:' + rowIndex);
} else {
keepLooking = false;
}
Expand Down Expand Up @@ -292,9 +287,9 @@
};

function getElementText(config, node) {

if (!node) return "";

var $node = $(node),
data = $node.attr('data-sort-value');
if (data !== undefined) return data;
Expand Down Expand Up @@ -351,7 +346,7 @@
tableBody[0].appendChild(r[pos][j]);
}

//
//
}
}

Expand Down Expand Up @@ -385,16 +380,16 @@
}

var meta = ($.metadata) ? true : false;

var header_index = computeTableHeaderCellIndexes(table);

var $tableHeaders = $(table.config.selectorHeaders, table).each(function (index) {

this.column = header_index[this.parentNode.rowIndex + "-" + this.cellIndex];
// this.column = index;
this.order = formatSortingOrder(table.config.sortInitialOrder);


this.count = this.order;

if (checkHeaderMetadata(this) || checkHeaderOptions(table, index)) this.sortDisabled = true;
Expand All @@ -411,7 +406,7 @@

if (table.config.debug) {
benchmark("Built headers:", time);
log($tableHeaders);
console.debug($tableHeaders);
}

return $tableHeaders;
Expand Down Expand Up @@ -497,12 +492,12 @@
};
return false;
}

function checkHeaderOptionsSortingLocked(table, i) {
if ((table.config.headers[i]) && (table.config.headers[i].lockedOrder)) return table.config.headers[i].lockedOrder;
return false;
}

function applyWidget(table) {
var c = table.config.widgets;
var l = c.length;
Expand Down Expand Up @@ -580,7 +575,7 @@
}

/* sorting methods */

var sortWrapper;

function multisort(table, sortList, cache) {
Expand Down Expand Up @@ -733,7 +728,7 @@
this.order = this.count++ % 2;
// always sort on the locked order.
if(this.lockedOrder) this.order = this.lockedOrder;

// user only whants to sort on one
// column
if (!e[config.sortMultiSortKey]) {
Expand Down Expand Up @@ -980,9 +975,9 @@
if (c.dateFormat == "us") {
// reformat the string in ISO format
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$1/$2");
}
}
if (c.dateFormat == "pt") {
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$2/$1");
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$2/$1");
} else if (c.dateFormat == "uk") {
// reformat the string in ISO format
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$2/$1");
Expand Down
Loading