34255 lines · 1.2 MB · JavaScript
RawDownload
                attr[name] = interpolateFn(scope);                 ($$observers[name] || ($$observers[name] = [])).$$inter = true;                (attr.$$observers && attr.$$observers[name].$$scope || scope).                  $watch(interpolateFn, function interpolateFnWatchAction(newValue, oldValue) {                    //special case for class attribute addition + removal                    //so that class changes can tap into the animation                    //hooks provided by the $animate service. Be sure to                    //skip animations when the first digest occurs (when                    //both the new and the old values are the same) since                    //the CSS classes are the non-interpolated values                    if (name === 'class' && newValue !== oldValue) {                      attr.$updateClass(newValue, oldValue);                    } else {                      attr.$set(name, newValue);                    }                  });              }            };          }      });    }      /**     * This is a special jqLite.replaceWith, which can replace items which     * have no parents, provided that the containing jqLite collection is provided.     *     * @param {JqLite=} $rootElement The root of the compile tree. Used so that we can replace nodes     *                               in the root of the tree.     * @param {JqLite} elementsToRemove The jqLite element which we are going to replace. We keep     *                                  the shell, but replace its DOM node reference.     * @param {Node} newNode The new DOM node.     */    function replaceWith($rootElement, elementsToRemove, newNode) {      var firstElementToRemove = elementsToRemove[0],          removeCount = elementsToRemove.length,          parent = firstElementToRemove.parentNode,          i, ii;       if ($rootElement) {        for (i = 0, ii = $rootElement.length; i < ii; i++) {          if ($rootElement[i] === firstElementToRemove) {            $rootElement[i++] = newNode;            for (var j = i, j2 = j + removeCount - 1,                     jj = $rootElement.length;                 j < jj; j++, j2++) {              if (j2 < jj) {                $rootElement[j] = $rootElement[j2];              } else {                delete $rootElement[j];              }            }            $rootElement.length -= removeCount - 1;             // If the replaced element is also the jQuery .context then replace it            // .context is a deprecated jQuery api, so we should set it only when jQuery set it            // http://api.jquery.com/context/            if ($rootElement.context === firstElementToRemove) {              $rootElement.context = newNode;            }            break;          }        }      }       if (parent) {        parent.replaceChild(newNode, firstElementToRemove);      }       // Append all the `elementsToRemove` to a fragment. This will...      // - remove them from the DOM      // - allow them to still be traversed with .nextSibling      // - allow a single fragment.qSA to fetch all elements being removed      var fragment = window.document.createDocumentFragment();      for (i = 0; i < removeCount; i++) {        fragment.appendChild(elementsToRemove[i]);      }       if (jqLite.hasData(firstElementToRemove)) {        // Copy over user data (that includes Angular's $scope etc.). Don't copy private        // data here because there's no public interface in jQuery to do that and copying over        // event listeners (which is the main use of private data) wouldn't work anyway.        jqLite.data(newNode, jqLite.data(firstElementToRemove));         // Remove $destroy event listeners from `firstElementToRemove`        jqLite(firstElementToRemove).off('$destroy');      }       // Cleanup any data/listeners on the elements and children.      // This includes invoking the $destroy event on any elements with listeners.      jqLite.cleanData(fragment.querySelectorAll('*'));       // Update the jqLite collection to only contain the `newNode`      for (i = 1; i < removeCount; i++) {        delete elementsToRemove[i];      }      elementsToRemove[0] = newNode;      elementsToRemove.length = 1;    }      function cloneAndAnnotateFn(fn, annotation) {      return extend(function() { return fn.apply(null, arguments); }, fn, annotation);    }      function invokeLinkFn(linkFn, scope, $element, attrs, controllers, transcludeFn) {      try {        linkFn(scope, $element, attrs, controllers, transcludeFn);      } catch (e) {        $exceptionHandler(e, startingTag($element));      }    }     function strictBindingsCheck(attrName, directiveName) {      if (strictComponentBindingsEnabled) {        throw $compileMinErr('missingattr',          'Attribute \'{0}\' of \'{1}\' is non-optional and must be set!',          attrName, directiveName);      }    }     // Set up $watches for isolate scope and controller bindings.    function initializeDirectiveBindings(scope, attrs, destination, bindings, directive) {      var removeWatchCollection = [];      var initialChanges = {};      var changes;       forEach(bindings, function initializeBinding(definition, scopeName) {        var attrName = definition.attrName,        optional = definition.optional,        mode = definition.mode, // @, =, <, or &        lastValue,        parentGet, parentSet, compare, removeWatch;         switch (mode) {           case '@':            if (!optional && !hasOwnProperty.call(attrs, attrName)) {              strictBindingsCheck(attrName, directive.name);              destination[scopeName] = attrs[attrName] = undefined;             }            removeWatch = attrs.$observe(attrName, function(value) {              if (isString(value) || isBoolean(value)) {                var oldValue = destination[scopeName];                recordChanges(scopeName, value, oldValue);                destination[scopeName] = value;              }            });            attrs.$$observers[attrName].$$scope = scope;            lastValue = attrs[attrName];            if (isString(lastValue)) {              // If the attribute has been provided then we trigger an interpolation to ensure              // the value is there for use in the link fn              destination[scopeName] = $interpolate(lastValue)(scope);            } else if (isBoolean(lastValue)) {              // If the attributes is one of the BOOLEAN_ATTR then Angular will have converted              // the value to boolean rather than a string, so we special case this situation              destination[scopeName] = lastValue;            }            initialChanges[scopeName] = new SimpleChange(_UNINITIALIZED_VALUE, destination[scopeName]);            removeWatchCollection.push(removeWatch);            break;           case '=':            if (!hasOwnProperty.call(attrs, attrName)) {              if (optional) break;              strictBindingsCheck(attrName, directive.name);              attrs[attrName] = undefined;            }            if (optional && !attrs[attrName]) break;             parentGet = $parse(attrs[attrName]);            if (parentGet.literal) {              compare = equals;            } else {              compare = simpleCompare;            }            parentSet = parentGet.assign || function() {              // reset the change, or we will throw this exception on every $digest              lastValue = destination[scopeName] = parentGet(scope);              throw $compileMinErr('nonassign',                  'Expression \'{0}\' in attribute \'{1}\' used with directive \'{2}\' is non-assignable!',                  attrs[attrName], attrName, directive.name);            };            lastValue = destination[scopeName] = parentGet(scope);            var parentValueWatch = function parentValueWatch(parentValue) {              if (!compare(parentValue, destination[scopeName])) {                // we are out of sync and need to copy                if (!compare(parentValue, lastValue)) {                  // parent changed and it has precedence                  destination[scopeName] = parentValue;                } else {                  // if the parent can be assigned then do so                  parentSet(scope, parentValue = destination[scopeName]);                }              }              lastValue = parentValue;              return lastValue;            };            parentValueWatch.$stateful = true;            if (definition.collection) {              removeWatch = scope.$watchCollection(attrs[attrName], parentValueWatch);            } else {              removeWatch = scope.$watch($parse(attrs[attrName], parentValueWatch), null, parentGet.literal);            }            removeWatchCollection.push(removeWatch);            break;           case '<':            if (!hasOwnProperty.call(attrs, attrName)) {              if (optional) break;              strictBindingsCheck(attrName, directive.name);              attrs[attrName] = undefined;            }            if (optional && !attrs[attrName]) break;             parentGet = $parse(attrs[attrName]);            var deepWatch = parentGet.literal;             var initialValue = destination[scopeName] = parentGet(scope);            initialChanges[scopeName] = new SimpleChange(_UNINITIALIZED_VALUE, destination[scopeName]);             removeWatch = scope.$watch(parentGet, function parentValueWatchAction(newValue, oldValue) {              if (oldValue === newValue) {                if (oldValue === initialValue || (deepWatch && equals(oldValue, initialValue))) {                  return;                }                oldValue = initialValue;              }              recordChanges(scopeName, newValue, oldValue);              destination[scopeName] = newValue;            }, deepWatch);             removeWatchCollection.push(removeWatch);            break;           case '&':            if (!optional && !hasOwnProperty.call(attrs, attrName)) {              strictBindingsCheck(attrName, directive.name);            }            // Don't assign Object.prototype method to scope            parentGet = attrs.hasOwnProperty(attrName) ? $parse(attrs[attrName]) : noop;             // Don't assign noop to destination if expression is not valid            if (parentGet === noop && optional) break;             destination[scopeName] = function(locals) {              return parentGet(scope, locals);            };            break;        }      });       function recordChanges(key, currentValue, previousValue) {        if (isFunction(destination.$onChanges) && !simpleCompare(currentValue, previousValue)) {          // If we have not already scheduled the top level onChangesQueue handler then do so now          if (!onChangesQueue) {            scope.$$postDigest(flushOnChangesQueue);            onChangesQueue = [];          }          // If we have not already queued a trigger of onChanges for this controller then do so now          if (!changes) {            changes = {};            onChangesQueue.push(triggerOnChangesHook);          }          // If the has been a change on this property already then we need to reuse the previous value          if (changes[key]) {            previousValue = changes[key].previousValue;          }          // Store this change          changes[key] = new SimpleChange(previousValue, currentValue);        }      }       function triggerOnChangesHook() {        destination.$onChanges(changes);        // Now clear the changes so that we schedule onChanges when more changes arrive        changes = undefined;      }       return {        initialChanges: initialChanges,        removeWatches: removeWatchCollection.length && function removeWatches() {          for (var i = 0, ii = removeWatchCollection.length; i < ii; ++i) {            removeWatchCollection[i]();          }        }      };    }  }];} function SimpleChange(previous, current) {  this.previousValue = previous;  this.currentValue = current;}SimpleChange.prototype.isFirstChange = function() { return this.previousValue === _UNINITIALIZED_VALUE; };  var PREFIX_REGEXP = /^((?:x|data)[:\-_])/i;var SPECIAL_CHARS_REGEXP = /[:\-_]+(.)/g; /** * Converts all accepted directives format into proper directive name. * @param name Name to normalize */function directiveNormalize(name) {  return name    .replace(PREFIX_REGEXP, '')    .replace(SPECIAL_CHARS_REGEXP, function(_, letter, offset) {      return offset ? letter.toUpperCase() : letter;    });} /** * @ngdoc type * @name $compile.directive.Attributes * * @description * A shared object between directive compile / linking functions which contains normalized DOM * element attributes. The values reflect current binding state `{{ }}`. The normalization is * needed since all of these are treated as equivalent in Angular: * * ``` *    <span ng:bind="a" ng-bind="a" data-ng-bind="a" x-ng-bind="a"> * ``` */ /** * @ngdoc property * @name $compile.directive.Attributes#$attr * * @description * A map of DOM element attribute names to the normalized name. This is * needed to do reverse lookup from normalized name back to actual name. */  /** * @ngdoc method * @name $compile.directive.Attributes#$set * @kind function * * @description * Set DOM element attribute value. * * * @param {string} name Normalized element attribute name of the property to modify. The name is *          reverse-translated using the {@link ng.$compile.directive.Attributes#$attr $attr} *          property to the original name. * @param {string} value Value to set the attribute to. The value can be an interpolated string. */   /** * Closure compiler type information */ function nodesetLinkingFn(  /* angular.Scope */ scope,  /* NodeList */ nodeList,  /* Element */ rootElement,  /* function(Function) */ boundTranscludeFn) {} function directiveLinkingFn(  /* nodesetLinkingFn */ nodesetLinkingFn,  /* angular.Scope */ scope,  /* Node */ node,  /* Element */ rootElement,  /* function(Function) */ boundTranscludeFn) {} function tokenDifference(str1, str2) {  var values = '',      tokens1 = str1.split(/\s+/),      tokens2 = str2.split(/\s+/);   outer:  for (var i = 0; i < tokens1.length; i++) {    var token = tokens1[i];    for (var j = 0; j < tokens2.length; j++) {      if (token === tokens2[j]) continue outer;    }    values += (values.length > 0 ? ' ' : '') + token;  }  return values;} function removeComments(jqNodes) {  jqNodes = jqLite(jqNodes);  var i = jqNodes.length;   if (i <= 1) {    return jqNodes;  }   while (i--) {    var node = jqNodes[i];    if (node.nodeType === NODE_TYPE_COMMENT ||       (node.nodeType === NODE_TYPE_TEXT && node.nodeValue.trim() === '')) {         splice.call(jqNodes, i, 1);    }  }  return jqNodes;} var $controllerMinErr = minErr('$controller');  var CNTRL_REG = /^(\S+)(\s+as\s+([\w$]+))?$/;function identifierForController(controller, ident) {  if (ident && isString(ident)) return ident;  if (isString(controller)) {    var match = CNTRL_REG.exec(controller);    if (match) return match[3];  }}  /** * @ngdoc provider * @name $controllerProvider * @this * * @description * The {@link ng.$controller $controller service} is used by Angular to create new * controllers. * * This provider allows controller registration via the * {@link ng.$controllerProvider#register register} method. */function $ControllerProvider() {  var controllers = {},      globals = false;   /**   * @ngdoc method   * @name $controllerProvider#has   * @param {string} name Controller name to check.   */  this.has = function(name) {    return controllers.hasOwnProperty(name);  };   /**   * @ngdoc method   * @name $controllerProvider#register   * @param {string|Object} name Controller name, or an object map of controllers where the keys are   *    the names and the values are the constructors.   * @param {Function|Array} constructor Controller constructor fn (optionally decorated with DI   *    annotations in the array notation).   */  this.register = function(name, constructor) {    assertNotHasOwnProperty(name, 'controller');    if (isObject(name)) {      extend(controllers, name);    } else {      controllers[name] = constructor;    }  };   /**   * @ngdoc method   * @name $controllerProvider#allowGlobals   * @description If called, allows `$controller` to find controller constructors on `window`   *   * @deprecated   * sinceVersion="v1.3.0"   * removeVersion="v1.7.0"   * This method of finding controllers has been deprecated.   */  this.allowGlobals = function() {    globals = true;  };    this.$get = ['$injector', '$window', function($injector, $window) {     /**     * @ngdoc service     * @name $controller     * @requires $injector     *     * @param {Function|string} constructor If called with a function then it's considered to be the     *    controller constructor function. Otherwise it's considered to be a string which is used     *    to retrieve the controller constructor using the following steps:     *     *    * check if a controller with given name is registered via `$controllerProvider`     *    * check if evaluating the string on the current scope returns a constructor     *    * if $controllerProvider#allowGlobals, check `window[constructor]` on the global     *      `window` object (deprecated, not recommended)     *     *    The string can use the `controller as property` syntax, where the controller instance is published     *    as the specified property on the `scope`; the `scope` must be injected into `locals` param for this     *    to work correctly.

Lines 10501–11000 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