backbone-childs
Advanced tools
Comparing version 1.0.2 to 1.0.3
46
index.js
@@ -5,11 +5,39 @@ var _ = require('underscore'); | ||
/** | ||
* Remove an element and provide a function that inserts it into its original position | ||
* @param element {Element} The element to be temporarily removed | ||
* @return {Function} A function that inserts the element into its original position | ||
**/ | ||
function removeToInsertLater(element) { | ||
var parentNode = element.parentNode; | ||
var nextSibling = element.nextSibling; | ||
parentNode.removeChild(element); | ||
return function() { | ||
if (nextSibling) { | ||
parentNode.insertBefore(element, nextSibling); | ||
} else { | ||
parentNode.appendChild(element); | ||
} | ||
}; | ||
} | ||
var removeChilds = function (node) { | ||
var last; | ||
while (last = node.lastChild) node.removeChild(last); | ||
}; | ||
module.exports = pluginator = viewType.extend({ | ||
renderSubviews: function() { | ||
// it is faster to remove the entire element and replace it | ||
// -> however this will lead to lost id,class and style props | ||
var oldEl = this.el; | ||
var el = document.createElement("div"); | ||
this.setElement(el); | ||
// it might be that the element is not on the DOM yet | ||
var elOnDom = oldEl.parentNode != undefined; | ||
if(elOnDom){ | ||
var insert = removeToInsertLater(oldEl) | ||
} | ||
removeChilds(oldEl); | ||
var frag = document.createDocumentFragment(); | ||
if (oldEl.parentNode != null) { | ||
oldEl.parentNode.replaceChild(this.el, oldEl); | ||
} | ||
var views = this._views(); | ||
@@ -28,4 +56,8 @@ var viewsSorted = _.sortBy(views, function(el) { | ||
} | ||
el.appendChild(frag); | ||
return el; | ||
oldEl.appendChild(frag); | ||
if(elOnDom){ | ||
insert(); | ||
} | ||
return oldEl; | ||
}, | ||
@@ -32,0 +64,0 @@ addView: function(key, view) { |
{ | ||
"name": "backbone-childs", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Extended backbone view with support for child views", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
4104
4
99
1
38