Parser: update input/select elements binding

This commit is contained in:
Mottie 2014-07-08 21:27:22 -05:00
parent 24d1865df4
commit 98d47ff3bb

View File

@ -68,13 +68,13 @@
// This method only works with jQuery 1.7+ // This method only works with jQuery 1.7+
// you can change it to use delegate (v1.4.3+) or live (v1.3+) as desired // you can change it to use delegate (v1.4.3+) or live (v1.3+) as desired
// if this code interferes somehow, target the specific table $('#mytable'), instead of $('table') // if this code interferes somehow, target the specific table $('#mytable'), instead of $('table')
$(window).load(function(){ $(function(){
$('table').on('tablesorter-initialized', function(){
// this flag prevents the updateCell event from being spammed // this flag prevents the updateCell event from being spammed
// it happens when you modify input text and hit enter // it happens when you modify input text and hit enter
var alreadyUpdating = false, var alreadyUpdating = false;
t = $.tablesorter.css.table || 'tablesorter';
// bind to .tablesorter (default class name) // bind to .tablesorter (default class name)
$('.' + t).find('tbody').on('change', 'select, input', function(e){ $(this).children('tbody').on('change', 'select, input', function(e){
if (!alreadyUpdating) { if (!alreadyUpdating) {
var $tar = $(e.target), var $tar = $(e.target),
$cell = $tar.closest('td'), $cell = $tar.closest('td'),
@ -88,11 +88,13 @@
return false; return false;
} }
alreadyUpdating = true; alreadyUpdating = true;
$table.trigger('updateCell', [ $tar.closest('td'), resort ]); $table.trigger('updateCell', [ $tar.closest('td'), resort, function(){
updateServer(e, $table, $tar); updateServer(e, $table, $tar);
setTimeout(function(){ alreadyUpdating = false; }, 10); setTimeout(function(){ alreadyUpdating = false; }, 10);
} ]);
} }
}); });
}); });
});
})(jQuery); })(jQuery);