* 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)
| 8718 | * @returns {Function} A composite linking function of all of the matched directives or null. |
| 8719 | */ |
| 8720 | function compileNodes(nodeList, transcludeFn, $rootElement, maxPriority, ignoreDirective, |
| 8721 | previousCompileContext) { |
| 8722 | var linkFns = [], |
| 8723 | attrs, directives, nodeLinkFn, childNodes, childLinkFn, linkFnFound, nodeLinkFnFound; |
| 8724 | |
| 8725 | for (var i = 0; i < nodeList.length; i++) { |
| 8726 | attrs = new Attributes(); |
| 8727 | |
| 8728 | // we must always refer to nodeList[i] since the nodes can be replaced underneath us. |
| 8729 | directives = collectDirectives(nodeList[i], [], attrs, i === 0 ? maxPriority : undefined, |
| 8730 | ignoreDirective); |
| 8731 | |
| 8732 | nodeLinkFn = (directives.length) |
| 8733 | ? applyDirectivesToNode(directives, nodeList[i], attrs, transcludeFn, $rootElement, |
| 8734 | null, [], [], previousCompileContext) |
| 8735 | : null; |
| 8736 | |
| 8737 | if (nodeLinkFn && nodeLinkFn.scope) { |
| 8738 | compile.$$addScopeClass(attrs.$$element); |
| 8739 | } |
| 8740 | |
| 8741 | childLinkFn = (nodeLinkFn && nodeLinkFn.terminal || |
| 8742 | !(childNodes = nodeList[i].childNodes) || |
| 8743 | !childNodes.length) |
| 8744 | ? null |
| 8745 | : compileNodes(childNodes, |
| 8746 | nodeLinkFn ? ( |
| 8747 | (nodeLinkFn.transcludeOnThisElement || !nodeLinkFn.templateOnThisElement) |
| 8748 | && nodeLinkFn.transclude) : transcludeFn); |
| 8749 | |
| 8750 | if (nodeLinkFn || childLinkFn) { |
| 8751 | linkFns.push(i, nodeLinkFn, childLinkFn); |
| 8752 | linkFnFound = true; |
| 8753 | nodeLinkFnFound = nodeLinkFnFound || nodeLinkFn; |
| 8754 | } |
| 8755 | |
| 8756 | //use the previous context only for the first element in the virtual group |
| 8757 | previousCompileContext = null; |
| 8758 | } |
| 8759 | |
| 8760 | // return a linking function if we have found anything, null otherwise |
| 8761 | return linkFnFound ? compositeLinkFn : null; |
| 8762 | |
| 8763 | function compositeLinkFn(scope, nodeList, $rootElement, parentBoundTranscludeFn) { |
| 8764 | var nodeLinkFn, childLinkFn, node, childScope, i, ii, idx, childBoundTranscludeFn; |
| 8765 | var stableNodeList; |
| 8766 | |
| 8767 | |
| 8768 | if (nodeLinkFnFound) { |
| 8769 | // copy nodeList so that if a nodeLinkFn removes or adds an element at this DOM level our |
| 8770 | // offsets don't get screwed up |
| 8771 | var nodeListLength = nodeList.length; |
| 8772 | stableNodeList = new Array(nodeListLength); |
| 8773 | |
| 8774 | // create a sparse array by only copying the elements which have a linkFn |
| 8775 | for (i = 0; i < linkFns.length; i += 3) { |
| 8776 | idx = linkFns[i]; |
| 8777 | stableNodeList[idx] = nodeList[idx]; |
no test coverage detected