MCPcopy Index your code
hub / github.com/angular-ui/ui-grid / mergeTemplateAttributes

Function mergeTemplateAttributes

lib/test/angular/1.5.0/angular.js:9105–9136  ·  view source on GitHub ↗

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

(dst, src)

Source from the content-addressed store, hash-verified

9103 * @param {object} src source attributes (from the directive template)
9104 */
9105 function mergeTemplateAttributes(dst, src) {
9106 var srcAttr = src.$attr,
9107 dstAttr = dst.$attr,
9108 $element = dst.$$element;
9109
9110 // reapply the old attributes to the new element
9111 forEach(dst, function(value, key) {
9112 if (key.charAt(0) != '$') {
9113 if (src[key] && src[key] !== value) {
9114 value += (key === 'style' ? ';' : ' ') + src[key];
9115 }
9116 dst.$set(key, value, true, srcAttr[key]);
9117 }
9118 });
9119
9120 // copy the new attributes on the old attrs object
9121 forEach(src, function(value, key) {
9122 if (key == 'class') {
9123 safeAddClass($element, value);
9124 dst['class'] = (dst['class'] ? dst['class'] + ' ' : '') + value;
9125 } else if (key == 'style') {
9126 $element.attr('style', $element.attr('style') + ';' + value);
9127 dst['style'] = (dst['style'] ? dst['style'] + ';' : '') + value;
9128 // `dst` will never contain hasOwnProperty as DOM parser won't let it.
9129 // You will get an "InvalidCharacterError: DOM Exception 5" error if you
9130 // have an attribute like "has-own-property" or "data-has-own-property", etc.
9131 } else if (key.charAt(0) != '$' && !dst.hasOwnProperty(key)) {
9132 dst[key] = value;
9133 dstAttr[key] = srcAttr[key];
9134 }
9135 });
9136 }
9137
9138
9139 function compileTemplateUrl(directives, $compileNode, tAttrs,

Callers 2

applyDirectivesToNodeFunction · 0.70
compileTemplateUrlFunction · 0.70

Calls 2

forEachFunction · 0.70
safeAddClassFunction · 0.70

Tested by

no test coverage detected