var parent = this._parent; if(node.parentNode && node.parentNode.tagName && parent && !parent._dirty){ return this; } if(node.nodeType == 1 && !this.rootNode){ this.rootNode = node || true; } if(!parent){ if(node.nodeType == 3 && dojo.trim(node.data)){ throw new Error("Text should not exist outside of the root node in template"); } return this; } if(this._closed && (node.nodeType != 3 || dojo.trim(node.data))){ throw new Error("Content should not exist outside of the root node in template"); } if(parent._dirty){ if(node._drawn && node.parentNode == parent){ var caches = parent._cache; if(caches){ for(var i = 0, cache; cache = caches[i]; i++){ this.onAddNode(cache); parent.insertBefore(cache, node); this.onAddNodeComplete(cache); } caches.length = 0; } } parent._dirty = false; } if(!parent._cache){ parent._cache = []; this._cache.push(parent); } parent._dirty = true; parent._cache.push(node); return this;