* 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)
| 7047 | * @returns {Function} A composite linking function of all of the matched directives or null. |
| 7048 | */ |
| 7049 | function compileNodes(nodeList, transcludeFn, $rootElement, maxPriority, ignoreDirective, |
| 7050 | previousCompileContext) { |
| 7051 | var linkFns = [], |
| 7052 | attrs, directives, nodeLinkFn, childNodes, childLinkFn, linkFnFound, nodeLinkFnFound; |
| 7053 | |
| 7054 | for (var i = 0; i < nodeList.length; i++) { |
| 7055 | attrs = new Attributes(); |
| 7056 | |
| 7057 | // we must always refer to nodeList[i] since the nodes can be replaced underneath us. |
| 7058 | directives = collectDirectives(nodeList[i], [], attrs, i === 0 ? maxPriority : undefined, |
| 7059 | ignoreDirective); |
| 7060 | |
| 7061 | nodeLinkFn = (directives.length) |
| 7062 | ? applyDirectivesToNode(directives, nodeList[i], attrs, transcludeFn, $rootElement, |
| 7063 | null, [], [], previousCompileContext) |
| 7064 | : null; |
| 7065 | |
| 7066 | if (nodeLinkFn && nodeLinkFn.scope) { |
| 7067 | compile.$$addScopeClass(attrs.$$element); |
| 7068 | } |
| 7069 | |
| 7070 | childLinkFn = (nodeLinkFn && nodeLinkFn.terminal || |
| 7071 | !(childNodes = nodeList[i].childNodes) || |
| 7072 | !childNodes.length) |
| 7073 | ? null |
| 7074 | : compileNodes(childNodes, |
| 7075 | nodeLinkFn ? ( |
| 7076 | (nodeLinkFn.transcludeOnThisElement || !nodeLinkFn.templateOnThisElement) |
| 7077 | && nodeLinkFn.transclude) : transcludeFn); |
| 7078 | |
| 7079 | if (nodeLinkFn || childLinkFn) { |
| 7080 | linkFns.push(i, nodeLinkFn, childLinkFn); |
| 7081 | linkFnFound = true; |
| 7082 | nodeLinkFnFound = nodeLinkFnFound || nodeLinkFn; |
| 7083 | } |
| 7084 | |
| 7085 | //use the previous context only for the first element in the virtual group |
| 7086 | previousCompileContext = null; |
| 7087 | } |
| 7088 | |
| 7089 | // return a linking function if we have found anything, null otherwise |
| 7090 | return linkFnFound ? compositeLinkFn : null; |
| 7091 | |
| 7092 | function compositeLinkFn(scope, nodeList, $rootElement, parentBoundTranscludeFn) { |
| 7093 | var nodeLinkFn, childLinkFn, node, childScope, i, ii, idx, childBoundTranscludeFn; |
| 7094 | var stableNodeList; |
| 7095 | |
| 7096 | |
| 7097 | if (nodeLinkFnFound) { |
| 7098 | // copy nodeList so that if a nodeLinkFn removes or adds an element at this DOM level our |
| 7099 | // offsets don't get screwed up |
| 7100 | var nodeListLength = nodeList.length; |
| 7101 | stableNodeList = new Array(nodeListLength); |
| 7102 | |
| 7103 | // create a sparse array by only copying the elements which have a linkFn |
| 7104 | for (i = 0; i < linkFns.length; i+=3) { |
| 7105 | idx = linkFns[i]; |
| 7106 | stableNodeList[idx] = nodeList[idx]; |
no test coverage detected