Skip to content
Browse files

.dim() & height() & width() on `document` element

  • Loading branch information...
1 parent 23028df commit d4b483ddde36786947e367be04d6027f1142c0fc @rvagg rvagg committed Oct 27, 2012
Showing with 17 additions and 5 deletions.
  1. +0 −1 .jshintrc
  2. +8 −3 src/bonzo.js
  3. +5 −0 tests/bridge-test.js
  4. +4 −1 tests/layout-test.js
View
1 .jshintrc
@@ -13,7 +13,6 @@
, "undef": true
, "sub": true
, "white": false
- , "indent": 2
, "asi": true
, "laxbreak": true
, "eqnull": true
View
11 src/bonzo.js
@@ -817,7 +817,8 @@
, dim: function () {
if (!this.length) return { height: 0, width: 0 }
var el = this[0]
- , orig = !el.offsetWidth && !el.offsetHeight ?
+ , de = el.nodeType == 9 && el.documentElement // document
+ , orig = !de && !!el.style && !el.offsetWidth && !el.offsetHeight ?
// el isn't visible, can't be measured properly, so fix that
function (t) {
var s = {
@@ -832,8 +833,12 @@
})
return s
}(this) : null
- , width = el.offsetWidth
- , height = el.offsetHeight
+ , width = de
+ ? Math.max(el.body.scrollWidth, el.body.offsetWidth, de.scrollWidth, de.offsetWidth, de.clientWidth)
+ : el.offsetWidth
+ , height = de
+ ? Math.max(el.body.scrollHeight, el.body.offsetHeight, de.scrollWidth, de.offsetWidth, de.clientHeight)
+ : el.offsetHeight
orig && this.first().css(orig)
return {
View
5 tests/bridge-test.js
@@ -28,6 +28,11 @@ sink('Ender bridge', function (test, ok, before, after, assert) {
$el.remove()
})
+ test('height & width of `document`', 2, function () {
+ ok(ender(document).height() > 0)
+ ok(ender(document).width() > 0)
+ })
+
test('no-arg parents()', 5, function () {
try {
var parents = ender('#parent-test').parents()
View
5 tests/layout-test.js
@@ -52,7 +52,7 @@ sink('Layout', function (test, ok) {
ok(!nullSet.height, 'no offset().height')
})
- test('dimensions', 5, function () {
+ test('dimensions', 7, function () {
var $el = $(dom.create('<div/>')).css({
position: 'absolute'
, left: '50px'
@@ -73,6 +73,9 @@ sink('Layout', function (test, ok) {
ok($hidden.dim().height > 0 && $hidden.dim().height < 100, 'hidden element dim().height is reasonable non-zero')
ok($hidden.dim().width > 0 && $hidden.dim().width < 10000, 'hidden element dim().width is reasonable non-zero')
ok($hidden[0].style.display == 'none', 'hidden element is still hidden after dim() call')
+
+ ok($(document).dim().height > 0, 'document has a height > 0: ' + $(document).dim().height)
+ ok($(document).dim().width > 0, 'document has a width > 0: ' + $(document).dim().width)
})
test('viewport width & height', 2, function () {

0 comments on commit d4b483d

Please sign in to comment.
Something went wrong with that request. Please try again.