* 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)
| 7883 | * @returns {Function} A composite linking function of all of the matched directives or null. |
| 7884 | */ |
| 7885 | function compileNodes(nodeList, transcludeFn, $rootElement, maxPriority, ignoreDirective, |
| 7886 | previousCompileContext) { |
| 7887 | var linkFns = [], |
| 7888 | attrs, directives, nodeLinkFn, childNodes, childLinkFn, linkFnFound, nodeLinkFnFound; |
| 7889 | |
| 7890 | for (var i = 0; i < nodeList.length; i++) { |
| 7891 | attrs = new Attributes(); |
| 7892 | |
| 7893 | // we must always refer to nodeList[i] since the nodes can be replaced underneath us. |
| 7894 | directives = collectDirectives(nodeList[i], [], attrs, i === 0 ? maxPriority : undefined, |
| 7895 | ignoreDirective); |
| 7896 | |
| 7897 | nodeLinkFn = (directives.length) |
| 7898 | ? applyDirectivesToNode(directives, nodeList[i], attrs, transcludeFn, $rootElement, |
| 7899 | null, [], [], previousCompileContext) |
| 7900 | : null; |
| 7901 | |
| 7902 | if (nodeLinkFn && nodeLinkFn.scope) { |
| 7903 | compile.$$addScopeClass(attrs.$$element); |
| 7904 | } |
| 7905 | |
| 7906 | childLinkFn = (nodeLinkFn && nodeLinkFn.terminal || |
| 7907 | !(childNodes = nodeList[i].childNodes) || |
| 7908 | !childNodes.length) |
| 7909 | ? null |
| 7910 | : compileNodes(childNodes, |
| 7911 | nodeLinkFn ? ( |
| 7912 | (nodeLinkFn.transcludeOnThisElement || !nodeLinkFn.templateOnThisElement) |
| 7913 | && nodeLinkFn.transclude) : transcludeFn); |
| 7914 | |
| 7915 | if (nodeLinkFn || childLinkFn) { |
| 7916 | linkFns.push(i, nodeLinkFn, childLinkFn); |
| 7917 | linkFnFound = true; |
| 7918 | nodeLinkFnFound = nodeLinkFnFound || nodeLinkFn; |
| 7919 | } |
| 7920 | |
| 7921 | //use the previous context only for the first element in the virtual group |
| 7922 | previousCompileContext = null; |
| 7923 | } |
| 7924 | |
| 7925 | // return a linking function if we have found anything, null otherwise |
| 7926 | return linkFnFound ? compositeLinkFn : null; |
| 7927 | |
| 7928 | function compositeLinkFn(scope, nodeList, $rootElement, parentBoundTranscludeFn) { |
| 7929 | var nodeLinkFn, childLinkFn, node, childScope, i, ii, idx, childBoundTranscludeFn; |
| 7930 | var stableNodeList; |
| 7931 | |
| 7932 | |
| 7933 | if (nodeLinkFnFound) { |
| 7934 | // copy nodeList so that if a nodeLinkFn removes or adds an element at this DOM level our |
| 7935 | // offsets don't get screwed up |
| 7936 | var nodeListLength = nodeList.length; |
| 7937 | stableNodeList = new Array(nodeListLength); |
| 7938 | |
| 7939 | // create a sparse array by only copying the elements which have a linkFn |
| 7940 | for (i = 0; i < linkFns.length; i+=3) { |
| 7941 | idx = linkFns[i]; |
| 7942 | stableNodeList[idx] = nodeList[idx]; |
no test coverage detected