diff --git a/.datatables-commit-sync b/.datatables-commit-sync index 9d0b2736..f1015efb 100644 --- a/.datatables-commit-sync +++ b/.datatables-commit-sync @@ -1 +1 @@ -6ce86aedafd9cdc882b15c8fa069a156791ede89 +8401eab9328f17b363d5b693bd65caecd7a0c994 diff --git a/media/js/jquery.dataTables.js b/media/js/jquery.dataTables.js index 9eecbea4..6f82ade4 100644 --- a/media/js/jquery.dataTables.js +++ b/media/js/jquery.dataTables.js @@ -356,22 +356,30 @@ /** * Adjust the table column widths for new data. Note: you would probably want to * do a redraw after calling this function! - * @param {object} oSettings dataTables settings object + * @param {object} settings dataTables settings object * @memberof DataTable#oApi */ - function _fnAdjustColumnSizing ( oSettings ) + function _fnAdjustColumnSizing ( settings ) { /* Not interested in doing column width calculation if auto-width is disabled */ - if ( oSettings.oFeatures.bAutoWidth !== false ) + if ( settings.oFeatures.bAutoWidth !== false ) { - _fnCalculateColumnWidths( oSettings ); - for ( var i=0 , iLen=oSettings.aoColumns.length ; i 0 ) { - oSettings.aoColumns[i].sWidth = _fnStringToCss( iWidth ); + column.sWidth = _fnStringToCss( iWidth ); } iCorrector++; } } var cssWidth = $(nCalcTmp).css('width'); - oSettings.nTable.style.width = (cssWidth.indexOf('%') !== -1) ? + table.style.width = (cssWidth.indexOf('%') !== -1) ? cssWidth : _fnStringToCss( $(nCalcTmp).outerWidth() ); nCalcTmp.parentNode.removeChild( nCalcTmp ); } if ( widthAttr ) { - oSettings.nTable.style.width = _fnStringToCss( widthAttr ); + table.style.width = _fnStringToCss( widthAttr ); - if ( ! oSettings._attachedResizing && - (oSettings.oScroll.sY !== '' || oSettings.oScroll.sX !== '') ) + if ( ! oSettings._reszEvt ) { - $(window).bind('resize.DT-'+oSettings.sInstance, function () { - _fnScrollDraw( oSettings ); - } ); - oSettings._attachedResizing = true; + $(window).bind('resize.DT-'+oSettings.sInstance, throttle( function () { + _fnAdjustColumnSizing( oSettings ); + } ) ); + + oSettings._reszEvt = true; } } } + // @todo Move into a private functions file or make a proper DT function of it + function throttle( fn ) { + var + frequency = 200, + last, + timer; + + return function () { + var + now = +new Date(), + args = arguments; + + if ( last && now < last + frequency ) { + clearTimeout( timer ); + + timer = setTimeout( function () { + last = now; + fn(); + }, frequency ); + } + else { + last = now; + fn(); + } + }; + } + + /** * Adjust a table's width to take account of scrolling * @param {object} oSettings dataTables settings object