Resizable: add resizable_throttle option to throttle mousemove event. Fixes #662

This commit is contained in:
Mottie 2014-07-03 23:04:15 -05:00
parent b83f67a965
commit 10b0f4e7f2
2 changed files with 50 additions and 9 deletions

View File

@ -1680,6 +1680,8 @@ $(function(){
resizable_addLastColumn: false, resizable_addLastColumn: false,
// Add the starting & reset header widths // Add the starting & reset header widths
resizable_widths : [], resizable_widths : [],
// throttle resizable event (needed for slow browsers)
resizable_throttle : false,
// *** savesort widget *** // *** savesort widget ***
// if false, the sort will not be saved for next page reload // if false, the sort will not be saved for next page reload
@ -2879,6 +2881,33 @@ $('table').trigger('search', false);</pre></div>
<td><a href="example-widget-resizable.html">Example</a></td> <td><a href="example-widget-resizable.html">Example</a></td>
</tr> </tr>
<tr id="widget-resizable-throttle">
<td><a href="#" class="permalink">resizable_throttle</a></td>
<td>Boolean</td>
<td>false</td>
<td>
Resizable widget: Set this option to throttle the resizable events (<span class="version">v2.17.4</span>).
<div class="collapsible">
<br>
When <code>false</code> throttling of the mousemove (resizing) event is not applied.<br>
<br>
Set this option to either <code>true</code> for a default 5 millisecond delay, or set it to any number less than 10 to adjust the throttling delay that is applied to the mousemove/resizing event.<br>
<br>
Use the <a href="#widget-resizable-throttle"><code>&quot;resizable_widths&quot;</code></a> option as follows:
<pre class="prettyprint lang-js">$(function(){
$("table").tablesorter({
widgets: ["resizable"],
widgetOptions : {
// set to true for a default 5ms throttling delay
// or set to a number < 10 (more than that makes the resizing adjustment unusable
resizable_throttle : true
}
});
});</pre></div>
</td>
<td></td>
</tr>
<tr id="widget-savesort"> <tr id="widget-savesort">
<td><a href="#" class="permalink">saveSort</a></td> <td><a href="#" class="permalink">saveSort</a></td>
<td>Boolean</td> <td>Boolean</td>

View File

@ -1506,19 +1506,31 @@ ts.addWidget({
options: { options: {
resizable : true, resizable : true,
resizable_addLastColumn : false, resizable_addLastColumn : false,
resizable_widths : [] resizable_widths : [],
resizable_throttle : false // set to true (5ms) or any number 0-10 range
}, },
format: function(table, c, wo) { format: function(table, c, wo) {
if (c.$table.hasClass('hasResizable')) { return; } if (c.$table.hasClass('hasResizable')) { return; }
c.$table.addClass('hasResizable'); c.$table.addClass('hasResizable');
ts.resizableReset(table, true); // set default widths ts.resizableReset(table, true); // set default widths
var $rows, $columns, $column, column, var $rows, $columns, $column, column, timer,
storedSizes = {}, storedSizes = {},
$table = c.$table, $table = c.$table,
mouseXPosition = 0, mouseXPosition = 0,
$target = null, $target = null,
$next = null, $next = null,
fullWidth = Math.abs($table.parent().width() - $table.width()) < 20, fullWidth = Math.abs($table.parent().width() - $table.width()) < 20,
mouseMove = function(event){
if (mouseXPosition === 0 || !$target) { return; }
// resize columns
var leftEdge = event.pageX - mouseXPosition,
targetWidth = $target.width();
$target.width( targetWidth + leftEdge );
if ($target.width() !== targetWidth && fullWidth) {
$next.width( $next.width() - leftEdge );
}
mouseXPosition = event.pageX;
},
stopResize = function() { stopResize = function() {
if (ts.storage && $target && $next) { if (ts.storage && $target && $next) {
storedSizes = {}; storedSizes = {};
@ -1587,14 +1599,14 @@ ts.addWidget({
.bind('mousemove.tsresize', function(event) { .bind('mousemove.tsresize', function(event) {
// ignore mousemove if no mousedown // ignore mousemove if no mousedown
if (mouseXPosition === 0 || !$target) { return; } if (mouseXPosition === 0 || !$target) { return; }
// resize columns if (wo.resizable_throttle) {
var leftEdge = event.pageX - mouseXPosition, clearTimeout(timer);
targetWidth = $target.width(); timer = setTimeout(function(){
$target.width( targetWidth + leftEdge ); mouseMove(event);
if ($target.width() !== targetWidth && fullWidth) { }, isNaN(wo.resizable_throttle) ? 5 : wo.resizable_throttle );
$next.width( $next.width() - leftEdge ); } else {
mouseMove(event);
} }
mouseXPosition = event.pageX;
}) })
.bind('mouseup.tsresize', function() { .bind('mouseup.tsresize', function() {
stopResize(); stopResize();