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:
parent
4c4bfb04b8
commit
7c53a1824c
50
media/js/jquery.dataTables.js
vendored
50
media/js/jquery.dataTables.js
vendored
@ -3926,35 +3926,37 @@
|
|||||||
*/
|
*/
|
||||||
function _fnScrollBarWidth ()
|
function _fnScrollBarWidth ()
|
||||||
{
|
{
|
||||||
var inner = document.createElement('p');
|
var inner = $('<p/>').css( {
|
||||||
var style = inner.style;
|
width: '100%',
|
||||||
style.width = "100%";
|
height: 200,
|
||||||
style.height = "200px";
|
padding: 0
|
||||||
style.padding = "0px";
|
} )[0];
|
||||||
|
|
||||||
var outer = document.createElement('div');
|
var outer = $('<div/>')
|
||||||
style = outer.style;
|
.css( {
|
||||||
style.position = "absolute";
|
position: 'absolute',
|
||||||
style.top = "0px";
|
top: 0,
|
||||||
style.left = "0px";
|
left: 0,
|
||||||
style.visibility = "hidden";
|
width: 200,
|
||||||
style.width = "200px";
|
height: 150,
|
||||||
style.height = "150px";
|
padding: 0,
|
||||||
style.padding = "0px";
|
overflow: 'hidden',
|
||||||
style.overflow = "hidden";
|
visibility: 'hidden'
|
||||||
outer.appendChild(inner);
|
} )
|
||||||
|
.append( inner )
|
||||||
document.body.appendChild(outer);
|
.appendTo( 'body' );
|
||||||
|
|
||||||
var w1 = inner.offsetWidth;
|
var w1 = inner.offsetWidth;
|
||||||
outer.style.overflow = 'scroll';
|
outer.css( 'overflow', 'scroll' );
|
||||||
var w2 = inner.offsetWidth;
|
var w2 = inner.offsetWidth;
|
||||||
if ( w1 == w2 )
|
if ( w1 === w2 )
|
||||||
{
|
{
|
||||||
w2 = outer.clientWidth;
|
w2 = outer[0].clientWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
document.body.removeChild(outer);
|
outer.remove();
|
||||||
return (w1 - w2);
|
|
||||||
|
return w1 - w2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -370,34 +370,36 @@ function _fnStringToCss( s )
|
|||||||
*/
|
*/
|
||||||
function _fnScrollBarWidth ()
|
function _fnScrollBarWidth ()
|
||||||
{
|
{
|
||||||
var inner = document.createElement('p');
|
var inner = $('<p/>').css( {
|
||||||
var style = inner.style;
|
width: '100%',
|
||||||
style.width = "100%";
|
height: 200,
|
||||||
style.height = "200px";
|
padding: 0
|
||||||
style.padding = "0px";
|
} )[0];
|
||||||
|
|
||||||
var outer = document.createElement('div');
|
var outer = $('<div/>')
|
||||||
style = outer.style;
|
.css( {
|
||||||
style.position = "absolute";
|
position: 'absolute',
|
||||||
style.top = "0px";
|
top: 0,
|
||||||
style.left = "0px";
|
left: 0,
|
||||||
style.visibility = "hidden";
|
width: 200,
|
||||||
style.width = "200px";
|
height: 150,
|
||||||
style.height = "150px";
|
padding: 0,
|
||||||
style.padding = "0px";
|
overflow: 'hidden',
|
||||||
style.overflow = "hidden";
|
visibility: 'hidden'
|
||||||
outer.appendChild(inner);
|
} )
|
||||||
|
.append( inner )
|
||||||
document.body.appendChild(outer);
|
.appendTo( 'body' );
|
||||||
|
|
||||||
var w1 = inner.offsetWidth;
|
var w1 = inner.offsetWidth;
|
||||||
outer.style.overflow = 'scroll';
|
outer.css( 'overflow', 'scroll' );
|
||||||
var w2 = inner.offsetWidth;
|
var w2 = inner.offsetWidth;
|
||||||
if ( w1 == w2 )
|
if ( w1 === w2 )
|
||||||
{
|
{
|
||||||
w2 = outer.clientWidth;
|
w2 = outer[0].clientWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
document.body.removeChild(outer);
|
outer.remove();
|
||||||
return (w1 - w2);
|
|
||||||
|
return w1 - w2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user