* 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)
| 6856 | * @param {object} src source attributes (from the directive template) |
| 6857 | */ |
| 6858 | function mergeTemplateAttributes(dst, src) { |
| 6859 | var srcAttr = src.$attr, |
| 6860 | dstAttr = dst.$attr, |
| 6861 | $element = dst.$$element; |
| 6862 | |
| 6863 | // reapply the old attributes to the new element |
| 6864 | forEach(dst, function(value, key) { |
| 6865 | if (key.charAt(0) != '$') { |
| 6866 | if (src[key] && src[key] !== value) { |
| 6867 | value += (key === 'style' ? ';' : ' ') + src[key]; |
| 6868 | } |
| 6869 | dst.$set(key, value, true, srcAttr[key]); |
| 6870 | } |
| 6871 | }); |
| 6872 | |
| 6873 | // copy the new attributes on the old attrs object |
| 6874 | forEach(src, function(value, key) { |
| 6875 | if (key == 'class') { |
| 6876 | safeAddClass($element, value); |
| 6877 | dst['class'] = (dst['class'] ? dst['class'] + ' ' : '') + value; |
| 6878 | } else if (key == 'style') { |
| 6879 | $element.attr('style', $element.attr('style') + ';' + value); |
| 6880 | dst['style'] = (dst['style'] ? dst['style'] + ';' : '') + value; |
| 6881 | // `dst` will never contain hasOwnProperty as DOM parser won't let it. |
| 6882 | // You will get an "InvalidCharacterError: DOM Exception 5" error if you |
| 6883 | // have an attribute like "has-own-property" or "data-has-own-property", etc. |
| 6884 | } else if (key.charAt(0) != '$' && !dst.hasOwnProperty(key)) { |
| 6885 | dst[key] = value; |
| 6886 | dstAttr[key] = srcAttr[key]; |
| 6887 | } |
| 6888 | }); |
| 6889 | } |
| 6890 | |
| 6891 | |
| 6892 | function compileTemplateUrl(directives, $compileNode, tAttrs, |
no test coverage detected