MCPcopy Create free account
hub / github.com/EricSimons/ionic-course / compile

Function compile

code/songhop/www/lib/angular/angular.js:6876–6944  ·  view source on GitHub ↗
($compileNodes, transcludeFn, maxPriority, ignoreDirective,
                        previousCompileContext)

Source from the content-addressed store, hash-verified

6874 //================================
6875
6876 function compile($compileNodes, transcludeFn, maxPriority, ignoreDirective,
6877 previousCompileContext) {
6878 if (!($compileNodes instanceof jqLite)) {
6879 // jquery always rewraps, whereas we need to preserve the original selector so that we can
6880 // modify it.
6881 $compileNodes = jqLite($compileNodes);
6882 }
6883 // We can not compile top level text elements since text nodes can be merged and we will
6884 // not be able to attach scope data to them, so we will wrap them in <span>
6885 forEach($compileNodes, function(node, index) {
6886 if (node.nodeType == NODE_TYPE_TEXT && node.nodeValue.match(/\S+/) /* non-empty */ ) {
6887 $compileNodes[index] = jqLite(node).wrap('<span></span>').parent()[0];
6888 }
6889 });
6890 var compositeLinkFn =
6891 compileNodes($compileNodes, transcludeFn, $compileNodes,
6892 maxPriority, ignoreDirective, previousCompileContext);
6893 compile.$$addScopeClass($compileNodes);
6894 var namespace = null;
6895 return function publicLinkFn(scope, cloneConnectFn, options) {
6896 assertArg(scope, 'scope');
6897
6898 options = options || {};
6899 var parentBoundTranscludeFn = options.parentBoundTranscludeFn,
6900 transcludeControllers = options.transcludeControllers,
6901 futureParentElement = options.futureParentElement;
6902
6903 // When `parentBoundTranscludeFn` is passed, it is a
6904 // `controllersBoundTransclude` function (it was previously passed
6905 // as `transclude` to directive.link) so we must unwrap it to get
6906 // its `boundTranscludeFn`
6907 if (parentBoundTranscludeFn && parentBoundTranscludeFn.$$boundTransclude) {
6908 parentBoundTranscludeFn = parentBoundTranscludeFn.$$boundTransclude;
6909 }
6910
6911 if (!namespace) {
6912 namespace = detectNamespaceForChildElements(futureParentElement);
6913 }
6914 var $linkNode;
6915 if (namespace !== 'html') {
6916 // When using a directive with replace:true and templateUrl the $compileNodes
6917 // (or a child element inside of them)
6918 // might change, so we need to recreate the namespace adapted compileNodes
6919 // for call to the link function.
6920 // Note: This will already clone the nodes...
6921 $linkNode = jqLite(
6922 wrapTemplate(namespace, jqLite('<div>').append($compileNodes).html())
6923 );
6924 } else if (cloneConnectFn) {
6925 // important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
6926 // and sometimes changes the structure of the DOM.
6927 $linkNode = JQLitePrototype.clone.call($compileNodes);
6928 } else {
6929 $linkNode = $compileNodes;
6930 }
6931
6932 if (transcludeControllers) {
6933 for (var controllerName in transcludeControllers) {

Callers 2

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