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

Function mergeTemplateAttributes

lib/test/angular/1.8.0/angular.js:10872–10904  ·  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

10870 * @param {object} src source attributes (from the directive template)
10871 */
10872 function mergeTemplateAttributes(dst, src) {
10873 var srcAttr = src.$attr,
10874 dstAttr = dst.$attr;
10875
10876 // reapply the old attributes to the new element
10877 forEach(dst, function(value, key) {
10878 if (key.charAt(0) !== '$') {
10879 if (src[key] && src[key] !== value) {
10880 if (value.length) {
10881 value += (key === 'style' ? ';' : ' ') + src[key];
10882 } else {
10883 value = src[key];
10884 }
10885 }
10886 dst.$set(key, value, true, srcAttr[key]);
10887 }
10888 });
10889
10890 // copy the new attributes on the old attrs object
10891 forEach(src, function(value, key) {
10892 // Check if we already set this attribute in the loop above.
10893 // `dst` will never contain hasOwnProperty as DOM parser won't let it.
10894 // You will get an "InvalidCharacterError: DOM Exception 5" error if you
10895 // have an attribute like "has-own-property" or "data-has-own-property", etc.
10896 if (!dst.hasOwnProperty(key) && key.charAt(0) !== '$') {
10897 dst[key] = value;
10898
10899 if (key !== 'class' && key !== 'style') {
10900 dstAttr[key] = srcAttr[key];
10901 }
10902 }
10903 });
10904 }
10905
10906
10907 function compileTemplateUrl(directives, $compileNode, tAttrs,

Callers 2

applyDirectivesToNodeFunction · 0.70
compileTemplateUrlFunction · 0.70

Calls 1

forEachFunction · 0.70

Tested by

no test coverage detected