From bf553daf8d184fd16331c60c28dc05e706039df8 Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Mon, 20 Feb 2012 16:21:42 -0600 Subject: [PATCH] fix widget init code - fixes #28 --- README.markdown | 5 +++++ changelog.txt | 6 ++++++ docs/example-widget-savesort.html | 10 +++++++++- js/jquery.tablesorter.js | 21 +++++++++------------ js/jquery.tablesorter.min.js | 4 ++-- package.json | 2 +- 6 files changed, 32 insertions(+), 16 deletions(-) diff --git a/README.markdown b/README.markdown index 6dae5194..a079a039 100644 --- a/README.markdown +++ b/README.markdown @@ -34,6 +34,11 @@ 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.29 (2012-2-20) + +* Fixed a problem with the addWidget init function which apparently was always being called, even if you didn't want it! Fix for [issue #28](https://github.com/Mottie/tablesorter/issues/28). Thanks to thezoggy for helping with troubleshooting! +* Minor cleanup of sorting class names code. + #### Version 2.0.28.1 (2012-2-16) * Modified the plugin pager to ignore child rows. Fix for [issue #27](https://github.com/Mottie/tablesorter/issues/27). diff --git a/changelog.txt b/changelog.txt index 07518489..3ea5756f 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,11 @@ TableSorter Change Log +Version 2.0.29 (2012-2-20) +============================ + +* Fixed a problem with the addWidget init function which apparently was always being called, even if you didn't want it! Fix for [issue #28](https://github.com/Mottie/tablesorter/issues/28). Thanks to thezoggy for helping with troubleshooting! +* Minor cleanup of sorting class names code. + Version 2.0.28.1 (2012-2-16) ============================ diff --git a/docs/example-widget-savesort.html b/docs/example-widget-savesort.html index 59459e97..5319dbde 100644 --- a/docs/example-widget-savesort.html +++ b/docs/example-widget-savesort.html @@ -5,7 +5,7 @@ jQuery plugin: Tablesorter 2.0 - Save Sort Widget - + @@ -109,6 +109,14 @@ +

Page Header

+
+
+<link rel="stylesheet" href="css/blue/style.css">
+<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
+<script src="js/jquery.tablesorter.min.js"></script>
+<script src="js/jquery.tablesorter.widgets.min.js"></script>
+

Javascript


diff --git a/js/jquery.tablesorter.js b/js/jquery.tablesorter.js
index 6cf3b9e9..3b589b99 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.28
+* Version 2.0.29
 * @requires jQuery v1.2.3
 *
 * Copyright (c) 2007 Christian Bach
@@ -267,11 +267,10 @@
 			}
 
 			function initWidgets(table){
-				var i, w, l = widgets.length;
+				var i, w = table.config.widgets, l = w.length;
 				for (i = 0; i < l; i++) {
-					w = widgets[i];
-					if (w && w.hasOwnProperty('init')) {
-						w.init(table, widgets, w);
+					if (w[i] && w[i].hasOwnProperty('init')) {
+						w[i].init(table, widgets, w[i]);
 					}
 				}
 			}
@@ -461,10 +460,10 @@
 				return false;
 			}
 
-			function setHeadersCss(table, $headers, list, css) {
+			function setHeadersCss(table, $headers, list) {
+				var h = [], i, l, css = [table.config.cssDesc, table.config.cssAsc];
 				// remove all header information
 				$headers.removeClass(css[0]).removeClass(css[1]);
-				var h = [], i, l;
 				$headers.each(function (offset) {
 					if (!this.sortDisabled) {
 						h[this.column] = $(this);
@@ -616,7 +615,7 @@
 					if (!this.tHead || !this.tBodies) { return; }
 					// declare
 					var $this, $document, $headers, cache, config, shiftDown = 0,
-					sortOrder, sortCSS, totalRows, $cell, i, j, a, s, o;
+					sortOrder, totalRows, $cell, i, j, a, s, o;
 					// new blank config object
 					this.config = {};
 					// merge and extend.
@@ -633,8 +632,6 @@
 					this.config.string = { max: 1, 'max+': 1, 'max-': -1, none: 0 };
 					// build the cache for the tbody cells
 					cache = buildCache(this);
-					// get the css class names, could be done else where.
-					sortCSS = [config.cssDesc, config.cssAsc];
 					// fixate columns if the users supplies the fixedWidth option
 					fixColumnWidth(this);
 					// apply event handling to headers
@@ -702,7 +699,7 @@
 							$this.trigger("sortBegin", tbl[0]);
 							setTimeout(function () {
 								// set css for headers
-								setHeadersCss($this[0], $headers, config.sortList, sortCSS);
+								setHeadersCss($this[0], $headers, config.sortList);
 								appendToTable($this[0], multisort($this[0], config.sortList, cache));
 							}, 1);
 							// stop normal event by returning false
@@ -767,7 +764,7 @@
 						// update header count index
 						updateHeaderSortCount(this, sortList);
 						// set css for headers
-						setHeadersCss(this, $headers, sortList, sortCSS);
+						setHeadersCss(this, $headers, sortList);
 						// sort the table and append it to the dom
 						appendToTable(this, multisort(this, sortList, cache));
 					})
diff --git a/js/jquery.tablesorter.min.js b/js/jquery.tablesorter.min.js
index b2664e57..1c08919d 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.28 Minified using http://dean.edwards.name/packer/
+* Version 2.0.29 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.log!=="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($('').css('width',$(this).width()))});$(a).prepend(c)}}function updateHeaderSortCount(a,b){var i,s,o,c=a.config,l=b.length;for(i=0;ib)?1:-1}catch(er){return 0}}function sortTextDesc(a,b){if(a===''){return 1}if(b===''){return-1}if(a===b){return 0}if($.data(tbl[0],"tablesorter").sortLocaleCompare){return b.localeCompare(a)}return-sortText(a,b)}function getTextValue(a,b,d){if(b){var i,l=a.length,n=b+d;for(i=0;i=2){config.sortList.splice(j,1);o.count=0}}}}else{if(this.order<2){config.sortList.push([i,this.order])}}}if(config.sortAppend!==null){a=config.sortAppend;for(j=0;j0){c.trigger("sorton",[config.sortList])}else{applyWidget(this)}})};this.addParser=function(b){var i,l=g.length,a=true;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($('').css('width',$(this).width()))});$(a).prepend(c)}}function updateHeaderSortCount(a,b){var i,s,o,c=a.config,l=b.length;for(i=0;ib)?1:-1}catch(er){return 0}}function sortTextDesc(a,b){if(a===''){return 1}if(b===''){return-1}if(a===b){return 0}if($.data(tbl[0],"tablesorter").sortLocaleCompare){return b.localeCompare(a)}return-sortText(a,b)}function getTextValue(a,b,d){if(b){var i,l=a.length,n=b+d;for(i=0;i=2){config.sortList.splice(j,1);o.count=0}}}}else{if(this.order<2){config.sortList.push([i,this.order])}}}if(config.sortAppend!==null){a=config.sortAppend;for(j=0;j0){c.trigger("sorton",[config.sortList])}else{applyWidget(this)}})};this.addParser=function(b){var i,l=g.length,a=true;for(i=0;i