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

Function compile

test/angular/1.2/angular.js:6012–6055  ·  view source on GitHub ↗
($compileNodes, transcludeFn, maxPriority, ignoreDirective,
                        previousCompileContext)

Source from the content-addressed store, hash-verified

6010 //================================
6011
6012 function compile($compileNodes, transcludeFn, maxPriority, ignoreDirective,
6013 previousCompileContext) {
6014 if (!($compileNodes instanceof jqLite)) {
6015 // jquery always rewraps, whereas we need to preserve the original selector so that we can
6016 // modify it.
6017 $compileNodes = jqLite($compileNodes);
6018 }
6019 // We can not compile top level text elements since text nodes can be merged and we will
6020 // not be able to attach scope data to them, so we will wrap them in <span>
6021 forEach($compileNodes, function(node, index){
6022 if (node.nodeType == 3 /* text node */ && node.nodeValue.match(/\S+/) /* non-empty */ ) {
6023 $compileNodes[index] = node = jqLite(node).wrap('<span></span>').parent()[0];
6024 }
6025 });
6026 var compositeLinkFn =
6027 compileNodes($compileNodes, transcludeFn, $compileNodes,
6028 maxPriority, ignoreDirective, previousCompileContext);
6029 safeAddClass($compileNodes, 'ng-scope');
6030 return function publicLinkFn(scope, cloneConnectFn, transcludeControllers, parentBoundTranscludeFn){
6031 assertArg(scope, 'scope');
6032 // important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
6033 // and sometimes changes the structure of the DOM.
6034 var $linkNode = cloneConnectFn
6035 ? JQLitePrototype.clone.call($compileNodes) // IMPORTANT!!!
6036 : $compileNodes;
6037
6038 forEach(transcludeControllers, function(instance, name) {
6039 $linkNode.data('$' + name + 'Controller', instance);
6040 });
6041
6042 // Attach scope only to non-text nodes.
6043 for(var i = 0, ii = $linkNode.length; i<ii; i++) {
6044 var node = $linkNode[i],
6045 nodeType = node.nodeType;
6046 if (nodeType === 1 /* element */ || nodeType === 9 /* document */) {
6047 $linkNode.eq(i).data('$scope', scope);
6048 }
6049 }
6050
6051 if (cloneConnectFn) cloneConnectFn($linkNode, scope);
6052 if (compositeLinkFn) compositeLinkFn(scope, $linkNode, $linkNode, parentBoundTranscludeFn);
6053 return $linkNode;
6054 };
6055 }
6056
6057 function safeAddClass($element, className) {
6058 try {

Callers 2

doBootstrapFunction · 0.70
applyDirectivesToNodeFunction · 0.70

Calls 6

matchMethod · 0.80
forEachFunction · 0.70
compileNodesFunction · 0.70
safeAddClassFunction · 0.70
assertArgFunction · 0.70
compositeLinkFnFunction · 0.70

Tested by

no test coverage detected