1
0
mirror of https://github.com/DataTables/DataTables.git synced 2025-01-19 12:52:11 +01:00

Dev: Tidying up scrollbar width calcuation function

- Using jQuery we can make the code a bit smaller. Not much, just a 97
  byte saving, but every little helps, as they say....
This commit is contained in:
Allan Jardine 2013-02-18 08:42:32 +00:00
parent 4c4bfb04b8
commit 7c53a1824c
2 changed files with 52 additions and 48 deletions

View File

@ -3926,35 +3926,37 @@
*/
function _fnScrollBarWidth ()
{
var inner = document.createElement('p');
var style = inner.style;
style.width = "100%";
style.height = "200px";
style.padding = "0px";
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.padding = "0px";
style.overflow = "hidden";
outer.appendChild(inner);
document.body.appendChild(outer);
var inner = $('<p/>').css( {
width: '100%',
height: 200,
padding: 0
} )[0];
var outer = $('<div/>')
.css( {
position: 'absolute',
top: 0,
left: 0,
width: 200,
height: 150,
padding: 0,
overflow: 'hidden',
visibility: 'hidden'
} )
.append( inner )
.appendTo( 'body' );
var w1 = inner.offsetWidth;
outer.style.overflow = 'scroll';
outer.css( 'overflow', 'scroll' );
var w2 = inner.offsetWidth;
if ( w1 == w2 )
if ( w1 === w2 )
{
w2 = outer.clientWidth;
w2 = outer[0].clientWidth;
}
document.body.removeChild(outer);
return (w1 - w2);
outer.remove();
return w1 - w2;
}
/**

View File

@ -370,34 +370,36 @@ function _fnStringToCss( s )
*/
function _fnScrollBarWidth ()
{
var inner = document.createElement('p');
var style = inner.style;
style.width = "100%";
style.height = "200px";
style.padding = "0px";
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.padding = "0px";
style.overflow = "hidden";
outer.appendChild(inner);
document.body.appendChild(outer);
var inner = $('<p/>').css( {
width: '100%',
height: 200,
padding: 0
} )[0];
var outer = $('<div/>')
.css( {
position: 'absolute',
top: 0,
left: 0,
width: 200,
height: 150,
padding: 0,
overflow: 'hidden',
visibility: 'hidden'
} )
.append( inner )
.appendTo( 'body' );
var w1 = inner.offsetWidth;
outer.style.overflow = 'scroll';
outer.css( 'overflow', 'scroll' );
var w2 = inner.offsetWidth;
if ( w1 == w2 )
if ( w1 === w2 )
{
w2 = outer.clientWidth;
w2 = outer[0].clientWidth;
}
document.body.removeChild(outer);
return (w1 - w2);
outer.remove();
return w1 - w2;
}