Skip to content

Commit

Permalink
Merge pull request #411 from /issues/410@v2
Browse files Browse the repository at this point in the history
Return content from DOM helpers. Closes #410
  • Loading branch information
dfilatov committed Feb 22, 2014
2 parents c773c32 + 7423ed6 commit 9be73aa
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions common.blocks/i-bem/__dom/i-bem__dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -924,24 +924,26 @@ var DOM = BEM.decl('i-bem__dom',/** @lends BEMDOM.prototype */{
* Replaces a fragment of the DOM tree inside the context, destroying old blocks and intializing new ones
* @param {jQuery} ctx Root DOM node
* @param {jQuery|String} content New content
* @returns {jQuery} Updated root DOM node
*/
update : function(ctx, content) {
this.destruct(ctx, true);
this.init(ctx.html(content));
return this.init(ctx.html($(content)));
},

/**
* Changes a fragment of the DOM tree including the context and initializes blocks.
* @param {jQuery} ctx Root DOM node
* @param {jQuery|String} content Content to be added
* @returns {jQuery} New content
*/
replace : function(ctx, content) {
var prev = ctx.prev(),
parent = ctx.parent();

this.destruct(ctx);

this.init(prev.length?
return this.init(prev.length?
$(content).insertAfter(prev) :
$(content).prependTo(parent));
},
Expand All @@ -950,36 +952,40 @@ var DOM = BEM.decl('i-bem__dom',/** @lends BEMDOM.prototype */{
* Adds a fragment of the DOM tree at the end of the context and initializes blocks
* @param {jQuery} ctx Root DOM node
* @param {jQuery|String} content Content to be added
* @returns {jQuery} New content
*/
append : function(ctx, content) {
this.init($(content).appendTo(ctx));
return this.init($(content).appendTo(ctx));
},

/**
* Adds a fragment of the DOM tree at the beginning of the context and initializes blocks
* @param {jQuery} ctx Root DOM node
* @param {jQuery|String} content Content to be added
* @returns {jQuery} New content
*/
prepend : function(ctx, content) {
this.init($(content).prependTo(ctx));
return this.init($(content).prependTo(ctx));
},

/**
* Adds a fragment of the DOM tree before the context and initializes blocks
* @param {jQuery} ctx Contextual DOM node
* @param {jQuery|String} content Content to be added
* @returns {jQuery} New content
*/
before : function(ctx, content) {
this.init($(content).insertBefore(ctx));
return this.init($(content).insertBefore(ctx));
},

/**
* Adds a fragment of the DOM tree after the context and initializes blocks
* @param {jQuery} ctx Contextual DOM node
* @param {jQuery|String} content Content to be added
* @returns {jQuery} New content
*/
after : function(ctx, content) {
this.init($(content).insertAfter(ctx));
return this.init($(content).insertAfter(ctx));
},

/**
Expand Down

0 comments on commit 9be73aa

Please sign in to comment.