MCPcopy Create free account
hub / github.com/binux/qiandao / replaceWith

Function replaceWith

web/static/components/angularjs/angular.js:7034–7074  ·  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

7032 * @param {Node} newNode The new DOM node.
7033 */
7034 function replaceWith($rootElement, elementsToRemove, newNode) {
7035 var firstElementToRemove = elementsToRemove[0],
7036 removeCount = elementsToRemove.length,
7037 parent = firstElementToRemove.parentNode,
7038 i, ii;
7039
7040 if ($rootElement) {
7041 for(i = 0, ii = $rootElement.length; i < ii; i++) {
7042 if ($rootElement[i] == firstElementToRemove) {
7043 $rootElement[i++] = newNode;
7044 for (var j = i, j2 = j + removeCount - 1,
7045 jj = $rootElement.length;
7046 j < jj; j++, j2++) {
7047 if (j2 < jj) {
7048 $rootElement[j] = $rootElement[j2];
7049 } else {
7050 delete $rootElement[j];
7051 }
7052 }
7053 $rootElement.length -= removeCount - 1;
7054 break;
7055 }
7056 }
7057 }
7058
7059 if (parent) {
7060 parent.replaceChild(newNode, firstElementToRemove);
7061 }
7062 var fragment = document.createDocumentFragment();
7063 fragment.appendChild(firstElementToRemove);
7064 newNode[jqLite.expando] = firstElementToRemove[jqLite.expando];
7065 for (var k = 1, kk = elementsToRemove.length; k < kk; k++) {
7066 var element = elementsToRemove[k];
7067 jqLite(element).remove(); // must do this way to clean up expando
7068 fragment.appendChild(element);
7069 delete elementsToRemove[k];
7070 }
7071
7072 elementsToRemove[0] = newNode;
7073 elementsToRemove.length = 1;
7074 }
7075
7076
7077 function cloneAndAnnotateFn(fn, annotation) {

Callers 2

applyDirectivesToNodeFunction · 0.85
compileTemplateUrlFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected