MCPcopy Create free account
hub / github.com/apache/cloudstack / collectDirectives

Function collectDirectives

tools/ngui/static/js/lib/angular.js:4035–4099  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

4033 * @param {number=} maxPriority Max directive priority.
4034 */
4035 function collectDirectives(node, directives, attrs, maxPriority) {
4036 var nodeType = node.nodeType,
4037 attrsMap = attrs.$attr,
4038 match,
4039 className;
4040
4041 switch(nodeType) {
4042 case 1: /* Element */
4043 // use the node name: <directive>
4044 addDirective(directives,
4045 directiveNormalize(nodeName_(node).toLowerCase()), 'E', maxPriority);
4046
4047 // iterate over the attributes
4048 for (var attr, name, nName, value, nAttrs = node.attributes,
4049 j = 0, jj = nAttrs && nAttrs.length; j < jj; j++) {
4050 attr = nAttrs[j];
4051 if (attr.specified) {
4052 name = attr.name;
4053 nName = directiveNormalize(name.toLowerCase());
4054 attrsMap[nName] = name;
4055 attrs[nName] = value = trim((msie && name == 'href')
4056 ? decodeURIComponent(node.getAttribute(name, 2))
4057 : attr.value);
4058 if (getBooleanAttrName(node, nName)) {
4059 attrs[nName] = true; // presence means true
4060 }
4061 addAttrInterpolateDirective(node, directives, value, nName);
4062 addDirective(directives, nName, 'A', maxPriority);
4063 }
4064 }
4065
4066 // use class as directive
4067 className = node.className;
4068 if (isString(className) && className !== '') {
4069 while (match = CLASS_DIRECTIVE_REGEXP.exec(className)) {
4070 nName = directiveNormalize(match[2]);
4071 if (addDirective(directives, nName, 'C', maxPriority)) {
4072 attrs[nName] = trim(match[3]);
4073 }
4074 className = className.substr(match.index + match[0].length);
4075 }
4076 }
4077 break;
4078 case 3: /* Text Node */
4079 addTextInterpolateDirective(directives, node.nodeValue);
4080 break;
4081 case 8: /* Comment */
4082 try {
4083 match = COMMENT_DIRECTIVE_REGEXP.exec(node.nodeValue);
4084 if (match) {
4085 nName = directiveNormalize(match[1]);
4086 if (addDirective(directives, nName, 'M', maxPriority)) {
4087 attrs[nName] = trim(match[2]);
4088 }
4089 }
4090 } catch (e) {
4091 // turns out that under some circumstances IE9 throws errors when one attempts to read comment's node value.
4092 // Just ignore it and continue. (Can't seem to reproduce in test case.)

Callers 3

compileNodesFunction · 0.85
applyDirectivesToNodeFunction · 0.85
compileTemplateUrlFunction · 0.85

Calls 9

addDirectiveFunction · 0.85
directiveNormalizeFunction · 0.85
trimFunction · 0.85
getBooleanAttrNameFunction · 0.85
isStringFunction · 0.85
getAttributeMethod · 0.80
sortMethod · 0.65

Tested by

no test coverage detected