Skip to content

Commit

Permalink
fixing scott's table display detect so it sucks less. :)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed May 18, 2011
1 parent e530219 commit f4531a4
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions feature-detects/css-displaytable.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
// display: table and table-cell test. (both are tested under one name "table-cell" )
// By @scottjehl

// all additional table display values are here: http://pastebin.com/Gk9PeVaQ though Scott has seen some IE false positives with that sort of weak detection.
// more testing neccessary perhaps.

Modernizr.addTest( "display-table",function(){
var doc = window.document,
docElem = doc.documentElement,
create = function( el ){
return doc.createElement( el );
},
parent = create( "div" ),
child = create( "div" ),
childb = create( "div" ),
ret;

parent.style.display = "table";
child.style.display = childb.style.display = "table-cell";
child.style.padding = childb.style.padding = "10px";

parent.appendChild( child );
parent.appendChild( childb );
docElem.insertBefore( parent, docElem.firstChild );

ret = child.offsetLeft < childb.offsetLeft;
docElem.removeChild(parent);
return ret;
});

var doc = window.document,
docElem = doc.documentElement,
create = function( el ){
return doc.createElement( el );
},
parent = create( "div" ),
child = create( "div" ),
childb = create( "div" ),
ret;

parent.style.display = "table";
child.style.display = childb.style.display = "table-cell";
child.style.padding = childb.style.padding = "10px";

parent.appendChild( child );
parent.appendChild( childb );
docElem.insertBefore( parent, docElem.firstChild );

ret = child.offsetLeft < childb.offsetLeft;
docElem.removeChild(parent);
return ret;
});

3 comments on commit f4531a4

@scottjehl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certain circles may disagree. Frankly, whatever works, sir. :)

@SlexAxton
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took me a while. Guessing tabs v. spaces?

May I suggest that we don't shortcut document.createElement, etc. - After gzip this ends up being bigger...

@scottjehl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, good point! Sorry bout that.

Please sign in to comment.