34255 lines · 1.2 MB · JavaScript
RawDownload
              $element,              attrs,              linkFn.require && getControllers(linkFn.directiveName, linkFn.require, $element, elementControllers),              transcludeFn          );        }         // Trigger $postLink lifecycle hooks        forEach(elementControllers, function(controller) {          var controllerInstance = controller.instance;          if (isFunction(controllerInstance.$postLink)) {            controllerInstance.$postLink();          }        });         // This is the function that is injected as `$transclude`.        // Note: all arguments are optional!        function controllersBoundTransclude(scope, cloneAttachFn, futureParentElement, slotName) {          var transcludeControllers;          // No scope passed in:          if (!isScope(scope)) {            slotName = futureParentElement;            futureParentElement = cloneAttachFn;            cloneAttachFn = scope;            scope = undefined;          }           if (hasElementTranscludeDirective) {            transcludeControllers = elementControllers;          }          if (!futureParentElement) {            futureParentElement = hasElementTranscludeDirective ? $element.parent() : $element;          }          if (slotName) {            // slotTranscludeFn can be one of three things:            //  * a transclude function - a filled slot            //  * `null` - an optional slot that was not filled            //  * `undefined` - a slot that was not declared (i.e. invalid)            var slotTranscludeFn = boundTranscludeFn.$$slots[slotName];            if (slotTranscludeFn) {              return slotTranscludeFn(scope, cloneAttachFn, transcludeControllers, futureParentElement, scopeToChild);            } else if (isUndefined(slotTranscludeFn)) {              throw $compileMinErr('noslot',               'No parent directive that requires a transclusion with slot name "{0}". ' +               'Element: {1}',               slotName, startingTag($element));            }          } else {            return boundTranscludeFn(scope, cloneAttachFn, transcludeControllers, futureParentElement, scopeToChild);          }        }      }    }     function getControllers(directiveName, require, $element, elementControllers) {      var value;       if (isString(require)) {        var match = require.match(REQUIRE_PREFIX_REGEXP);        var name = require.substring(match[0].length);        var inheritType = match[1] || match[3];        var optional = match[2] === '?';         //If only parents then start at the parent element        if (inheritType === '^^') {          $element = $element.parent();        //Otherwise attempt getting the controller from elementControllers in case        //the element is transcluded (and has no data) and to avoid .data if possible        } else {          value = elementControllers && elementControllers[name];          value = value && value.instance;        }         if (!value) {          var dataName = '$' + name + 'Controller';          value = inheritType ? $element.inheritedData(dataName) : $element.data(dataName);        }         if (!value && !optional) {          throw $compileMinErr('ctreq',              'Controller \'{0}\', required by directive \'{1}\', can\'t be found!',              name, directiveName);        }      } else if (isArray(require)) {        value = [];        for (var i = 0, ii = require.length; i < ii; i++) {          value[i] = getControllers(directiveName, require[i], $element, elementControllers);        }      } else if (isObject(require)) {        value = {};        forEach(require, function(controller, property) {          value[property] = getControllers(directiveName, controller, $element, elementControllers);        });      }       return value || null;    }     function setupControllers($element, attrs, transcludeFn, controllerDirectives, isolateScope, scope, newIsolateScopeDirective) {      var elementControllers = createMap();      for (var controllerKey in controllerDirectives) {        var directive = controllerDirectives[controllerKey];        var locals = {          $scope: directive === newIsolateScopeDirective || directive.$$isolateScope ? isolateScope : scope,          $element: $element,          $attrs: attrs,          $transclude: transcludeFn        };         var controller = directive.controller;        if (controller === '@') {          controller = attrs[directive.name];        }         var controllerInstance = $controller(controller, locals, true, directive.controllerAs);         // For directives with element transclusion the element is a comment.        // In this case .data will not attach any data.        // Instead, we save the controllers for the element in a local hash and attach to .data        // later, once we have the actual element.        elementControllers[directive.name] = controllerInstance;        $element.data('$' + directive.name + 'Controller', controllerInstance.instance);      }      return elementControllers;    }     // Depending upon the context in which a directive finds itself it might need to have a new isolated    // or child scope created. For instance:    // * if the directive has been pulled into a template because another directive with a higher priority    // asked for element transclusion    // * if the directive itself asks for transclusion but it is at the root of a template and the original    // element was replaced. See https://github.com/angular/angular.js/issues/12936    function markDirectiveScope(directives, isolateScope, newScope) {      for (var j = 0, jj = directives.length; j < jj; j++) {        directives[j] = inherit(directives[j], {$$isolateScope: isolateScope, $$newScope: newScope});      }    }     /**     * looks up the directive and decorates it with exception handling and proper parameters. We     * call this the boundDirective.     *     * @param {string} name name of the directive to look up.     * @param {string} location The directive must be found in specific format.     *   String containing any of theses characters:     *     *   * `E`: element name     *   * `A': attribute     *   * `C`: class     *   * `M`: comment     * @returns {boolean} true if directive was added.     */    function addDirective(tDirectives, name, location, maxPriority, ignoreDirective, startAttrName,                          endAttrName) {      if (name === ignoreDirective) return null;      var match = null;      if (hasDirectives.hasOwnProperty(name)) {        for (var directive, directives = $injector.get(name + Suffix),            i = 0, ii = directives.length; i < ii; i++) {          directive = directives[i];          if ((isUndefined(maxPriority) || maxPriority > directive.priority) &&               directive.restrict.indexOf(location) !== -1) {            if (startAttrName) {              directive = inherit(directive, {$$start: startAttrName, $$end: endAttrName});            }            if (!directive.$$bindings) {              var bindings = directive.$$bindings =                  parseDirectiveBindings(directive, directive.name);              if (isObject(bindings.isolateScope)) {                directive.$$isolateBindings = bindings.isolateScope;              }            }            tDirectives.push(directive);            match = directive;          }        }      }      return match;    }      /**     * looks up the directive and returns true if it is a multi-element directive,     * and therefore requires DOM nodes between -start and -end markers to be grouped     * together.     *     * @param {string} name name of the directive to look up.     * @returns true if directive was registered as multi-element.     */    function directiveIsMultiElement(name) {      if (hasDirectives.hasOwnProperty(name)) {        for (var directive, directives = $injector.get(name + Suffix),            i = 0, ii = directives.length; i < ii; i++) {          directive = directives[i];          if (directive.multiElement) {            return true;          }        }      }      return false;    }     /**     * When the element is replaced with HTML template then the new attributes     * on the template need to be merged with the existing attributes in the DOM.     * The desired effect is to have both of the attributes present.     *     * @param {object} dst destination attributes (original DOM)     * @param {object} src source attributes (from the directive template)     */    function mergeTemplateAttributes(dst, src) {      var srcAttr = src.$attr,          dstAttr = dst.$attr;       // reapply the old attributes to the new element      forEach(dst, function(value, key) {        if (key.charAt(0) !== '$') {          if (src[key] && src[key] !== value) {            if (value.length) {              value += (key === 'style' ? ';' : ' ') + src[key];            } else {              value = src[key];            }          }          dst.$set(key, value, true, srcAttr[key]);        }      });       // copy the new attributes on the old attrs object      forEach(src, function(value, key) {        // Check if we already set this attribute in the loop above.        // `dst` will never contain hasOwnProperty as DOM parser won't let it.        // You will get an "InvalidCharacterError: DOM Exception 5" error if you        // have an attribute like "has-own-property" or "data-has-own-property", etc.        if (!dst.hasOwnProperty(key) && key.charAt(0) !== '$') {          dst[key] = value;           if (key !== 'class' && key !== 'style') {            dstAttr[key] = srcAttr[key];          }        }      });    }      function compileTemplateUrl(directives, $compileNode, tAttrs,        $rootElement, childTranscludeFn, preLinkFns, postLinkFns, previousCompileContext) {      var linkQueue = [],          afterTemplateNodeLinkFn,          afterTemplateChildLinkFn,          beforeTemplateCompileNode = $compileNode[0],          origAsyncDirective = directives.shift(),          derivedSyncDirective = inherit(origAsyncDirective, {            templateUrl: null, transclude: null, replace: null, $$originalDirective: origAsyncDirective          }),          templateUrl = (isFunction(origAsyncDirective.templateUrl))              ? origAsyncDirective.templateUrl($compileNode, tAttrs)              : origAsyncDirective.templateUrl,          templateNamespace = origAsyncDirective.templateNamespace;       $compileNode.empty();       $templateRequest(templateUrl)        .then(function(content) {          var compileNode, tempTemplateAttrs, $template, childBoundTranscludeFn;           content = denormalizeTemplate(content);           if (origAsyncDirective.replace) {            if (jqLiteIsTextNode(content)) {              $template = [];            } else {              $template = removeComments(wrapTemplate(templateNamespace, trim(content)));            }            compileNode = $template[0];             if ($template.length !== 1 || compileNode.nodeType !== NODE_TYPE_ELEMENT) {              throw $compileMinErr('tplrt',                  'Template for directive \'{0}\' must have exactly one root element. {1}',                  origAsyncDirective.name, templateUrl);            }             tempTemplateAttrs = {$attr: {}};            replaceWith($rootElement, $compileNode, compileNode);            var templateDirectives = collectDirectives(compileNode, [], tempTemplateAttrs);             if (isObject(origAsyncDirective.scope)) {              // the original directive that caused the template to be loaded async required              // an isolate scope              markDirectiveScope(templateDirectives, true);            }            directives = templateDirectives.concat(directives);            mergeTemplateAttributes(tAttrs, tempTemplateAttrs);          } else {            compileNode = beforeTemplateCompileNode;            $compileNode.html(content);          }           directives.unshift(derivedSyncDirective);           afterTemplateNodeLinkFn = applyDirectivesToNode(directives, compileNode, tAttrs,              childTranscludeFn, $compileNode, origAsyncDirective, preLinkFns, postLinkFns,              previousCompileContext);          forEach($rootElement, function(node, i) {            if (node === compileNode) {              $rootElement[i] = $compileNode[0];            }          });          afterTemplateChildLinkFn = compileNodes($compileNode[0].childNodes, childTranscludeFn);           while (linkQueue.length) {            var scope = linkQueue.shift(),                beforeTemplateLinkNode = linkQueue.shift(),                linkRootElement = linkQueue.shift(),                boundTranscludeFn = linkQueue.shift(),                linkNode = $compileNode[0];             if (scope.$$destroyed) continue;             if (beforeTemplateLinkNode !== beforeTemplateCompileNode) {              var oldClasses = beforeTemplateLinkNode.className;               if (!(previousCompileContext.hasElementTranscludeDirective &&                  origAsyncDirective.replace)) {                // it was cloned therefore we have to clone as well.                linkNode = jqLiteClone(compileNode);              }              replaceWith(linkRootElement, jqLite(beforeTemplateLinkNode), linkNode);               // Copy in CSS classes from original node              safeAddClass(jqLite(linkNode), oldClasses);            }            if (afterTemplateNodeLinkFn.transcludeOnThisElement) {              childBoundTranscludeFn = createBoundTranscludeFn(scope, afterTemplateNodeLinkFn.transclude, boundTranscludeFn);            } else {              childBoundTranscludeFn = boundTranscludeFn;            }            afterTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, linkNode, $rootElement,              childBoundTranscludeFn);          }          linkQueue = null;        }).catch(function(error) {          if (isError(error)) {            $exceptionHandler(error);          }        });       return function delayedNodeLinkFn(ignoreChildLinkFn, scope, node, rootElement, boundTranscludeFn) {        var childBoundTranscludeFn = boundTranscludeFn;        if (scope.$$destroyed) return;        if (linkQueue) {          linkQueue.push(scope,                         node,                         rootElement,                         childBoundTranscludeFn);        } else {          if (afterTemplateNodeLinkFn.transcludeOnThisElement) {            childBoundTranscludeFn = createBoundTranscludeFn(scope, afterTemplateNodeLinkFn.transclude, boundTranscludeFn);          }          afterTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, node, rootElement, childBoundTranscludeFn);        }      };    }      /**     * Sorting function for bound directives.     */    function byPriority(a, b) {      var diff = b.priority - a.priority;      if (diff !== 0) return diff;      if (a.name !== b.name) return (a.name < b.name) ? -1 : 1;      return a.index - b.index;    }     function assertNoDuplicate(what, previousDirective, directive, element) {       function wrapModuleNameIfDefined(moduleName) {        return moduleName ?          (' (module: ' + moduleName + ')') :          '';      }       if (previousDirective) {        throw $compileMinErr('multidir', 'Multiple directives [{0}{1}, {2}{3}] asking for {4} on: {5}',            previousDirective.name, wrapModuleNameIfDefined(previousDirective.$$moduleName),            directive.name, wrapModuleNameIfDefined(directive.$$moduleName), what, startingTag(element));      }    }      function addTextInterpolateDirective(directives, text) {      var interpolateFn = $interpolate(text, true);      if (interpolateFn) {        directives.push({          priority: 0,          compile: function textInterpolateCompileFn(templateNode) {            var templateNodeParent = templateNode.parent(),                hasCompileParent = !!templateNodeParent.length;             // When transcluding a template that has bindings in the root            // we don't have a parent and thus need to add the class during linking fn.            if (hasCompileParent) compile.$$addBindingClass(templateNodeParent);             return function textInterpolateLinkFn(scope, node) {              var parent = node.parent();              if (!hasCompileParent) compile.$$addBindingClass(parent);              compile.$$addBindingInfo(parent, interpolateFn.expressions);              scope.$watch(interpolateFn, function interpolateFnWatchAction(value) {                node[0].nodeValue = value;              });            };          }        });      }    }      function wrapTemplate(type, template) {      type = lowercase(type || 'html');      switch (type) {      case 'svg':      case 'math':        var wrapper = window.document.createElement('div');        wrapper.innerHTML = '<' + type + '>' + template + '</' + type + '>';        return wrapper.childNodes[0].childNodes;      default:        return template;      }    }      function getTrustedContext(node, attrNormalizedName) {      if (attrNormalizedName === 'srcdoc') {        return $sce.HTML;      }      var tag = nodeName_(node);      // All tags with src attributes require a RESOURCE_URL value, except for      // img and various html5 media tags.      if (attrNormalizedName === 'src' || attrNormalizedName === 'ngSrc') {        if (['img', 'video', 'audio', 'source', 'track'].indexOf(tag) === -1) {          return $sce.RESOURCE_URL;        }      // maction[xlink:href] can source SVG.  It's not limited to <maction>.      } else if (attrNormalizedName === 'xlinkHref' ||          (tag === 'form' && attrNormalizedName === 'action') ||          // links can be stylesheets or imports, which can run script in the current origin          (tag === 'link' && attrNormalizedName === 'href')      ) {        return $sce.RESOURCE_URL;      }    }      function addAttrInterpolateDirective(node, directives, value, name, isNgAttr) {      var trustedContext = getTrustedContext(node, name);      var mustHaveExpression = !isNgAttr;      var allOrNothing = ALL_OR_NOTHING_ATTRS[name] || isNgAttr;       var interpolateFn = $interpolate(value, mustHaveExpression, trustedContext, allOrNothing);       // no interpolation found -> ignore      if (!interpolateFn) return;       if (name === 'multiple' && nodeName_(node) === 'select') {        throw $compileMinErr('selmulti',            'Binding to the \'multiple\' attribute is not supported. Element: {0}',            startingTag(node));      }       if (EVENT_HANDLER_ATTR_REGEXP.test(name)) {        throw $compileMinErr('nodomevents',            'Interpolations for HTML DOM event attributes are disallowed.  Please use the ' +                'ng- versions (such as ng-click instead of onclick) instead.');      }       directives.push({        priority: 100,        compile: function() {            return {              pre: function attrInterpolatePreLinkFn(scope, element, attr) {                var $$observers = (attr.$$observers || (attr.$$observers = createMap()));                 // If the attribute has changed since last $interpolate()ed                var newValue = attr[name];                if (newValue !== value) {                  // we need to interpolate again since the attribute value has been updated                  // (e.g. by another directive's compile function)                  // ensure unset/empty values make interpolateFn falsy                  interpolateFn = newValue && $interpolate(newValue, true, trustedContext, allOrNothing);                  value = newValue;                }                 // if attribute was updated so that there is no interpolation going on we don't want to                // register any observers                if (!interpolateFn) return;                 // initialize attr object so that it's ready in case we need the value for isolate                // scope initialization, otherwise the value would not be available from isolate                // directive's linking fn during linking phase

Lines 10001–10500 of 34255. Previous lines

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t