34255 lines · 1.2 MB · JavaScript
RawDownload
        bindings = bindings.concat(binding);      } else {        bindings.push(binding);      }       $element.data('$binding', bindings);    } : noop;     compile.$$addBindingClass = debugInfoEnabled ? function $$addBindingClass($element) {      safeAddClass($element, 'ng-binding');    } : noop;     compile.$$addScopeInfo = debugInfoEnabled ? function $$addScopeInfo($element, scope, isolated, noTemplate) {      var dataName = isolated ? (noTemplate ? '$isolateScopeNoTemplate' : '$isolateScope') : '$scope';      $element.data(dataName, scope);    } : noop;     compile.$$addScopeClass = debugInfoEnabled ? function $$addScopeClass($element, isolated) {      safeAddClass($element, isolated ? 'ng-isolate-scope' : 'ng-scope');    } : noop;     compile.$$createComment = function(directiveName, comment) {      var content = '';      if (debugInfoEnabled) {        content = ' ' + (directiveName || '') + ': ';        if (comment) content += comment + ' ';      }      return window.document.createComment(content);    };     return compile;     //================================     function compile($compileNodes, transcludeFn, maxPriority, ignoreDirective,                        previousCompileContext) {      if (!($compileNodes instanceof jqLite)) {        // jquery always rewraps, whereas we need to preserve the original selector so that we can        // modify it.        $compileNodes = jqLite($compileNodes);      }      var compositeLinkFn =              compileNodes($compileNodes, transcludeFn, $compileNodes,                           maxPriority, ignoreDirective, previousCompileContext);      compile.$$addScopeClass($compileNodes);      var namespace = null;      return function publicLinkFn(scope, cloneConnectFn, options) {        if (!$compileNodes) {          throw $compileMinErr('multilink', 'This element has already been linked.');        }        assertArg(scope, 'scope');         if (previousCompileContext && previousCompileContext.needsNewScope) {          // A parent directive did a replace and a directive on this element asked          // for transclusion, which caused us to lose a layer of element on which          // we could hold the new transclusion scope, so we will create it manually          // here.          scope = scope.$parent.$new();        }         options = options || {};        var parentBoundTranscludeFn = options.parentBoundTranscludeFn,          transcludeControllers = options.transcludeControllers,          futureParentElement = options.futureParentElement;         // When `parentBoundTranscludeFn` is passed, it is a        // `controllersBoundTransclude` function (it was previously passed        // as `transclude` to directive.link) so we must unwrap it to get        // its `boundTranscludeFn`        if (parentBoundTranscludeFn && parentBoundTranscludeFn.$$boundTransclude) {          parentBoundTranscludeFn = parentBoundTranscludeFn.$$boundTransclude;        }         if (!namespace) {          namespace = detectNamespaceForChildElements(futureParentElement);        }        var $linkNode;        if (namespace !== 'html') {          // When using a directive with replace:true and templateUrl the $compileNodes          // (or a child element inside of them)          // might change, so we need to recreate the namespace adapted compileNodes          // for call to the link function.          // Note: This will already clone the nodes...          $linkNode = jqLite(            wrapTemplate(namespace, jqLite('<div>').append($compileNodes).html())          );        } else if (cloneConnectFn) {          // important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart          // and sometimes changes the structure of the DOM.          $linkNode = JQLitePrototype.clone.call($compileNodes);        } else {          $linkNode = $compileNodes;        }         if (transcludeControllers) {          for (var controllerName in transcludeControllers) {            $linkNode.data('$' + controllerName + 'Controller', transcludeControllers[controllerName].instance);          }        }         compile.$$addScopeInfo($linkNode, scope);         if (cloneConnectFn) cloneConnectFn($linkNode, scope);        if (compositeLinkFn) compositeLinkFn(scope, $linkNode, $linkNode, parentBoundTranscludeFn);         if (!cloneConnectFn) {          $compileNodes = compositeLinkFn = null;        }        return $linkNode;      };    }     function detectNamespaceForChildElements(parentElement) {      // TODO: Make this detect MathML as well...      var node = parentElement && parentElement[0];      if (!node) {        return 'html';      } else {        return nodeName_(node) !== 'foreignobject' && toString.call(node).match(/SVG/) ? 'svg' : 'html';      }    }     /**     * Compile function matches each node in nodeList against the directives. Once all directives     * for a particular node are collected their compile functions are executed. The compile     * functions return values - the linking functions - are combined into a composite linking     * function, which is the a linking function for the node.     *     * @param {NodeList} nodeList an array of nodes or NodeList to compile     * @param {function(angular.Scope, cloneAttachFn=)} transcludeFn A linking function, where the     *        scope argument is auto-generated to the new child of the transcluded parent scope.     * @param {DOMElement=} $rootElement If the nodeList is the root of the compilation tree then     *        the rootElement must be set the jqLite collection of the compile root. This is     *        needed so that the jqLite collection items can be replaced with widgets.     * @param {number=} maxPriority Max directive priority.     * @returns {Function} A composite linking function of all of the matched directives or null.     */    function compileNodes(nodeList, transcludeFn, $rootElement, maxPriority, ignoreDirective,                            previousCompileContext) {      var linkFns = [],          // `nodeList` can be either an element's `.childNodes` (live NodeList)          // or a jqLite/jQuery collection or an array          notLiveList = isArray(nodeList) || (nodeList instanceof jqLite),          attrs, directives, nodeLinkFn, childNodes, childLinkFn, linkFnFound, nodeLinkFnFound;        for (var i = 0; i < nodeList.length; i++) {        attrs = new Attributes();         // Support: IE 11 only        // Workaround for #11781 and #14924        if (msie === 11) {          mergeConsecutiveTextNodes(nodeList, i, notLiveList);        }         // We must always refer to `nodeList[i]` hereafter,        // since the nodes can be replaced underneath us.        directives = collectDirectives(nodeList[i], [], attrs, i === 0 ? maxPriority : undefined,                                        ignoreDirective);         nodeLinkFn = (directives.length)            ? applyDirectivesToNode(directives, nodeList[i], attrs, transcludeFn, $rootElement,                                      null, [], [], previousCompileContext)            : null;         if (nodeLinkFn && nodeLinkFn.scope) {          compile.$$addScopeClass(attrs.$$element);        }         childLinkFn = (nodeLinkFn && nodeLinkFn.terminal ||                      !(childNodes = nodeList[i].childNodes) ||                      !childNodes.length)            ? null            : compileNodes(childNodes,                 nodeLinkFn ? (                  (nodeLinkFn.transcludeOnThisElement || !nodeLinkFn.templateOnThisElement)                     && nodeLinkFn.transclude) : transcludeFn);         if (nodeLinkFn || childLinkFn) {          linkFns.push(i, nodeLinkFn, childLinkFn);          linkFnFound = true;          nodeLinkFnFound = nodeLinkFnFound || nodeLinkFn;        }         //use the previous context only for the first element in the virtual group        previousCompileContext = null;      }       // return a linking function if we have found anything, null otherwise      return linkFnFound ? compositeLinkFn : null;       function compositeLinkFn(scope, nodeList, $rootElement, parentBoundTranscludeFn) {        var nodeLinkFn, childLinkFn, node, childScope, i, ii, idx, childBoundTranscludeFn;        var stableNodeList;          if (nodeLinkFnFound) {          // copy nodeList so that if a nodeLinkFn removes or adds an element at this DOM level our          // offsets don't get screwed up          var nodeListLength = nodeList.length;          stableNodeList = new Array(nodeListLength);           // create a sparse array by only copying the elements which have a linkFn          for (i = 0; i < linkFns.length; i += 3) {            idx = linkFns[i];            stableNodeList[idx] = nodeList[idx];          }        } else {          stableNodeList = nodeList;        }         for (i = 0, ii = linkFns.length; i < ii;) {          node = stableNodeList[linkFns[i++]];          nodeLinkFn = linkFns[i++];          childLinkFn = linkFns[i++];           if (nodeLinkFn) {            if (nodeLinkFn.scope) {              childScope = scope.$new();              compile.$$addScopeInfo(jqLite(node), childScope);            } else {              childScope = scope;            }             if (nodeLinkFn.transcludeOnThisElement) {              childBoundTranscludeFn = createBoundTranscludeFn(                  scope, nodeLinkFn.transclude, parentBoundTranscludeFn);             } else if (!nodeLinkFn.templateOnThisElement && parentBoundTranscludeFn) {              childBoundTranscludeFn = parentBoundTranscludeFn;             } else if (!parentBoundTranscludeFn && transcludeFn) {              childBoundTranscludeFn = createBoundTranscludeFn(scope, transcludeFn);             } else {              childBoundTranscludeFn = null;            }             nodeLinkFn(childLinkFn, childScope, node, $rootElement, childBoundTranscludeFn);           } else if (childLinkFn) {            childLinkFn(scope, node.childNodes, undefined, parentBoundTranscludeFn);          }        }      }    }     function mergeConsecutiveTextNodes(nodeList, idx, notLiveList) {      var node = nodeList[idx];      var parent = node.parentNode;      var sibling;       if (node.nodeType !== NODE_TYPE_TEXT) {        return;      }       while (true) {        sibling = parent ? node.nextSibling : nodeList[idx + 1];        if (!sibling || sibling.nodeType !== NODE_TYPE_TEXT) {          break;        }         node.nodeValue = node.nodeValue + sibling.nodeValue;         if (sibling.parentNode) {          sibling.parentNode.removeChild(sibling);        }        if (notLiveList && sibling === nodeList[idx + 1]) {          nodeList.splice(idx + 1, 1);        }      }    }     function createBoundTranscludeFn(scope, transcludeFn, previousBoundTranscludeFn) {      function boundTranscludeFn(transcludedScope, cloneFn, controllers, futureParentElement, containingScope) {         if (!transcludedScope) {          transcludedScope = scope.$new(false, containingScope);          transcludedScope.$$transcluded = true;        }         return transcludeFn(transcludedScope, cloneFn, {          parentBoundTranscludeFn: previousBoundTranscludeFn,          transcludeControllers: controllers,          futureParentElement: futureParentElement        });      }       // We need  to attach the transclusion slots onto the `boundTranscludeFn`      // so that they are available inside the `controllersBoundTransclude` function      var boundSlots = boundTranscludeFn.$$slots = createMap();      for (var slotName in transcludeFn.$$slots) {        if (transcludeFn.$$slots[slotName]) {          boundSlots[slotName] = createBoundTranscludeFn(scope, transcludeFn.$$slots[slotName], previousBoundTranscludeFn);        } else {          boundSlots[slotName] = null;        }      }       return boundTranscludeFn;    }     /**     * Looks for directives on the given node and adds them to the directive collection which is     * sorted.     *     * @param node Node to search.     * @param directives An array to which the directives are added to. This array is sorted before     *        the function returns.     * @param attrs The shared attrs object which is used to populate the normalized attributes.     * @param {number=} maxPriority Max directive priority.     */    function collectDirectives(node, directives, attrs, maxPriority, ignoreDirective) {      var nodeType = node.nodeType,          attrsMap = attrs.$attr,          match,          nodeName,          className;       switch (nodeType) {        case NODE_TYPE_ELEMENT: /* Element */           nodeName = nodeName_(node);           // use the node name: <directive>          addDirective(directives,              directiveNormalize(nodeName), 'E', maxPriority, ignoreDirective);           // iterate over the attributes          for (var attr, name, nName, ngAttrName, value, isNgAttr, nAttrs = node.attributes,                   j = 0, jj = nAttrs && nAttrs.length; j < jj; j++) {            var attrStartName = false;            var attrEndName = false;             attr = nAttrs[j];            name = attr.name;            value = attr.value;             // support ngAttr attribute binding            ngAttrName = directiveNormalize(name);            isNgAttr = NG_ATTR_BINDING.test(ngAttrName);            if (isNgAttr) {              name = name.replace(PREFIX_REGEXP, '')                .substr(8).replace(/_(.)/g, function(match, letter) {                  return letter.toUpperCase();                });            }             var multiElementMatch = ngAttrName.match(MULTI_ELEMENT_DIR_RE);            if (multiElementMatch && directiveIsMultiElement(multiElementMatch[1])) {              attrStartName = name;              attrEndName = name.substr(0, name.length - 5) + 'end';              name = name.substr(0, name.length - 6);            }             nName = directiveNormalize(name.toLowerCase());            attrsMap[nName] = name;            if (isNgAttr || !attrs.hasOwnProperty(nName)) {                attrs[nName] = value;                if (getBooleanAttrName(node, nName)) {                  attrs[nName] = true; // presence means true                }            }            addAttrInterpolateDirective(node, directives, value, nName, isNgAttr);            addDirective(directives, nName, 'A', maxPriority, ignoreDirective, attrStartName,                          attrEndName);          }           if (nodeName === 'input' && node.getAttribute('type') === 'hidden') {            // Hidden input elements can have strange behaviour when navigating back to the page            // This tells the browser not to try to cache and reinstate previous values            node.setAttribute('autocomplete', 'off');          }           // use class as directive          if (!cssClassDirectivesEnabled) break;          className = node.className;          if (isObject(className)) {              // Maybe SVGAnimatedString              className = className.animVal;          }          if (isString(className) && className !== '') {            while ((match = CLASS_DIRECTIVE_REGEXP.exec(className))) {              nName = directiveNormalize(match[2]);              if (addDirective(directives, nName, 'C', maxPriority, ignoreDirective)) {                attrs[nName] = trim(match[3]);              }              className = className.substr(match.index + match[0].length);            }          }          break;        case NODE_TYPE_TEXT: /* Text Node */          addTextInterpolateDirective(directives, node.nodeValue);          break;        case NODE_TYPE_COMMENT: /* Comment */          if (!commentDirectivesEnabled) break;          collectCommentDirectives(node, directives, attrs, maxPriority, ignoreDirective);          break;      }       directives.sort(byPriority);      return directives;    }     function collectCommentDirectives(node, directives, attrs, maxPriority, ignoreDirective) {      // function created because of performance, try/catch disables      // the optimization of the whole function #14848      try {        var match = COMMENT_DIRECTIVE_REGEXP.exec(node.nodeValue);        if (match) {          var nName = directiveNormalize(match[1]);          if (addDirective(directives, nName, 'M', maxPriority, ignoreDirective)) {            attrs[nName] = trim(match[2]);          }        }      } catch (e) {        // turns out that under some circumstances IE9 throws errors when one attempts to read        // comment's node value.        // Just ignore it and continue. (Can't seem to reproduce in test case.)      }    }     /**     * Given a node with a directive-start it collects all of the siblings until it finds     * directive-end.     * @param node     * @param attrStart     * @param attrEnd     * @returns {*}     */    function groupScan(node, attrStart, attrEnd) {      var nodes = [];      var depth = 0;      if (attrStart && node.hasAttribute && node.hasAttribute(attrStart)) {        do {          if (!node) {            throw $compileMinErr('uterdir',                      'Unterminated attribute, found \'{0}\' but no matching \'{1}\' found.',                      attrStart, attrEnd);          }          if (node.nodeType === NODE_TYPE_ELEMENT) {            if (node.hasAttribute(attrStart)) depth++;            if (node.hasAttribute(attrEnd)) depth--;          }          nodes.push(node);          node = node.nextSibling;        } while (depth > 0);      } else {        nodes.push(node);      }       return jqLite(nodes);    }     /**     * Wrapper for linking function which converts normal linking function into a grouped     * linking function.     * @param linkFn     * @param attrStart     * @param attrEnd     * @returns {Function}     */    function groupElementsLinkFnWrapper(linkFn, attrStart, attrEnd) {      return function groupedElementsLink(scope, element, attrs, controllers, transcludeFn) {        element = groupScan(element[0], attrStart, attrEnd);        return linkFn(scope, element, attrs, controllers, transcludeFn);      };    }     /**     * A function generator that is used to support both eager and lazy compilation     * linking function.     * @param eager     * @param $compileNodes     * @param transcludeFn     * @param maxPriority     * @param ignoreDirective     * @param previousCompileContext     * @returns {Function}     */    function compilationGenerator(eager, $compileNodes, transcludeFn, maxPriority, ignoreDirective, previousCompileContext) {      var compiled;       if (eager) {        return compile($compileNodes, transcludeFn, maxPriority, ignoreDirective, previousCompileContext);      }      return /** @this */ function lazyCompilation() {        if (!compiled) {          compiled = compile($compileNodes, transcludeFn, maxPriority, ignoreDirective, previousCompileContext);           // Null out all of these references in order to make them eligible for garbage collection          // since this is a potentially long lived closure          $compileNodes = transcludeFn = previousCompileContext = null;        }        return compiled.apply(this, arguments);      };    }     /**     * Once the directives have been collected, their compile functions are executed. This method

Lines 9001–9500 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