* 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)
| 6969 | * @returns {Function} A composite linking function of all of the matched directives or null. |
| 6970 | */ |
| 6971 | function compileNodes(nodeList, transcludeFn, $rootElement, maxPriority, ignoreDirective, |
| 6972 | previousCompileContext) { |
| 6973 | var linkFns = [], |
| 6974 | attrs, directives, nodeLinkFn, childNodes, childLinkFn, linkFnFound, nodeLinkFnFound; |
| 6975 | |
| 6976 | for (var i = 0; i < nodeList.length; i++) { |
| 6977 | attrs = new Attributes(); |
| 6978 | |
| 6979 | // we must always refer to nodeList[i] since the nodes can be replaced underneath us. |
| 6980 | directives = collectDirectives(nodeList[i], [], attrs, i === 0 ? maxPriority : undefined, |
| 6981 | ignoreDirective); |
| 6982 | |
| 6983 | nodeLinkFn = (directives.length) |
| 6984 | ? applyDirectivesToNode(directives, nodeList[i], attrs, transcludeFn, $rootElement, |
| 6985 | null, [], [], previousCompileContext) |
| 6986 | : null; |
| 6987 | |
| 6988 | if (nodeLinkFn && nodeLinkFn.scope) { |
| 6989 | compile.$$addScopeClass(attrs.$$element); |
| 6990 | } |
| 6991 | |
| 6992 | childLinkFn = (nodeLinkFn && nodeLinkFn.terminal || |
| 6993 | !(childNodes = nodeList[i].childNodes) || |
| 6994 | !childNodes.length) |
| 6995 | ? null |
| 6996 | : compileNodes(childNodes, |
| 6997 | nodeLinkFn ? ( |
| 6998 | (nodeLinkFn.transcludeOnThisElement || !nodeLinkFn.templateOnThisElement) |
| 6999 | && nodeLinkFn.transclude) : transcludeFn); |
| 7000 | |
| 7001 | if (nodeLinkFn || childLinkFn) { |
| 7002 | linkFns.push(i, nodeLinkFn, childLinkFn); |
| 7003 | linkFnFound = true; |
| 7004 | nodeLinkFnFound = nodeLinkFnFound || nodeLinkFn; |
| 7005 | } |
| 7006 | |
| 7007 | //use the previous context only for the first element in the virtual group |
| 7008 | previousCompileContext = null; |
| 7009 | } |
| 7010 | |
| 7011 | // return a linking function if we have found anything, null otherwise |
| 7012 | return linkFnFound ? compositeLinkFn : null; |
| 7013 | |
| 7014 | function compositeLinkFn(scope, nodeList, $rootElement, parentBoundTranscludeFn) { |
| 7015 | var nodeLinkFn, childLinkFn, node, childScope, i, ii, idx, childBoundTranscludeFn; |
| 7016 | var stableNodeList; |
| 7017 | |
| 7018 | |
| 7019 | if (nodeLinkFnFound) { |
| 7020 | // copy nodeList so that if a nodeLinkFn removes or adds an element at this DOM level our |
| 7021 | // offsets don't get screwed up |
| 7022 | var nodeListLength = nodeList.length; |
| 7023 | stableNodeList = new Array(nodeListLength); |
| 7024 | |
| 7025 | // create a sparse array by only copying the elements which have a linkFn |
| 7026 | for (i = 0; i < linkFns.length; i+=3) { |
| 7027 | idx = linkFns[i]; |
| 7028 | stableNodeList[idx] = nodeList[idx]; |
no test coverage detected