From 40a236a7cc823161517b94df257f524b3995c53b Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Mon, 25 Jun 2012 11:19:56 +0100 Subject: [PATCH] Update: Remove use of $.browser since this is depricated in jQuery 1.8 and will be completely removed in jQuery 1.9. Instead we now use feature detection to determine if there is a browser bug with the width calculation of scrolling elements that needs to be worked around. This does unfortunatly increase the code size a bit - it is either this or using user agent string detection (which is exactly what is being removed from jQuery). Starting 1.9.3 development --- media/js/jquery.dataTables.js | 57 ++++++++++++++++++++++++++---- media/src/DataTables.js | 6 ++-- media/src/api/api.internal.js | 3 +- media/src/core/core.constructor.js | 3 ++ media/src/core/core.scrolling.js | 2 +- media/src/core/core.support.js | 27 ++++++++++++++ media/src/model/model.settings.js | 16 ++++++++- 7 files changed, 102 insertions(+), 12 deletions(-) diff --git a/media/js/jquery.dataTables.js b/media/js/jquery.dataTables.js index ae5d1750..88fd5d4e 100644 --- a/media/js/jquery.dataTables.js +++ b/media/js/jquery.dataTables.js @@ -1,7 +1,7 @@ /** * @summary DataTables * @description Paginate, search and sort HTML tables - * @version 1.9.2 + * @version 1.9.3.dev * @file jquery.dataTables.js * @author Allan Jardine (www.sprymedia.co.uk) * @contact www.sprymedia.co.uk/contact @@ -21,7 +21,7 @@ */ /*jslint evil: true, undef: true, browser: true */ -/*globals $, jQuery,_fnExternApiFunc,_fnInitialise,_fnInitComplete,_fnLanguageCompat,_fnAddColumn,_fnColumnOptions,_fnAddData,_fnCreateTr,_fnGatherData,_fnBuildHead,_fnDrawHead,_fnDraw,_fnReDraw,_fnAjaxUpdate,_fnAjaxParameters,_fnAjaxUpdateDraw,_fnServerParams,_fnAddOptionsHtml,_fnFeatureHtmlTable,_fnScrollDraw,_fnAdjustColumnSizing,_fnFeatureHtmlFilter,_fnFilterComplete,_fnFilterCustom,_fnFilterColumn,_fnFilter,_fnBuildSearchArray,_fnBuildSearchRow,_fnFilterCreateSearch,_fnDataToSearch,_fnSort,_fnSortAttachListener,_fnSortingClasses,_fnFeatureHtmlPaginate,_fnPageChange,_fnFeatureHtmlInfo,_fnUpdateInfo,_fnFeatureHtmlLength,_fnFeatureHtmlProcessing,_fnProcessingDisplay,_fnVisibleToColumnIndex,_fnColumnIndexToVisible,_fnNodeToDataIndex,_fnVisbleColumns,_fnCalculateEnd,_fnConvertToWidth,_fnCalculateColumnWidths,_fnScrollingWidthAdjust,_fnGetWidestNode,_fnGetMaxLenString,_fnStringToCss,_fnDetectType,_fnSettingsFromNode,_fnGetDataMaster,_fnGetTrNodes,_fnGetTdNodes,_fnEscapeRegex,_fnDeleteIndex,_fnReOrderIndex,_fnColumnOrdering,_fnLog,_fnClearTable,_fnSaveState,_fnLoadState,_fnCreateCookie,_fnReadCookie,_fnDetectHeader,_fnGetUniqueThs,_fnScrollBarWidth,_fnApplyToChildren,_fnMap,_fnGetRowData,_fnGetCellData,_fnSetCellData,_fnGetObjectDataFn,_fnSetObjectDataFn,_fnApplyColumnDefs,_fnBindAction,_fnCallbackReg,_fnCallbackFire,_fnJsonString,_fnRender,_fnNodeToColumnIndex,_fnInfoMacros*/ +/*globals $, jQuery,_fnExternApiFunc,_fnInitialise,_fnInitComplete,_fnLanguageCompat,_fnAddColumn,_fnColumnOptions,_fnAddData,_fnCreateTr,_fnGatherData,_fnBuildHead,_fnDrawHead,_fnDraw,_fnReDraw,_fnAjaxUpdate,_fnAjaxParameters,_fnAjaxUpdateDraw,_fnServerParams,_fnAddOptionsHtml,_fnFeatureHtmlTable,_fnScrollDraw,_fnAdjustColumnSizing,_fnFeatureHtmlFilter,_fnFilterComplete,_fnFilterCustom,_fnFilterColumn,_fnFilter,_fnBuildSearchArray,_fnBuildSearchRow,_fnFilterCreateSearch,_fnDataToSearch,_fnSort,_fnSortAttachListener,_fnSortingClasses,_fnFeatureHtmlPaginate,_fnPageChange,_fnFeatureHtmlInfo,_fnUpdateInfo,_fnFeatureHtmlLength,_fnFeatureHtmlProcessing,_fnProcessingDisplay,_fnVisibleToColumnIndex,_fnColumnIndexToVisible,_fnNodeToDataIndex,_fnVisbleColumns,_fnCalculateEnd,_fnConvertToWidth,_fnCalculateColumnWidths,_fnScrollingWidthAdjust,_fnGetWidestNode,_fnGetMaxLenString,_fnStringToCss,_fnDetectType,_fnSettingsFromNode,_fnGetDataMaster,_fnGetTrNodes,_fnGetTdNodes,_fnEscapeRegex,_fnDeleteIndex,_fnReOrderIndex,_fnColumnOrdering,_fnLog,_fnClearTable,_fnSaveState,_fnLoadState,_fnCreateCookie,_fnReadCookie,_fnDetectHeader,_fnGetUniqueThs,_fnScrollBarWidth,_fnApplyToChildren,_fnMap,_fnGetRowData,_fnGetCellData,_fnSetCellData,_fnGetObjectDataFn,_fnSetObjectDataFn,_fnApplyColumnDefs,_fnBindAction,_fnCallbackReg,_fnCallbackFire,_fnJsonString,_fnRender,_fnNodeToColumnIndex,_fnInfoMacros,_fnBrowserDetect*/ (/** @lends */function($, window, document, undefined) { /** @@ -3098,7 +3098,7 @@ iWidth, aApplied=[], iSanityWidth, nScrollFootInner = (o.nTFoot !== null) ? o.nScrollFoot.getElementsByTagName('div')[0] : null, nScrollFootTable = (o.nTFoot !== null) ? nScrollFootInner.getElementsByTagName('table')[0] : null, - ie67 = $.browser.msie && $.browser.version <= 7; + ie67 = o.oBrowser.bScrollOversize; /* * 1. Re-create the table inside the scrolling div @@ -4779,6 +4779,33 @@ return (bArr ? "[" : "{") + json + (bArr ? "]" : "}"); }; + + /** + * From some browsers (specifically IE6/7) we need special handling to work around browser + * bugs - this function is used to detect when these workarounds are needed. + * @param {object} oSettings dataTables settings object + * @memberof DataTable#oApi + */ + function _fnBrowserDetect( oSettings ) + { + /* IE6/7 will oversize a width 100% element inside a scrolling element, to include the + * width of the scrollbar, while other browsers ensure the inner element is contained + * without forcing scrolling + */ + var n = $( + '
'+ + '
'+ + '
'+ + '
'+ + '
')[0]; + + document.body.appendChild( n ); + oSettings.oBrowser.bScrollOversize = $('#DT_BrowserTest', n)[0].offsetWidth === 100 ? true : false; + document.body.removeChild( n ); + + alert( oSettings.oBrowser.bScrollOversize ); + } + @@ -6171,7 +6198,8 @@ "_fnJsonString": _fnJsonString, "_fnRender": _fnRender, "_fnNodeToColumnIndex": _fnNodeToColumnIndex, - "_fnInfoMacros": _fnInfoMacros + "_fnInfoMacros": _fnInfoMacros, + "_fnBrowserDetect": _fnBrowserDetect }; $.extend( DataTable.ext.oApi, this.oApi ); @@ -6560,6 +6588,9 @@ * Cache the header, body and footer as required, creating them if needed */ + /* Browser support detection */ + _fnBrowserDetect( oSettings ); + // Work around for Webkit bug 83867 - store the caption-side before removing from doc var captions = $(this).children('caption').each( function () { this._captionSide = $(this).css('caption-side'); @@ -6736,7 +6767,7 @@ * @type string * @default Version number */ - DataTable.version = "1.9.2"; + DataTable.version = "1.9.3.dev"; /** * Private data store, containing all of the settings objects that are created for the @@ -10544,11 +10575,25 @@ * Information callback function. See * {@link DataTable.defaults.fnInfoCallback} * @type function - * @default + * @default null */ "fnInfoCallback": null }, + /** + * Browser support parameters + * @namespace + */ + "oBrowser": { + /** + * Indicate if the browser incorrectly calculates width:100% inside a + * scrolling element (IE6/7) + * @type boolean + * @default false + */ + "bScrollOversize": false + }, + /** * Array referencing the nodes which are used for the features. The * parameters of this object match what is allowed by sDom - i.e. diff --git a/media/src/DataTables.js b/media/src/DataTables.js index a72368f8..9f766eb7 100644 --- a/media/src/DataTables.js +++ b/media/src/DataTables.js @@ -1,7 +1,7 @@ /** * @summary DataTables * @description Paginate, search and sort HTML tables - * @version 1.9.2 + * @version 1.9.3.dev * @file jquery.dataTables.js * @author Allan Jardine (www.sprymedia.co.uk) * @contact www.sprymedia.co.uk/contact @@ -21,7 +21,7 @@ */ /*jslint evil: true, undef: true, browser: true */ -/*globals $, jQuery,_fnExternApiFunc,_fnInitialise,_fnInitComplete,_fnLanguageCompat,_fnAddColumn,_fnColumnOptions,_fnAddData,_fnCreateTr,_fnGatherData,_fnBuildHead,_fnDrawHead,_fnDraw,_fnReDraw,_fnAjaxUpdate,_fnAjaxParameters,_fnAjaxUpdateDraw,_fnServerParams,_fnAddOptionsHtml,_fnFeatureHtmlTable,_fnScrollDraw,_fnAdjustColumnSizing,_fnFeatureHtmlFilter,_fnFilterComplete,_fnFilterCustom,_fnFilterColumn,_fnFilter,_fnBuildSearchArray,_fnBuildSearchRow,_fnFilterCreateSearch,_fnDataToSearch,_fnSort,_fnSortAttachListener,_fnSortingClasses,_fnFeatureHtmlPaginate,_fnPageChange,_fnFeatureHtmlInfo,_fnUpdateInfo,_fnFeatureHtmlLength,_fnFeatureHtmlProcessing,_fnProcessingDisplay,_fnVisibleToColumnIndex,_fnColumnIndexToVisible,_fnNodeToDataIndex,_fnVisbleColumns,_fnCalculateEnd,_fnConvertToWidth,_fnCalculateColumnWidths,_fnScrollingWidthAdjust,_fnGetWidestNode,_fnGetMaxLenString,_fnStringToCss,_fnDetectType,_fnSettingsFromNode,_fnGetDataMaster,_fnGetTrNodes,_fnGetTdNodes,_fnEscapeRegex,_fnDeleteIndex,_fnReOrderIndex,_fnColumnOrdering,_fnLog,_fnClearTable,_fnSaveState,_fnLoadState,_fnCreateCookie,_fnReadCookie,_fnDetectHeader,_fnGetUniqueThs,_fnScrollBarWidth,_fnApplyToChildren,_fnMap,_fnGetRowData,_fnGetCellData,_fnSetCellData,_fnGetObjectDataFn,_fnSetObjectDataFn,_fnApplyColumnDefs,_fnBindAction,_fnCallbackReg,_fnCallbackFire,_fnJsonString,_fnRender,_fnNodeToColumnIndex,_fnInfoMacros*/ +/*globals $, jQuery,_fnExternApiFunc,_fnInitialise,_fnInitComplete,_fnLanguageCompat,_fnAddColumn,_fnColumnOptions,_fnAddData,_fnCreateTr,_fnGatherData,_fnBuildHead,_fnDrawHead,_fnDraw,_fnReDraw,_fnAjaxUpdate,_fnAjaxParameters,_fnAjaxUpdateDraw,_fnServerParams,_fnAddOptionsHtml,_fnFeatureHtmlTable,_fnScrollDraw,_fnAdjustColumnSizing,_fnFeatureHtmlFilter,_fnFilterComplete,_fnFilterCustom,_fnFilterColumn,_fnFilter,_fnBuildSearchArray,_fnBuildSearchRow,_fnFilterCreateSearch,_fnDataToSearch,_fnSort,_fnSortAttachListener,_fnSortingClasses,_fnFeatureHtmlPaginate,_fnPageChange,_fnFeatureHtmlInfo,_fnUpdateInfo,_fnFeatureHtmlLength,_fnFeatureHtmlProcessing,_fnProcessingDisplay,_fnVisibleToColumnIndex,_fnColumnIndexToVisible,_fnNodeToDataIndex,_fnVisbleColumns,_fnCalculateEnd,_fnConvertToWidth,_fnCalculateColumnWidths,_fnScrollingWidthAdjust,_fnGetWidestNode,_fnGetMaxLenString,_fnStringToCss,_fnDetectType,_fnSettingsFromNode,_fnGetDataMaster,_fnGetTrNodes,_fnGetTdNodes,_fnEscapeRegex,_fnDeleteIndex,_fnReOrderIndex,_fnColumnOrdering,_fnLog,_fnClearTable,_fnSaveState,_fnLoadState,_fnCreateCookie,_fnReadCookie,_fnDetectHeader,_fnGetUniqueThs,_fnScrollBarWidth,_fnApplyToChildren,_fnMap,_fnGetRowData,_fnGetCellData,_fnSetCellData,_fnGetObjectDataFn,_fnSetObjectDataFn,_fnApplyColumnDefs,_fnBindAction,_fnCallbackReg,_fnCallbackFire,_fnJsonString,_fnRender,_fnNodeToColumnIndex,_fnInfoMacros,_fnBrowserDetect*/ (/** @lends */function($, window, document, undefined) { /** @@ -93,7 +93,7 @@ * @type string * @default Version number */ - DataTable.version = "1.9.2"; + DataTable.version = "1.9.3.dev"; /** * Private data store, containing all of the settings objects that are created for the diff --git a/media/src/api/api.internal.js b/media/src/api/api.internal.js index 1cbc8ee1..c85f57c9 100644 --- a/media/src/api/api.internal.js +++ b/media/src/api/api.internal.js @@ -113,7 +113,8 @@ this.oApi = { "_fnJsonString": _fnJsonString, "_fnRender": _fnRender, "_fnNodeToColumnIndex": _fnNodeToColumnIndex, - "_fnInfoMacros": _fnInfoMacros + "_fnInfoMacros": _fnInfoMacros, + "_fnBrowserDetect": _fnBrowserDetect }; $.extend( DataTable.ext.oApi, this.oApi ); diff --git a/media/src/core/core.constructor.js b/media/src/core/core.constructor.js index ed0756d9..9f21e1ea 100644 --- a/media/src/core/core.constructor.js +++ b/media/src/core/core.constructor.js @@ -371,6 +371,9 @@ _fnSortingClasses( oSettings ); * Cache the header, body and footer as required, creating them if needed */ +/* Browser support detection */ +_fnBrowserDetect( oSettings ); + // Work around for Webkit bug 83867 - store the caption-side before removing from doc var captions = $(this).children('caption').each( function () { this._captionSide = $(this).css('caption-side'); diff --git a/media/src/core/core.scrolling.js b/media/src/core/core.scrolling.js index 1889fd9f..45ddd3be 100644 --- a/media/src/core/core.scrolling.js +++ b/media/src/core/core.scrolling.js @@ -194,7 +194,7 @@ function _fnScrollDraw ( o ) iWidth, aApplied=[], iSanityWidth, nScrollFootInner = (o.nTFoot !== null) ? o.nScrollFoot.getElementsByTagName('div')[0] : null, nScrollFootTable = (o.nTFoot !== null) ? nScrollFootInner.getElementsByTagName('table')[0] : null, - ie67 = $.browser.msie && $.browser.version <= 7; + ie67 = o.oBrowser.bScrollOversize; /* * 1. Re-create the table inside the scrolling div diff --git a/media/src/core/core.support.js b/media/src/core/core.support.js index e3597c00..f00cf03e 100644 --- a/media/src/core/core.support.js +++ b/media/src/core/core.support.js @@ -314,3 +314,30 @@ var _fnJsonString = (window.JSON) ? JSON.stringify : function( o ) return (bArr ? "[" : "{") + json + (bArr ? "]" : "}"); }; + +/** + * From some browsers (specifically IE6/7) we need special handling to work around browser + * bugs - this function is used to detect when these workarounds are needed. + * @param {object} oSettings dataTables settings object + * @memberof DataTable#oApi + */ +function _fnBrowserDetect( oSettings ) +{ + /* IE6/7 will oversize a width 100% element inside a scrolling element, to include the + * width of the scrollbar, while other browsers ensure the inner element is contained + * without forcing scrolling + */ + var n = $( + '
'+ + '
'+ + '
'+ + '
'+ + '
')[0]; + + document.body.appendChild( n ); + oSettings.oBrowser.bScrollOversize = $('#DT_BrowserTest', n)[0].offsetWidth === 100 ? true : false; + document.body.removeChild( n ); + + alert( oSettings.oBrowser.bScrollOversize ); +} + diff --git a/media/src/model/model.settings.js b/media/src/model/model.settings.js index 6d66e9e6..27254799 100644 --- a/media/src/model/model.settings.js +++ b/media/src/model/model.settings.js @@ -223,11 +223,25 @@ DataTable.models.oSettings = { * Information callback function. See * {@link DataTable.defaults.fnInfoCallback} * @type function - * @default + * @default null */ "fnInfoCallback": null }, + /** + * Browser support parameters + * @namespace + */ + "oBrowser": { + /** + * Indicate if the browser incorrectly calculates width:100% inside a + * scrolling element (IE6/7) + * @type boolean + * @default false + */ + "bScrollOversize": false + }, + /** * Array referencing the nodes which are used for the features. The * parameters of this object match what is allowed by sDom - i.e.