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

Function mergeTemplateAttributes

test/angular/1.7/angular.js:10807–10839  ·  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

10805 * @param {object} src source attributes (from the directive template)
10806 */
10807 function mergeTemplateAttributes(dst, src) {
10808 var srcAttr = src.$attr,
10809 dstAttr = dst.$attr;
10810
10811 // reapply the old attributes to the new element
10812 forEach(dst, function(value, key) {
10813 if (key.charAt(0) !== '$') {
10814 if (src[key] && src[key] !== value) {
10815 if (value.length) {
10816 value += (key === 'style' ? ';' : ' ') + src[key];
10817 } else {
10818 value = src[key];
10819 }
10820 }
10821 dst.$set(key, value, true, srcAttr[key]);
10822 }
10823 });
10824
10825 // copy the new attributes on the old attrs object
10826 forEach(src, function(value, key) {
10827 // Check if we already set this attribute in the loop above.
10828 // `dst` will never contain hasOwnProperty as DOM parser won't let it.
10829 // You will get an "InvalidCharacterError: DOM Exception 5" error if you
10830 // have an attribute like "has-own-property" or "data-has-own-property", etc.
10831 if (!dst.hasOwnProperty(key) && key.charAt(0) !== '$') {
10832 dst[key] = value;
10833
10834 if (key !== 'class' && key !== 'style') {
10835 dstAttr[key] = srcAttr[key];
10836 }
10837 }
10838 });
10839 }
10840
10841
10842 function compileTemplateUrl(directives, $compileNode, tAttrs,

Callers 2

applyDirectivesToNodeFunction · 0.70
compileTemplateUrlFunction · 0.70

Calls 1

forEachFunction · 0.70

Tested by

no test coverage detected