* 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)
| 6079 | * @returns {Function} A composite linking function of all of the matched directives or null. |
| 6080 | */ |
| 6081 | function compileNodes(nodeList, transcludeFn, $rootElement, maxPriority, ignoreDirective, |
| 6082 | previousCompileContext) { |
| 6083 | var linkFns = [], |
| 6084 | attrs, directives, nodeLinkFn, childNodes, childLinkFn, linkFnFound; |
| 6085 | |
| 6086 | for (var i = 0; i < nodeList.length; i++) { |
| 6087 | attrs = new Attributes(); |
| 6088 | |
| 6089 | // we must always refer to nodeList[i] since the nodes can be replaced underneath us. |
| 6090 | directives = collectDirectives(nodeList[i], [], attrs, i === 0 ? maxPriority : undefined, |
| 6091 | ignoreDirective); |
| 6092 | |
| 6093 | nodeLinkFn = (directives.length) |
| 6094 | ? applyDirectivesToNode(directives, nodeList[i], attrs, transcludeFn, $rootElement, |
| 6095 | null, [], [], previousCompileContext) |
| 6096 | : null; |
| 6097 | |
| 6098 | if (nodeLinkFn && nodeLinkFn.scope) { |
| 6099 | safeAddClass(attrs.$$element, 'ng-scope'); |
| 6100 | } |
| 6101 | |
| 6102 | childLinkFn = (nodeLinkFn && nodeLinkFn.terminal || |
| 6103 | !(childNodes = nodeList[i].childNodes) || |
| 6104 | !childNodes.length) |
| 6105 | ? null |
| 6106 | : compileNodes(childNodes, |
| 6107 | nodeLinkFn ? ( |
| 6108 | (nodeLinkFn.transcludeOnThisElement || !nodeLinkFn.templateOnThisElement) |
| 6109 | && nodeLinkFn.transclude) : transcludeFn); |
| 6110 | |
| 6111 | linkFns.push(nodeLinkFn, childLinkFn); |
| 6112 | linkFnFound = linkFnFound || nodeLinkFn || childLinkFn; |
| 6113 | //use the previous context only for the first element in the virtual group |
| 6114 | previousCompileContext = null; |
| 6115 | } |
| 6116 | |
| 6117 | // return a linking function if we have found anything, null otherwise |
| 6118 | return linkFnFound ? compositeLinkFn : null; |
| 6119 | |
| 6120 | function compositeLinkFn(scope, nodeList, $rootElement, parentBoundTranscludeFn) { |
| 6121 | var nodeLinkFn, childLinkFn, node, childScope, i, ii, n, childBoundTranscludeFn; |
| 6122 | |
| 6123 | // copy nodeList so that linking doesn't break due to live list updates. |
| 6124 | var nodeListLength = nodeList.length, |
| 6125 | stableNodeList = new Array(nodeListLength); |
| 6126 | for (i = 0; i < nodeListLength; i++) { |
| 6127 | stableNodeList[i] = nodeList[i]; |
| 6128 | } |
| 6129 | |
| 6130 | for(i = 0, n = 0, ii = linkFns.length; i < ii; n++) { |
| 6131 | node = stableNodeList[n]; |
| 6132 | nodeLinkFn = linkFns[i++]; |
| 6133 | childLinkFn = linkFns[i++]; |
| 6134 | |
| 6135 | if (nodeLinkFn) { |
| 6136 | if (nodeLinkFn.scope) { |
| 6137 | childScope = scope.$new(); |
| 6138 | jqLite.data(node, '$scope', childScope); |
no test coverage detected