MCPcopy Index your code
hub / github.com/angular-ui/ui-grid / compile

Function compile

lib/test/angular/1.4.3/angular.js:7351–7419  ·  view source on GitHub ↗
($compileNodes, transcludeFn, maxPriority, ignoreDirective,
                        previousCompileContext)

Source from the content-addressed store, hash-verified

7349 //================================
7350
7351 function compile($compileNodes, transcludeFn, maxPriority, ignoreDirective,
7352 previousCompileContext) {
7353 if (!($compileNodes instanceof jqLite)) {
7354 // jquery always rewraps, whereas we need to preserve the original selector so that we can
7355 // modify it.
7356 $compileNodes = jqLite($compileNodes);
7357 }
7358 // We can not compile top level text elements since text nodes can be merged and we will
7359 // not be able to attach scope data to them, so we will wrap them in <span>
7360 forEach($compileNodes, function(node, index) {
7361 if (node.nodeType == NODE_TYPE_TEXT && node.nodeValue.match(/\S+/) /* non-empty */ ) {
7362 $compileNodes[index] = jqLite(node).wrap('<span></span>').parent()[0];
7363 }
7364 });
7365 var compositeLinkFn =
7366 compileNodes($compileNodes, transcludeFn, $compileNodes,
7367 maxPriority, ignoreDirective, previousCompileContext);
7368 compile.$$addScopeClass($compileNodes);
7369 var namespace = null;
7370 return function publicLinkFn(scope, cloneConnectFn, options) {
7371 assertArg(scope, 'scope');
7372
7373 options = options || {};
7374 var parentBoundTranscludeFn = options.parentBoundTranscludeFn,
7375 transcludeControllers = options.transcludeControllers,
7376 futureParentElement = options.futureParentElement;
7377
7378 // When `parentBoundTranscludeFn` is passed, it is a
7379 // `controllersBoundTransclude` function (it was previously passed
7380 // as `transclude` to directive.link) so we must unwrap it to get
7381 // its `boundTranscludeFn`
7382 if (parentBoundTranscludeFn && parentBoundTranscludeFn.$$boundTransclude) {
7383 parentBoundTranscludeFn = parentBoundTranscludeFn.$$boundTransclude;
7384 }
7385
7386 if (!namespace) {
7387 namespace = detectNamespaceForChildElements(futureParentElement);
7388 }
7389 var $linkNode;
7390 if (namespace !== 'html') {
7391 // When using a directive with replace:true and templateUrl the $compileNodes
7392 // (or a child element inside of them)
7393 // might change, so we need to recreate the namespace adapted compileNodes
7394 // for call to the link function.
7395 // Note: This will already clone the nodes...
7396 $linkNode = jqLite(
7397 wrapTemplate(namespace, jqLite('<div>').append($compileNodes).html())
7398 );
7399 } else if (cloneConnectFn) {
7400 // important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
7401 // and sometimes changes the structure of the DOM.
7402 $linkNode = JQLitePrototype.clone.call($compileNodes);
7403 } else {
7404 $linkNode = $compileNodes;
7405 }
7406
7407 if (transcludeControllers) {
7408 for (var controllerName in transcludeControllers) {

Callers 3

doBootstrapFunction · 0.70
applyDirectivesToNodeFunction · 0.70

Calls 6

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

Tested by

no test coverage detected