Skip to content

Commit

Permalink
- add toggle() method
Browse files Browse the repository at this point in the history
- add tests for toggle()
- bump version to 0.6.6
  • Loading branch information
ded committed Sep 7, 2011
1 parent 041520f commit 1beac57
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
16 changes: 12 additions & 4 deletions bonzo.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@

, html: function (h, text) {
var method = text ?
html.textContent == null ?
html.textContent === null ?
'innerText' :
'textContent' :
'innerHTML', m;
Expand Down Expand Up @@ -494,6 +494,14 @@
, scrollLeft: function (x) {
return scroll.call(this, x, null, 'x')
}

, toggle: function(callback) {
this.each(function (el) {
el.style.display = (el.offsetWidth || el.offsetHeight) ? 'none' : ''
})
callback && callback()
return this
}
}

function normalize(node) {
Expand All @@ -502,14 +510,14 @@

function scroll(x, y, type) {
var el = this[0]
if (x == null && y == null) {
if (x === null && y === null) {
return (isBody(el) ? getWindowScroll() : { x: el.scrollLeft, y: el.scrollTop })[type]
}
if (isBody(el)) {
win.scrollTo(x, y)
} else {
x != null && (el.scrollLeft = x)
y != null && (el.scrollTop = y)
x !== null && (el.scrollLeft = x)
y !== null && (el.scrollTop = y)
}
return this
}
Expand Down
2 changes: 1 addition & 1 deletion bonzo.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions make/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ require('smoosh').config({
, "whitespace": true
, "asi": true
, "laxbreak": true
, "eqeqeq": false
}
}).run().build().analyze()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bonzo"
, "description": "Library agnostic, extensible DOM utility"
, "version": "0.6.5"
, "version": "0.6.6"
, "homepage": "https://github.com/ded/bonzo"
, "author": "Dustin Diaz <dustin@dustindiaz.com> (http://dustindiaz.com)"
, "repository": {
Expand Down
16 changes: 12 additions & 4 deletions src/bonzo.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@

, html: function (h, text) {
var method = text ?
html.textContent == null ?
html.textContent === null ?
'innerText' :
'textContent' :
'innerHTML', m;
Expand Down Expand Up @@ -489,6 +489,14 @@
, scrollLeft: function (x) {
return scroll.call(this, x, null, 'x')
}

, toggle: function(callback) {
this.each(function (el) {
el.style.display = (el.offsetWidth || el.offsetHeight) ? 'none' : ''
})
callback && callback()
return this
}
}

function normalize(node) {
Expand All @@ -497,14 +505,14 @@

function scroll(x, y, type) {
var el = this[0]
if (x == null && y == null) {
if (x === null && y === null) {
return (isBody(el) ? getWindowScroll() : { x: el.scrollLeft, y: el.scrollTop })[type]
}
if (isBody(el)) {
win.scrollTo(x, y)
} else {
x != null && (el.scrollLeft = x)
y != null && (el.scrollTop = y)
x !== null && (el.scrollLeft = x)
y !== null && (el.scrollTop = y)
}
return this
}
Expand Down
Loading

0 comments on commit 1beac57

Please sign in to comment.