* 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)
| 7583 | * @returns {Function} A composite linking function of all of the matched directives or null. |
| 7584 | */ |
| 7585 | function compileNodes(nodeList, transcludeFn, $rootElement, maxPriority, ignoreDirective, |
| 7586 | previousCompileContext) { |
| 7587 | var linkFns = [], |
| 7588 | attrs, directives, nodeLinkFn, childNodes, childLinkFn, linkFnFound, nodeLinkFnFound; |
| 7589 | |
| 7590 | for (var i = 0; i < nodeList.length; i++) { |
| 7591 | attrs = new Attributes(); |
| 7592 | |
| 7593 | // we must always refer to nodeList[i] since the nodes can be replaced underneath us. |
| 7594 | directives = collectDirectives(nodeList[i], [], attrs, i === 0 ? maxPriority : undefined, |
| 7595 | ignoreDirective); |
| 7596 | |
| 7597 | nodeLinkFn = (directives.length) |
| 7598 | ? applyDirectivesToNode(directives, nodeList[i], attrs, transcludeFn, $rootElement, |
| 7599 | null, [], [], previousCompileContext) |
| 7600 | : null; |
| 7601 | |
| 7602 | if (nodeLinkFn && nodeLinkFn.scope) { |
| 7603 | compile.$$addScopeClass(attrs.$$element); |
| 7604 | } |
| 7605 | |
| 7606 | childLinkFn = (nodeLinkFn && nodeLinkFn.terminal || |
| 7607 | !(childNodes = nodeList[i].childNodes) || |
| 7608 | !childNodes.length) |
| 7609 | ? null |
| 7610 | : compileNodes(childNodes, |
| 7611 | nodeLinkFn ? ( |
| 7612 | (nodeLinkFn.transcludeOnThisElement || !nodeLinkFn.templateOnThisElement) |
| 7613 | && nodeLinkFn.transclude) : transcludeFn); |
| 7614 | |
| 7615 | if (nodeLinkFn || childLinkFn) { |
| 7616 | linkFns.push(i, nodeLinkFn, childLinkFn); |
| 7617 | linkFnFound = true; |
| 7618 | nodeLinkFnFound = nodeLinkFnFound || nodeLinkFn; |
| 7619 | } |
| 7620 | |
| 7621 | //use the previous context only for the first element in the virtual group |
| 7622 | previousCompileContext = null; |
| 7623 | } |
| 7624 | |
| 7625 | // return a linking function if we have found anything, null otherwise |
| 7626 | return linkFnFound ? compositeLinkFn : null; |
| 7627 | |
| 7628 | function compositeLinkFn(scope, nodeList, $rootElement, parentBoundTranscludeFn) { |
| 7629 | var nodeLinkFn, childLinkFn, node, childScope, i, ii, idx, childBoundTranscludeFn; |
| 7630 | var stableNodeList; |
| 7631 | |
| 7632 | |
| 7633 | if (nodeLinkFnFound) { |
| 7634 | // copy nodeList so that if a nodeLinkFn removes or adds an element at this DOM level our |
| 7635 | // offsets don't get screwed up |
| 7636 | var nodeListLength = nodeList.length; |
| 7637 | stableNodeList = new Array(nodeListLength); |
| 7638 | |
| 7639 | // create a sparse array by only copying the elements which have a linkFn |
| 7640 | for (i = 0; i < linkFns.length; i+=3) { |
| 7641 | idx = linkFns[i]; |
| 7642 | stableNodeList[idx] = nodeList[idx]; |
no test coverage detected