fixed destroy/remove widget issues

This commit is contained in:
Mottie 2013-01-04 11:00:48 -06:00
parent 5c378ec2fa
commit 3e9b5d56ce
2 changed files with 24 additions and 18 deletions

View File

@ -867,30 +867,32 @@
};
ts.destroy = function(table, removeClasses, callback){
var $t = $(table), c = table.config,
$h = $t.find('thead:first');
// clear flag in case the plugin is initialized again
table.hasInitialized = false;
// remove widget added rows
$h.find('tr:not(.' + c.cssHeaderRow + ')').remove();
// remove resizer widget stuff
$h.find('.tablesorter-resizer').remove();
if (!table.hasInitialized) { return; }
// remove all widgets
ts.refreshWidgets(table, true, true);
var $t = $(table), c = table.config,
$h = $t.find('thead:first'),
$r = $h.find('tr.' + c.cssHeaderRow).removeClass(c.cssHeaderRow),
$f = $t.find('tfoot:first > tr').children('th, td');
// remove widget added rows, just in case
$h.find('tr').not($r).remove();
// disable tablesorter
$t
.removeData('tablesorter')
.unbind('sortReset update updateCell addRows sorton appendCache applyWidgetId applyWidgets refreshWidgets destroy mouseup mouseleave')
.find('.' + c.cssHeader)
.unbind('click mousedown mousemove mouseup')
c.$headers.add($f)
.removeClass(c.cssHeader + ' ' + c.cssAsc + ' ' + c.cssDesc)
.find('.tablesorter-header-inner').each(function(){
if (c.cssIcon !== '') { $(this).find('.' + c.cssIcon).remove(); }
$(this).replaceWith( $(this).contents() );
.removeAttr('data-column');
$r.find(c.selectorSort).unbind('mousedown.tablesorter mouseup.tablesorter');
// restore headers
$r.children().each(function(i){
$(this).html( c.headerContent[i] );
});
if (removeClasses !== false) {
$t.removeClass(c.tableClass);
$t.removeClass(c.tableClass + ' tablesorter-' + c.theme);
}
// clear flag in case the plugin is initialized again
table.hasInitialized = false;
if (typeof callback === 'function') {
callback(table);
}

View File

@ -81,7 +81,8 @@ $.tablesorter.storage = function(table, key, val){
v = (d !== 0) ? $.parseJSON(k[d]) || {} : {};
}
}
if (val && JSON && JSON.hasOwnProperty('stringify')){
// allow val to be an empty string to
if ((val || val === '') && window.JSON && JSON.hasOwnProperty('stringify')){
// add unique identifiers = url pathname > table ID/index on page > data
if (!v[url]) {
v[url] = {};
@ -96,7 +97,7 @@ $.tablesorter.storage = function(table, key, val){
document.cookie = key + '=' + (JSON.stringify(v)).replace(/\"/g,'\"') + '; expires=' + d.toGMTString() + '; path=/';
}
} else {
return ( v && v.hasOwnProperty(url) && v[url].hasOwnProperty(id) ) ? v[url][id] : {};
return v && v[url] ? v[url][id] : {};
}
};
@ -263,6 +264,8 @@ $.tablesorter.addWidget({
var k, $tb,
b = c.$tbodies,
rmv = (c.widgetOptions.columns || [ "primary", "secondary", "tertiary" ]).join(' ');
c.$headers.removeClass(rmv);
$(table).children('tfoot').children('tr').children('th, td').removeClass(rmv);
for (k = 0; k < b.length; k++ ){
$tb = $.tablesorter.processTbody(table, b.eq(k), true); // remove tbody
$tb.children('tr').each(function(){
@ -679,7 +682,7 @@ $.tablesorter.addWidget({
innr = '.tablesorter-header-inner',
firstRow = hdrCells.eq(0).parent(),
tfoot = $table.find('tfoot'),
t2 = $table.clone(), // clone table, but don't remove id... the table might be styled by css
t2 = wo.$sticky = $table.clone(), // clone table, but don't remove id... the table might be styled by css
// clone the entire thead - seems to work in IE8+
stkyHdr = t2.children('thead:first')
.addClass(css)
@ -791,6 +794,7 @@ $.tablesorter.addWidget({
.removeClass('hasStickyHeaders')
.unbind('sortEnd.tsSticky pagerComplete.tsSticky')
.find('.' + css).remove();
if (wo.$sticky) { wo.$sticky.remove(); } // remove cloned thead
$(window).unbind('scroll.tsSticky resize.tsSticky');
}
});