MCPcopy Create free account
hub / github.com/angular-ui/ui-router / replaceWith

Function replaceWith

test/angular/1.2/angular.js:7139–7179  ·  view source on GitHub ↗

* This is a special jqLite.replaceWith, which can replace items which * have no parents, provided that the containing jqLite collection is provided. * * @param {JqLite=} $rootElement The root of the compile tree. Used so that we can replace nodes * i

($rootElement, elementsToRemove, newNode)

Source from the content-addressed store, hash-verified

7137 * @param {Node} newNode The new DOM node.
7138 */
7139 function replaceWith($rootElement, elementsToRemove, newNode) {
7140 var firstElementToRemove = elementsToRemove[0],
7141 removeCount = elementsToRemove.length,
7142 parent = firstElementToRemove.parentNode,
7143 i, ii;
7144
7145 if ($rootElement) {
7146 for(i = 0, ii = $rootElement.length; i < ii; i++) {
7147 if ($rootElement[i] == firstElementToRemove) {
7148 $rootElement[i++] = newNode;
7149 for (var j = i, j2 = j + removeCount - 1,
7150 jj = $rootElement.length;
7151 j < jj; j++, j2++) {
7152 if (j2 < jj) {
7153 $rootElement[j] = $rootElement[j2];
7154 } else {
7155 delete $rootElement[j];
7156 }
7157 }
7158 $rootElement.length -= removeCount - 1;
7159 break;
7160 }
7161 }
7162 }
7163
7164 if (parent) {
7165 parent.replaceChild(newNode, firstElementToRemove);
7166 }
7167 var fragment = document.createDocumentFragment();
7168 fragment.appendChild(firstElementToRemove);
7169 newNode[jqLite.expando] = firstElementToRemove[jqLite.expando];
7170 for (var k = 1, kk = elementsToRemove.length; k < kk; k++) {
7171 var element = elementsToRemove[k];
7172 jqLite(element).remove(); // must do this way to clean up expando
7173 fragment.appendChild(element);
7174 delete elementsToRemove[k];
7175 }
7176
7177 elementsToRemove[0] = newNode;
7178 elementsToRemove.length = 1;
7179 }
7180
7181
7182 function cloneAndAnnotateFn(fn, annotation) {

Callers 2

applyDirectivesToNodeFunction · 0.70
compileTemplateUrlFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected