* 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)
| 7895 | * @param {object} src source attributes (from the directive template) |
| 7896 | */ |
| 7897 | function mergeTemplateAttributes(dst, src) { |
| 7898 | var srcAttr = src.$attr, |
| 7899 | dstAttr = dst.$attr, |
| 7900 | $element = dst.$$element; |
| 7901 | |
| 7902 | // reapply the old attributes to the new element |
| 7903 | forEach(dst, function(value, key) { |
| 7904 | if (key.charAt(0) != '$') { |
| 7905 | if (src[key] && src[key] !== value) { |
| 7906 | value += (key === 'style' ? ';' : ' ') + src[key]; |
| 7907 | } |
| 7908 | dst.$set(key, value, true, srcAttr[key]); |
| 7909 | } |
| 7910 | }); |
| 7911 | |
| 7912 | // copy the new attributes on the old attrs object |
| 7913 | forEach(src, function(value, key) { |
| 7914 | if (key == 'class') { |
| 7915 | safeAddClass($element, value); |
| 7916 | dst['class'] = (dst['class'] ? dst['class'] + ' ' : '') + value; |
| 7917 | } else if (key == 'style') { |
| 7918 | $element.attr('style', $element.attr('style') + ';' + value); |
| 7919 | dst['style'] = (dst['style'] ? dst['style'] + ';' : '') + value; |
| 7920 | // `dst` will never contain hasOwnProperty as DOM parser won't let it. |
| 7921 | // You will get an "InvalidCharacterError: DOM Exception 5" error if you |
| 7922 | // have an attribute like "has-own-property" or "data-has-own-property", etc. |
| 7923 | } else if (key.charAt(0) != '$' && !dst.hasOwnProperty(key)) { |
| 7924 | dst[key] = value; |
| 7925 | dstAttr[key] = srcAttr[key]; |
| 7926 | } |
| 7927 | }); |
| 7928 | } |
| 7929 | |
| 7930 | |
| 7931 | function compileTemplateUrl(directives, $compileNode, tAttrs, |
no test coverage detected