* 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)
| 7810 | * @param {object} src source attributes (from the directive template) |
| 7811 | */ |
| 7812 | function mergeTemplateAttributes(dst, src) { |
| 7813 | var srcAttr = src.$attr, |
| 7814 | dstAttr = dst.$attr, |
| 7815 | $element = dst.$$element; |
| 7816 | |
| 7817 | // reapply the old attributes to the new element |
| 7818 | forEach(dst, function(value, key) { |
| 7819 | if (key.charAt(0) != '$') { |
| 7820 | if (src[key] && src[key] !== value) { |
| 7821 | value += (key === 'style' ? ';' : ' ') + src[key]; |
| 7822 | } |
| 7823 | dst.$set(key, value, true, srcAttr[key]); |
| 7824 | } |
| 7825 | }); |
| 7826 | |
| 7827 | // copy the new attributes on the old attrs object |
| 7828 | forEach(src, function(value, key) { |
| 7829 | if (key == 'class') { |
| 7830 | safeAddClass($element, value); |
| 7831 | dst['class'] = (dst['class'] ? dst['class'] + ' ' : '') + value; |
| 7832 | } else if (key == 'style') { |
| 7833 | $element.attr('style', $element.attr('style') + ';' + value); |
| 7834 | dst['style'] = (dst['style'] ? dst['style'] + ';' : '') + value; |
| 7835 | // `dst` will never contain hasOwnProperty as DOM parser won't let it. |
| 7836 | // You will get an "InvalidCharacterError: DOM Exception 5" error if you |
| 7837 | // have an attribute like "has-own-property" or "data-has-own-property", etc. |
| 7838 | } else if (key.charAt(0) != '$' && !dst.hasOwnProperty(key)) { |
| 7839 | dst[key] = value; |
| 7840 | dstAttr[key] = srcAttr[key]; |
| 7841 | } |
| 7842 | }); |
| 7843 | } |
| 7844 | |
| 7845 | |
| 7846 | function compileTemplateUrl(directives, $compileNode, tAttrs, |
no test coverage detected