* 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 a
(node, directives, attrs, maxPriority, ignoreDirective)
| 7098 | * @param {number=} maxPriority Max directive priority. |
| 7099 | */ |
| 7100 | function collectDirectives(node, directives, attrs, maxPriority, ignoreDirective) { |
| 7101 | var nodeType = node.nodeType, |
| 7102 | attrsMap = attrs.$attr, |
| 7103 | match, |
| 7104 | className; |
| 7105 | |
| 7106 | switch (nodeType) { |
| 7107 | case NODE_TYPE_ELEMENT: /* Element */ |
| 7108 | // use the node name: <directive> |
| 7109 | addDirective(directives, |
| 7110 | directiveNormalize(nodeName_(node)), 'E', maxPriority, ignoreDirective); |
| 7111 | |
| 7112 | // iterate over the attributes |
| 7113 | for (var attr, name, nName, ngAttrName, value, isNgAttr, nAttrs = node.attributes, |
| 7114 | j = 0, jj = nAttrs && nAttrs.length; j < jj; j++) { |
| 7115 | var attrStartName = false; |
| 7116 | var attrEndName = false; |
| 7117 | |
| 7118 | attr = nAttrs[j]; |
| 7119 | name = attr.name; |
| 7120 | value = trim(attr.value); |
| 7121 | |
| 7122 | // support ngAttr attribute binding |
| 7123 | ngAttrName = directiveNormalize(name); |
| 7124 | if (isNgAttr = NG_ATTR_BINDING.test(ngAttrName)) { |
| 7125 | name = snake_case(ngAttrName.substr(6), '-'); |
| 7126 | } |
| 7127 | |
| 7128 | var directiveNName = ngAttrName.replace(/(Start|End)$/, ''); |
| 7129 | if (directiveIsMultiElement(directiveNName)) { |
| 7130 | if (ngAttrName === directiveNName + 'Start') { |
| 7131 | attrStartName = name; |
| 7132 | attrEndName = name.substr(0, name.length - 5) + 'end'; |
| 7133 | name = name.substr(0, name.length - 6); |
| 7134 | } |
| 7135 | } |
| 7136 | |
| 7137 | nName = directiveNormalize(name.toLowerCase()); |
| 7138 | attrsMap[nName] = name; |
| 7139 | if (isNgAttr || !attrs.hasOwnProperty(nName)) { |
| 7140 | attrs[nName] = value; |
| 7141 | if (getBooleanAttrName(node, nName)) { |
| 7142 | attrs[nName] = true; // presence means true |
| 7143 | } |
| 7144 | } |
| 7145 | addAttrInterpolateDirective(node, directives, value, nName, isNgAttr); |
| 7146 | addDirective(directives, nName, 'A', maxPriority, ignoreDirective, attrStartName, |
| 7147 | attrEndName); |
| 7148 | } |
| 7149 | |
| 7150 | // use class as directive |
| 7151 | className = node.className; |
| 7152 | if (isString(className) && className !== '') { |
| 7153 | while (match = CLASS_DIRECTIVE_REGEXP.exec(className)) { |
| 7154 | nName = directiveNormalize(match[2]); |
| 7155 | if (addDirective(directives, nName, 'C', maxPriority, ignoreDirective)) { |
| 7156 | attrs[nName] = trim(match[3]); |
| 7157 | } |
no test coverage detected