($compileNodes, transcludeFn, maxPriority, ignoreDirective,
previousCompileContext)
| 9034 | //================================ |
| 9035 | |
| 9036 | function compile($compileNodes, transcludeFn, maxPriority, ignoreDirective, |
| 9037 | previousCompileContext) { |
| 9038 | if (!($compileNodes instanceof jqLite)) { |
| 9039 | // jquery always rewraps, whereas we need to preserve the original selector so that we can |
| 9040 | // modify it. |
| 9041 | $compileNodes = jqLite($compileNodes); |
| 9042 | } |
| 9043 | var compositeLinkFn = |
| 9044 | compileNodes($compileNodes, transcludeFn, $compileNodes, |
| 9045 | maxPriority, ignoreDirective, previousCompileContext); |
| 9046 | compile.$$addScopeClass($compileNodes); |
| 9047 | var namespace = null; |
| 9048 | return function publicLinkFn(scope, cloneConnectFn, options) { |
| 9049 | if (!$compileNodes) { |
| 9050 | throw $compileMinErr('multilink', 'This element has already been linked.'); |
| 9051 | } |
| 9052 | assertArg(scope, 'scope'); |
| 9053 | |
| 9054 | if (previousCompileContext && previousCompileContext.needsNewScope) { |
| 9055 | // A parent directive did a replace and a directive on this element asked |
| 9056 | // for transclusion, which caused us to lose a layer of element on which |
| 9057 | // we could hold the new transclusion scope, so we will create it manually |
| 9058 | // here. |
| 9059 | scope = scope.$parent.$new(); |
| 9060 | } |
| 9061 | |
| 9062 | options = options || {}; |
| 9063 | var parentBoundTranscludeFn = options.parentBoundTranscludeFn, |
| 9064 | transcludeControllers = options.transcludeControllers, |
| 9065 | futureParentElement = options.futureParentElement; |
| 9066 | |
| 9067 | // When `parentBoundTranscludeFn` is passed, it is a |
| 9068 | // `controllersBoundTransclude` function (it was previously passed |
| 9069 | // as `transclude` to directive.link) so we must unwrap it to get |
| 9070 | // its `boundTranscludeFn` |
| 9071 | if (parentBoundTranscludeFn && parentBoundTranscludeFn.$$boundTransclude) { |
| 9072 | parentBoundTranscludeFn = parentBoundTranscludeFn.$$boundTransclude; |
| 9073 | } |
| 9074 | |
| 9075 | if (!namespace) { |
| 9076 | namespace = detectNamespaceForChildElements(futureParentElement); |
| 9077 | } |
| 9078 | var $linkNode; |
| 9079 | if (namespace !== 'html') { |
| 9080 | // When using a directive with replace:true and templateUrl the $compileNodes |
| 9081 | // (or a child element inside of them) |
| 9082 | // might change, so we need to recreate the namespace adapted compileNodes |
| 9083 | // for call to the link function. |
| 9084 | // Note: This will already clone the nodes... |
| 9085 | $linkNode = jqLite( |
| 9086 | wrapTemplate(namespace, jqLite('<div>').append($compileNodes).html()) |
| 9087 | ); |
| 9088 | } else if (cloneConnectFn) { |
| 9089 | // important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart |
| 9090 | // and sometimes changes the structure of the DOM. |
| 9091 | $linkNode = JQLitePrototype.clone.call($compileNodes); |
| 9092 | } else { |
| 9093 | $linkNode = $compileNodes; |
no test coverage detected