MCPcopy Create free account
hub / github.com/apache/cloudstack / compile

Function compile

tools/ngui/static/js/lib/angular.js:3890–3923  ·  view source on GitHub ↗
($compileNodes, transcludeFn, maxPriority)

Source from the content-addressed store, hash-verified

3888 //================================
3889
3890 function compile($compileNodes, transcludeFn, maxPriority) {
3891 if (!($compileNodes instanceof jqLite)) {
3892 // jquery always rewraps, whereas we need to preserve the original selector so that we can modify it.
3893 $compileNodes = jqLite($compileNodes);
3894 }
3895 // We can not compile top level text elements since text nodes can be merged and we will
3896 // not be able to attach scope data to them, so we will wrap them in <span>
3897 forEach($compileNodes, function(node, index){
3898 if (node.nodeType == 3 /* text node */ && node.nodeValue.match(/\S+/) /* non-empty */ ) {
3899 $compileNodes[index] = jqLite(node).wrap('<span></span>').parent()[0];
3900 }
3901 });
3902 var compositeLinkFn = compileNodes($compileNodes, transcludeFn, $compileNodes, maxPriority);
3903 return function publicLinkFn(scope, cloneConnectFn){
3904 assertArg(scope, 'scope');
3905 // important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
3906 // and sometimes changes the structure of the DOM.
3907 var $linkNode = cloneConnectFn
3908 ? JQLitePrototype.clone.call($compileNodes) // IMPORTANT!!!
3909 : $compileNodes;
3910
3911 // Attach scope only to non-text nodes.
3912 for(var i = 0, ii = $linkNode.length; i<ii; i++) {
3913 var node = $linkNode[i];
3914 if (node.nodeType == 1 /* element */ || node.nodeType == 9 /* document */) {
3915 $linkNode.eq(i).data('$scope', scope);
3916 }
3917 }
3918 safeAddClass($linkNode, 'ng-scope');
3919 if (cloneConnectFn) cloneConnectFn($linkNode, scope);
3920 if (compositeLinkFn) compositeLinkFn(scope, $linkNode, $linkNode);
3921 return $linkNode;
3922 };
3923 }
3924
3925 function wrongMode(localName, mode) {
3926 throw Error("Unsupported '" + mode + "' for '" + localName + "'.");

Callers 2

resumeBootstrapInternalFunction · 0.85
applyDirectivesToNodeFunction · 0.85

Calls 10

forEachFunction · 0.85
compileNodesFunction · 0.85
assertArgFunction · 0.85
safeAddClassFunction · 0.85
compositeLinkFnFunction · 0.85
parentMethod · 0.80
eqMethod · 0.80
matchMethod · 0.45
callMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected