Skip to content

Commit

Permalink
Add root() method to Strophe.Builder. Fixes #214
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbrand committed Oct 25, 2016
1 parent ee32e5c commit 578f56b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
deprecated and will be removed in a future release.
* #114 Add an error handler for HTTP calls
* #213 "XHR open failed." in BOSH in IE9
* #214 Add function to move Strophe.Builder pointer back to the root node

## Version 1.2.8 - 2016-09-16
* #200 Fix for webpack
Expand Down
15 changes: 15 additions & 0 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,21 @@ Strophe.Builder.prototype = {
return this;
},

/** Function: root
* Make the root element the new current element.
*
* When at a deeply nested element in the tree, this function can be used
* to jump back to the root of the tree, instead of having to repeatedly
* call up().
*
* Returns:
* The Stophe.Builder object.
*/
root: function () {
this.node = this.nodeTree;
return this;
},

/** Function: attrs
* Add or modify attributes of the current element.
*
Expand Down
6 changes: 6 additions & 0 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ define([

module("Builder");

test("The root() method", function () {
var builder = new Strophe.Builder('root');
var el = builder.c('child').c('grandchild').c('greatgrandchild').root();
equal(el.node.nodeName, 'root', 'root() jump back to the root of the tree');
});

test("Correct namespace (#32)", function () {
var stanzas = [new Strophe.Builder("message", {foo: "asdf"}).tree(),
$build("iq", {}).tree(),
Expand Down

0 comments on commit 578f56b

Please sign in to comment.