* Compile function matches each node in nodeList against the directives. Once all directives * for a particular node are collected their compile functions are executed. The compile * functions return values - the linking functions - are combined into a composite linking * function, wh
(nodeList, transcludeFn, $rootElement, maxPriority, ignoreDirective,
previousCompileContext)
| 7444 | * @returns {Function} A composite linking function of all of the matched directives or null. |
| 7445 | */ |
| 7446 | function compileNodes(nodeList, transcludeFn, $rootElement, maxPriority, ignoreDirective, |
| 7447 | previousCompileContext) { |
| 7448 | var linkFns = [], |
| 7449 | attrs, directives, nodeLinkFn, childNodes, childLinkFn, linkFnFound, nodeLinkFnFound; |
| 7450 | |
| 7451 | for (var i = 0; i < nodeList.length; i++) { |
| 7452 | attrs = new Attributes(); |
| 7453 | |
| 7454 | // we must always refer to nodeList[i] since the nodes can be replaced underneath us. |
| 7455 | directives = collectDirectives(nodeList[i], [], attrs, i === 0 ? maxPriority : undefined, |
| 7456 | ignoreDirective); |
| 7457 | |
| 7458 | nodeLinkFn = (directives.length) |
| 7459 | ? applyDirectivesToNode(directives, nodeList[i], attrs, transcludeFn, $rootElement, |
| 7460 | null, [], [], previousCompileContext) |
| 7461 | : null; |
| 7462 | |
| 7463 | if (nodeLinkFn && nodeLinkFn.scope) { |
| 7464 | compile.$$addScopeClass(attrs.$$element); |
| 7465 | } |
| 7466 | |
| 7467 | childLinkFn = (nodeLinkFn && nodeLinkFn.terminal || |
| 7468 | !(childNodes = nodeList[i].childNodes) || |
| 7469 | !childNodes.length) |
| 7470 | ? null |
| 7471 | : compileNodes(childNodes, |
| 7472 | nodeLinkFn ? ( |
| 7473 | (nodeLinkFn.transcludeOnThisElement || !nodeLinkFn.templateOnThisElement) |
| 7474 | && nodeLinkFn.transclude) : transcludeFn); |
| 7475 | |
| 7476 | if (nodeLinkFn || childLinkFn) { |
| 7477 | linkFns.push(i, nodeLinkFn, childLinkFn); |
| 7478 | linkFnFound = true; |
| 7479 | nodeLinkFnFound = nodeLinkFnFound || nodeLinkFn; |
| 7480 | } |
| 7481 | |
| 7482 | //use the previous context only for the first element in the virtual group |
| 7483 | previousCompileContext = null; |
| 7484 | } |
| 7485 | |
| 7486 | // return a linking function if we have found anything, null otherwise |
| 7487 | return linkFnFound ? compositeLinkFn : null; |
| 7488 | |
| 7489 | function compositeLinkFn(scope, nodeList, $rootElement, parentBoundTranscludeFn) { |
| 7490 | var nodeLinkFn, childLinkFn, node, childScope, i, ii, idx, childBoundTranscludeFn; |
| 7491 | var stableNodeList; |
| 7492 | |
| 7493 | |
| 7494 | if (nodeLinkFnFound) { |
| 7495 | // copy nodeList so that if a nodeLinkFn removes or adds an element at this DOM level our |
| 7496 | // offsets don't get screwed up |
| 7497 | var nodeListLength = nodeList.length; |
| 7498 | stableNodeList = new Array(nodeListLength); |
| 7499 | |
| 7500 | // create a sparse array by only copying the elements which have a linkFn |
| 7501 | for (i = 0; i < linkFns.length; i+=3) { |
| 7502 | idx = linkFns[i]; |
| 7503 | stableNodeList[idx] = nodeList[idx]; |
no test coverage detected