From 88932adb92c6794eb2ebf84e2907588c777dad0c Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Sun, 7 Aug 2011 14:57:06 +0100 Subject: [PATCH] Fix: The scrollbar width calculation could sometimes be wrong when trying to calculate the size of the bar due to CSS styles. The inner P element could be given padding for example which would result in the scrollbar width being wrong and thus any calculations later on witht he scrollbar width would be incorrect. --- media/js/jquery.dataTables.js | 38 ++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/media/js/jquery.dataTables.js b/media/js/jquery.dataTables.js index 5f3db429..85fec435 100644 --- a/media/js/jquery.dataTables.js +++ b/media/js/jquery.dataTables.js @@ -6508,32 +6508,34 @@ */ function _fnScrollBarWidth () { - var inner = document.createElement('p'); + var inner = document.createElement('p'); var style = inner.style; - style.width = "100%"; - style.height = "200px"; + style.width = "100%"; + style.height = "200px"; + style.padding = "0px"; - var outer = document.createElement('div'); + var outer = document.createElement('div'); style = outer.style; - style.position = "absolute"; - style.top = "0px"; - style.left = "0px"; - style.visibility = "hidden"; - style.width = "200px"; - style.height = "150px"; - style.overflow = "hidden"; - outer.appendChild(inner); + style.position = "absolute"; + style.top = "0px"; + style.left = "0px"; + style.visibility = "hidden"; + style.width = "200px"; + style.height = "150px"; + style.padding = "0px"; + style.overflow = "hidden"; + outer.appendChild(inner); - document.body.appendChild(outer); - var w1 = inner.offsetWidth; - outer.style.overflow = 'scroll'; - var w2 = inner.offsetWidth; + document.body.appendChild(outer); + var w1 = inner.offsetWidth; + outer.style.overflow = 'scroll'; + var w2 = inner.offsetWidth; if ( w1 == w2 ) { - w2 = outer.clientWidth; + w2 = outer.clientWidth; } - document.body.removeChild(outer); + document.body.removeChild(outer); return (w1 - w2); }