diff --git a/README.markdown b/README.markdown
index 1ad0cbac..ffa97042 100644
--- a/README.markdown
+++ b/README.markdown
@@ -34,6 +34,30 @@ Included all original [document pages](http://mottie.github.com/tablesorter/docs
View the [complete listing here](http://mottie.github.com/tablesorter/changelog.txt).
+####Version 2.0.28 (2012-2-1)
+
+* Added a new function to widgets called "init" which is called upon initialization, before any of the widgets are applied.
+ * I added it to allow the "saveSort" widget to get the saved sort data (localStorage or cookie) before the initial sort was applied.
+ * The "saveSort" widget is still compatible with the original tablesorter, but the original version will call all of the widgets twice on initialization, if using the "saveSort" widget.
+ * New add widget format is as follows:
+
+ ```javascript
+ $.tablesorter.addWidget({
+ id: 'myWidget',
+ init: function(table, allWidgets, thisWidget){
+ // widget initialization code - this is only run ONCE
+ // but in this example I call the format function because
+ // I want to keep it backwards compatible with the original tablesorter
+ thisWidget.format(table, true);
+ },
+ format: function(table, initFlag) {
+ // widget code to apply to the table AFTER EACH SORT
+ // the initFlag is true when format is called for the first time, but
+ // only if it is called from the init function
+ }
+ });
+ ```
+
####Version 2.0.27 (2012-1-31)
* Added `sortReset` option
diff --git a/changelog.txt b/changelog.txt
index fe808c98..f7229c49 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,5 +1,30 @@
TableSorter Change Log
+Version 2.0.28 (2012-2-1)
+============================
+
+* Added a new function to widgets called "init" which is called upon initialization, before any of the widgets are applied.
+ * I added it to allow the "saveSort" widget to get the saved sort data (localStorage or cookie) before the initial sort was applied.
+ * The "saveSort" widget is still compatible with the original tablesorter, but the original version will call all of the widgets twice on initialization, if using the "saveSort" widget.
+ * New add widget format is as follows:
+
+ ```javascript
+ $.tablesorter.addWidget({
+ id: 'myWidget',
+ init: function(table, allWidgets, thisWidget){
+ // widget initialization code - this is only run ONCE
+ // but in this example I call the format function because
+ // I want to keep it backwards compatible with the original tablesorter
+ thisWidget.format(table, true);
+ },
+ format: function(table, initFlag) {
+ // widget code to apply to the table AFTER EACH SORT
+ // the initFlag is true when format is called for the first time, but
+ // only if it is called from the init function
+ }
+ });
+ ```
+
Version 2.0.27 (2012-1-31)
============================
diff --git a/docs/example-widget-savesort.html b/docs/example-widget-savesort.html
index 8f73c3e1..59459e97 100644
--- a/docs/example-widget-savesort.html
+++ b/docs/example-widget-savesort.html
@@ -24,7 +24,7 @@
$("table").tablesorter({
// use save sort widget
- widgets: ["saveSort"]
+ widgets: ["saveSort", "zebra"]
});
diff --git a/js/jquery.tablesorter.js b/js/jquery.tablesorter.js
index a9009f48..6cf3b9e9 100644
--- a/js/jquery.tablesorter.js
+++ b/js/jquery.tablesorter.js
@@ -1,6 +1,6 @@
/*
* TableSorter 2.0 - Client-side table sorting with ease!
-* Version 2.0.27
+* Version 2.0.28
* @requires jQuery v1.2.3
*
* Copyright (c) 2007 Christian Bach
@@ -76,7 +76,7 @@
* @author Christian Bach/christian.bach@polyester.se
* @contributor Rob Garrison/https://github.com/Mottie/tablesorter
*/
-(function($){
+!(function($){
$.extend({
tablesorter: new function(){
@@ -109,7 +109,7 @@
/* debuging utils */
function log(s) {
- if (typeof console !== "undefined" && typeof console.debug !== "undefined") {
+ if (typeof console !== "undefined" && typeof console.log !== "undefined") {
console.log(s);
} else {
alert(s);
@@ -266,6 +266,16 @@
return cache;
}
+ function initWidgets(table){
+ var i, w, l = widgets.length;
+ for (i = 0; i < l; i++) {
+ w = widgets[i];
+ if (w && w.hasOwnProperty('init')) {
+ w.init(table, widgets, w);
+ }
+ }
+ }
+
function getWidgetById(name) {
var i, w, l = widgets.length;
for (i = 0; i < l; i++) {
@@ -774,6 +784,8 @@
if ($.metadata && ($(this).metadata() && $(this).metadata().sortlist)) {
config.sortList = $(this).metadata().sortlist;
}
+ // initialize widgets
+ initWidgets(this);
// if user has supplied a sort list to constructor.
if (config.sortList.length > 0) {
$this.trigger("sorton", [config.sortList]);
diff --git a/js/jquery.tablesorter.min.js b/js/jquery.tablesorter.min.js
index a07bb3c0..b2664e57 100644
--- a/js/jquery.tablesorter.min.js
+++ b/js/jquery.tablesorter.min.js
@@ -1,7 +1,7 @@
/*
* TableSorter 2.0 - Client-side table sorting with ease!
-* Version 2.0.27 Minified using http://dean.edwards.name/packer/
+* Version 2.0.28 Minified using http://dean.edwards.name/packer/
* Copyright (c) 2007 Christian Bach
*/
-(function($){$.extend({tablesorter:new function(){var g=[],widgets=[],tbl;this.defaults={cssHeader:"header",cssAsc:"headerSortUp",cssDesc:"headerSortDown",cssChildRow:"expand-child",sortInitialOrder:"asc",sortMultiSortKey:"shiftKey",sortForce:null,sortAppend:null,sortLocaleCompare:false,textExtraction:"simple",parsers:{},widgets:[],widgetZebra:{css:["even","odd"]},headers:{},widthFixed:false,cancelSelection:true,sortList:[],headerList:[],dateFormat:"mmddyyyy",onRenderHeader:null,selectorHeaders:'thead th',tableClass:'tablesorter',debug:false};function log(s){if(typeof console!=="undefined"&&typeof console.debug!=="undefined"){console.log(s)}else{alert(s)}}function benchmark(s,d){log(s+","+(new Date().getTime()-d.getTime())+"ms")}this.benchmark=benchmark;function getElementText(a,b,c){var d="",te=a.textExtraction;if(!b){return""}if(!a.supportsTextContent){a.supportsTextContent=b.textContent||false}if(te==="simple"){if(a.supportsTextContent){d=b.textContent}else{if(b.childNodes[0]&&b.childNodes[0].hasChildNodes()){d=b.childNodes[0].innerHTML}else{d=b.innerHTML}}}else{if(typeof(te)==="function"){d=te(b)}else if(typeof(te)==="object"&&te.hasOwnProperty(c)){d=te[c](b)}else{d=$(b).text()}}return d}function getParserById(a){var i,l=g.length;for(i=0;i").each(function(a){this.column=header_index[this.parentNode.rowIndex+"-"+this.cellIndex];this.order=formatSortingOrder(checkHeaderOrder(b,a));this.count=this.order;if(checkHeaderMetadata(this)||checkHeaderOptions(b,a)||$(this).is('.sorter-false')){this.sortDisabled=true}this.lockedOrder=false;lock=checkHeaderLocked(b,a);if(typeof(lock)!=='undefined'&&lock!==false){this.order=this.lockedOrder=formatSortingOrder(lock)}if(!this.sortDisabled){$th=$(this).addClass(c.cssHeader);if(c.onRenderHeader){c.onRenderHeader.apply($th,[a])}}c.headerList[a]=this});if(c.debug){benchmark("Built headers:",time);log($tableHeaders)}return $tableHeaders}function checkCellColSpan(a,b,d){var i,cell,arr=[],r=a.tHead.rows,c=r[d].cells;for(i=0;i1){arr=arr.concat(checkCellColSpan(a,b,d++))}else{if(a.tHead.length===1||(cell.rowSpan>1||!r[d+1])){arr.push(cell)}}}return arr}function isValueInArray(v,a){var i,l=a.length;for(i=0;i');$("tr:first td",a.tBodies[0]).each(function(){c.append($('