* 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)
| 8134 | * @returns {Function} A composite linking function of all of the matched directives or null. |
| 8135 | */ |
| 8136 | function compileNodes(nodeList, transcludeFn, $rootElement, maxPriority, ignoreDirective, |
| 8137 | previousCompileContext) { |
| 8138 | var linkFns = [], |
| 8139 | attrs, directives, nodeLinkFn, childNodes, childLinkFn, linkFnFound, nodeLinkFnFound; |
| 8140 | |
| 8141 | for (var i = 0; i < nodeList.length; i++) { |
| 8142 | attrs = new Attributes(); |
| 8143 | |
| 8144 | // we must always refer to nodeList[i] since the nodes can be replaced underneath us. |
| 8145 | directives = collectDirectives(nodeList[i], [], attrs, i === 0 ? maxPriority : undefined, |
| 8146 | ignoreDirective); |
| 8147 | |
| 8148 | nodeLinkFn = (directives.length) |
| 8149 | ? applyDirectivesToNode(directives, nodeList[i], attrs, transcludeFn, $rootElement, |
| 8150 | null, [], [], previousCompileContext) |
| 8151 | : null; |
| 8152 | |
| 8153 | if (nodeLinkFn && nodeLinkFn.scope) { |
| 8154 | compile.$$addScopeClass(attrs.$$element); |
| 8155 | } |
| 8156 | |
| 8157 | childLinkFn = (nodeLinkFn && nodeLinkFn.terminal || |
| 8158 | !(childNodes = nodeList[i].childNodes) || |
| 8159 | !childNodes.length) |
| 8160 | ? null |
| 8161 | : compileNodes(childNodes, |
| 8162 | nodeLinkFn ? ( |
| 8163 | (nodeLinkFn.transcludeOnThisElement || !nodeLinkFn.templateOnThisElement) |
| 8164 | && nodeLinkFn.transclude) : transcludeFn); |
| 8165 | |
| 8166 | if (nodeLinkFn || childLinkFn) { |
| 8167 | linkFns.push(i, nodeLinkFn, childLinkFn); |
| 8168 | linkFnFound = true; |
| 8169 | nodeLinkFnFound = nodeLinkFnFound || nodeLinkFn; |
| 8170 | } |
| 8171 | |
| 8172 | //use the previous context only for the first element in the virtual group |
| 8173 | previousCompileContext = null; |
| 8174 | } |
| 8175 | |
| 8176 | // return a linking function if we have found anything, null otherwise |
| 8177 | return linkFnFound ? compositeLinkFn : null; |
| 8178 | |
| 8179 | function compositeLinkFn(scope, nodeList, $rootElement, parentBoundTranscludeFn) { |
| 8180 | var nodeLinkFn, childLinkFn, node, childScope, i, ii, idx, childBoundTranscludeFn; |
| 8181 | var stableNodeList; |
| 8182 | |
| 8183 | |
| 8184 | if (nodeLinkFnFound) { |
| 8185 | // copy nodeList so that if a nodeLinkFn removes or adds an element at this DOM level our |
| 8186 | // offsets don't get screwed up |
| 8187 | var nodeListLength = nodeList.length; |
| 8188 | stableNodeList = new Array(nodeListLength); |
| 8189 | |
| 8190 | // create a sparse array by only copying the elements which have a linkFn |
| 8191 | for (i = 0; i < linkFns.length; i+=3) { |
| 8192 | idx = linkFns[i]; |
| 8193 | stableNodeList[idx] = nodeList[idx]; |
no test coverage detected