Permalink
Browse files

can call detach() on detached elements

  • Loading branch information...
1 parent 3f3134e commit e6b7ebd3ceb9d850e8884e8250060258a50af47c @rvagg rvagg committed Oct 30, 2012
Showing with 9 additions and 12 deletions.
  1. +2 −5 bonzo.js
  2. +1 −1 bonzo.min.js
  3. +2 −5 src/bonzo.js
  4. +4 −1 tests/dommanip-test.js
View
@@ -927,10 +927,7 @@
*/
, remove: function () {
this.deepEach(clearData)
-
- return this.each(function (el) {
- el[parentNode] && el[parentNode].removeChild(el)
- })
+ return this.detach()
}
@@ -953,7 +950,7 @@
*/
, detach: function () {
return this.each(function (el) {
- el[parentNode].removeChild(el)
+ el[parentNode] && el[parentNode].removeChild(el)
})
}
View
View
@@ -922,10 +922,7 @@
*/
, remove: function () {
this.deepEach(clearData)
-
- return this.each(function (el) {
- el[parentNode] && el[parentNode].removeChild(el)
- })
+ return this.detach()
}
@@ -948,7 +945,7 @@
*/
, detach: function () {
return this.each(function (el) {
- el[parentNode].removeChild(el)
+ el[parentNode] && el[parentNode].removeChild(el)
})
}
@@ -204,11 +204,14 @@ sink('DOM Manipulation', function(test, ok, before, after, assert) {
ok(Q('#empty p').length === 0, 'target has 0 {p} elements')
})
- test('should detach and return node list', 4, function () {
+ test('should detach and return node list', 5, function () {
ok(Q('#detach div').length == 2, 'target originally has 2 nodes')
var orphans = $('#detach div').detach()
ok(Q('#detach div').length === 0, 'target has detached 2 nodes')
ok(orphans.length == 2, '2 orphans were returned')
ok(!$.isAncestor(document.body, orphans[0]), 'orphans do not exist in document')
+ try {
+ ok($(document.createElement('div')).detach(), 'can call detach on already detached elements')
+ } catch (e) { ok(false, 'error detaching detached element: ' + e); console && console.log(e,e.stack) }
})
})

0 comments on commit e6b7ebd

Please sign in to comment.