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

Function compile

test/angular/1.4/angular.js:7776–7858  ·  view source on GitHub ↗
($compileNodes, transcludeFn, maxPriority, ignoreDirective,
                        previousCompileContext)

Source from the content-addressed store, hash-verified

7774 //================================
7775
7776 function compile($compileNodes, transcludeFn, maxPriority, ignoreDirective,
7777 previousCompileContext) {
7778 if (!($compileNodes instanceof jqLite)) {
7779 // jquery always rewraps, whereas we need to preserve the original selector so that we can
7780 // modify it.
7781 $compileNodes = jqLite($compileNodes);
7782 }
7783
7784 var NOT_EMPTY = /\S+/;
7785
7786 // We can not compile top level text elements since text nodes can be merged and we will
7787 // not be able to attach scope data to them, so we will wrap them in <span>
7788 for (var i = 0, len = $compileNodes.length; i < len; i++) {
7789 var domNode = $compileNodes[i];
7790
7791 if (domNode.nodeType === NODE_TYPE_TEXT && domNode.nodeValue.match(NOT_EMPTY) /* non-empty */) {
7792 jqLiteWrapNode(domNode, $compileNodes[i] = document.createElement('span'));
7793 }
7794 }
7795
7796 var compositeLinkFn =
7797 compileNodes($compileNodes, transcludeFn, $compileNodes,
7798 maxPriority, ignoreDirective, previousCompileContext);
7799 compile.$$addScopeClass($compileNodes);
7800 var namespace = null;
7801 return function publicLinkFn(scope, cloneConnectFn, options) {
7802 assertArg(scope, 'scope');
7803
7804 if (previousCompileContext && previousCompileContext.needsNewScope) {
7805 // A parent directive did a replace and a directive on this element asked
7806 // for transclusion, which caused us to lose a layer of element on which
7807 // we could hold the new transclusion scope, so we will create it manually
7808 // here.
7809 scope = scope.$parent.$new();
7810 }
7811
7812 options = options || {};
7813 var parentBoundTranscludeFn = options.parentBoundTranscludeFn,
7814 transcludeControllers = options.transcludeControllers,
7815 futureParentElement = options.futureParentElement;
7816
7817 // When `parentBoundTranscludeFn` is passed, it is a
7818 // `controllersBoundTransclude` function (it was previously passed
7819 // as `transclude` to directive.link) so we must unwrap it to get
7820 // its `boundTranscludeFn`
7821 if (parentBoundTranscludeFn && parentBoundTranscludeFn.$$boundTransclude) {
7822 parentBoundTranscludeFn = parentBoundTranscludeFn.$$boundTransclude;
7823 }
7824
7825 if (!namespace) {
7826 namespace = detectNamespaceForChildElements(futureParentElement);
7827 }
7828 var $linkNode;
7829 if (namespace !== 'html') {
7830 // When using a directive with replace:true and templateUrl the $compileNodes
7831 // (or a child element inside of them)
7832 // might change, so we need to recreate the namespace adapted compileNodes
7833 // for call to the link function.

Callers 2

doBootstrapFunction · 0.70
applyDirectivesToNodeFunction · 0.70

Calls 7

matchMethod · 0.80
jqLiteWrapNodeFunction · 0.70
compileNodesFunction · 0.70
assertArgFunction · 0.70
wrapTemplateFunction · 0.70
compositeLinkFnFunction · 0.70

Tested by

no test coverage detected