MCPcopy
hub / github.com/angular-ui/ui-router / mergeTemplateAttributes

Function mergeTemplateAttributes

test/angular/1.4/angular.js:8704–8735  ·  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

8702 * @param {object} src source attributes (from the directive template)
8703 */
8704 function mergeTemplateAttributes(dst, src) {
8705 var srcAttr = src.$attr,
8706 dstAttr = dst.$attr,
8707 $element = dst.$$element;
8708
8709 // reapply the old attributes to the new element
8710 forEach(dst, function(value, key) {
8711 if (key.charAt(0) != '$') {
8712 if (src[key] && src[key] !== value) {
8713 value += (key === 'style' ? ';' : ' ') + src[key];
8714 }
8715 dst.$set(key, value, true, srcAttr[key]);
8716 }
8717 });
8718
8719 // copy the new attributes on the old attrs object
8720 forEach(src, function(value, key) {
8721 if (key == 'class') {
8722 safeAddClass($element, value);
8723 dst['class'] = (dst['class'] ? dst['class'] + ' ' : '') + value;
8724 } else if (key == 'style') {
8725 $element.attr('style', $element.attr('style') + ';' + value);
8726 dst['style'] = (dst['style'] ? dst['style'] + ';' : '') + value;
8727 // `dst` will never contain hasOwnProperty as DOM parser won't let it.
8728 // You will get an "InvalidCharacterError: DOM Exception 5" error if you
8729 // have an attribute like "has-own-property" or "data-has-own-property", etc.
8730 } else if (key.charAt(0) != '$' && !dst.hasOwnProperty(key)) {
8731 dst[key] = value;
8732 dstAttr[key] = srcAttr[key];
8733 }
8734 });
8735 }
8736
8737
8738 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