MCPcopy
hub / github.com/angular-ui/ui-router / compile

Function compile

test/angular/1.6/angular.js:9107–9183  ·  view source on GitHub ↗
($compileNodes, transcludeFn, maxPriority, ignoreDirective,
                        previousCompileContext)

Source from the content-addressed store, hash-verified

9105 //================================
9106
9107 function compile($compileNodes, transcludeFn, maxPriority, ignoreDirective,
9108 previousCompileContext) {
9109 if (!($compileNodes instanceof jqLite)) {
9110 // jquery always rewraps, whereas we need to preserve the original selector so that we can
9111 // modify it.
9112 $compileNodes = jqLite($compileNodes);
9113 }
9114 var compositeLinkFn =
9115 compileNodes($compileNodes, transcludeFn, $compileNodes,
9116 maxPriority, ignoreDirective, previousCompileContext);
9117 compile.$$addScopeClass($compileNodes);
9118 var namespace = null;
9119 return function publicLinkFn(scope, cloneConnectFn, options) {
9120 if (!$compileNodes) {
9121 throw $compileMinErr('multilink', 'This element has already been linked.');
9122 }
9123 assertArg(scope, 'scope');
9124
9125 if (previousCompileContext && previousCompileContext.needsNewScope) {
9126 // A parent directive did a replace and a directive on this element asked
9127 // for transclusion, which caused us to lose a layer of element on which
9128 // we could hold the new transclusion scope, so we will create it manually
9129 // here.
9130 scope = scope.$parent.$new();
9131 }
9132
9133 options = options || {};
9134 var parentBoundTranscludeFn = options.parentBoundTranscludeFn,
9135 transcludeControllers = options.transcludeControllers,
9136 futureParentElement = options.futureParentElement;
9137
9138 // When `parentBoundTranscludeFn` is passed, it is a
9139 // `controllersBoundTransclude` function (it was previously passed
9140 // as `transclude` to directive.link) so we must unwrap it to get
9141 // its `boundTranscludeFn`
9142 if (parentBoundTranscludeFn && parentBoundTranscludeFn.$$boundTransclude) {
9143 parentBoundTranscludeFn = parentBoundTranscludeFn.$$boundTransclude;
9144 }
9145
9146 if (!namespace) {
9147 namespace = detectNamespaceForChildElements(futureParentElement);
9148 }
9149 var $linkNode;
9150 if (namespace !== 'html') {
9151 // When using a directive with replace:true and templateUrl the $compileNodes
9152 // (or a child element inside of them)
9153 // might change, so we need to recreate the namespace adapted compileNodes
9154 // for call to the link function.
9155 // Note: This will already clone the nodes...
9156 $linkNode = jqLite(
9157 wrapTemplate(namespace, jqLite('<div></div>').append($compileNodes).html())
9158 );
9159 } else if (cloneConnectFn) {
9160 // important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
9161 // and sometimes changes the structure of the DOM.
9162 $linkNode = JQLitePrototype.clone.call($compileNodes);
9163 } else {
9164 $linkNode = $compileNodes;

Callers 2

doBootstrapFunction · 0.70
compilationGeneratorFunction · 0.70

Calls 5

compileNodesFunction · 0.70
assertArgFunction · 0.70
wrapTemplateFunction · 0.70
compositeLinkFnFunction · 0.70

Tested by

no test coverage detected