MCPcopy Index your code
hub / github.com/HelloZeroNet/ZeroNet / morphEl

Function morphEl

plugins/Sidebar/media/all.js:1448–1570  ·  view source on GitHub ↗
(fromNode, toNode, alreadyVisited)

Source from the content-addressed store, hash-verified

1446 }
1447
1448 function morphEl(fromNode, toNode, alreadyVisited) {
1449 if (toNode.id) {
1450 // If an element with an ID is being morphed then it is will be in the final
1451 // DOM so clear it out of the saved elements collection
1452 delete savedEls[toNode.id];
1453 }
1454
1455 if (onBeforeMorphEl(fromNode, toNode) === false) {
1456 return;
1457 }
1458
1459 morphAttrs(fromNode, toNode);
1460
1461 if (onBeforeMorphElChildren(fromNode, toNode) === false) {
1462 return;
1463 }
1464
1465 var curToNodeChild = toNode.firstChild;
1466 var curFromNodeChild = fromNode.firstChild;
1467 var curToNodeId;
1468
1469 var fromNextSibling;
1470 var toNextSibling;
1471 var savedEl;
1472 var unmatchedEl;
1473
1474 outer: while(curToNodeChild) {
1475 toNextSibling = curToNodeChild.nextSibling;
1476 curToNodeId = curToNodeChild.id;
1477
1478 while(curFromNodeChild) {
1479 var curFromNodeId = curFromNodeChild.id;
1480 fromNextSibling = curFromNodeChild.nextSibling;
1481
1482 if (!alreadyVisited) {
1483 if (curFromNodeId && (unmatchedEl = unmatchedEls[curFromNodeId])) {
1484 unmatchedEl.parentNode.replaceChild(curFromNodeChild, unmatchedEl);
1485 morphEl(curFromNodeChild, unmatchedEl, alreadyVisited);
1486 curFromNodeChild = fromNextSibling;
1487 continue;
1488 }
1489 }
1490
1491 var curFromNodeType = curFromNodeChild.nodeType;
1492
1493 if (curFromNodeType === curToNodeChild.nodeType) {
1494 var isCompatible = false;
1495
1496 if (curFromNodeType === 1) { // Both nodes being compared are Element nodes
1497 if (curFromNodeChild.tagName === curToNodeChild.tagName) {
1498 // We have compatible DOM elements
1499 if (curFromNodeId || curToNodeId) {
1500 // If either DOM element has an ID then we handle
1501 // those differently since we want to match up
1502 // by ID
1503 if (curToNodeId === curFromNodeId) {
1504 isCompatible = true;
1505 }

Callers 1

morphdomFunction · 0.70

Calls 2

morphAttrsFunction · 0.70
removeNodeFunction · 0.70

Tested by

no test coverage detected