* 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)
| 9761 | * @param {object} src source attributes (from the directive template) |
| 9762 | */ |
| 9763 | function mergeTemplateAttributes(dst, src) { |
| 9764 | var srcAttr = src.$attr, |
| 9765 | dstAttr = dst.$attr; |
| 9766 | |
| 9767 | // reapply the old attributes to the new element |
| 9768 | forEach(dst, function(value, key) { |
| 9769 | if (key.charAt(0) !== '$') { |
| 9770 | if (src[key] && src[key] !== value) { |
| 9771 | value += (key === 'style' ? ';' : ' ') + src[key]; |
| 9772 | } |
| 9773 | dst.$set(key, value, true, srcAttr[key]); |
| 9774 | } |
| 9775 | }); |
| 9776 | |
| 9777 | // copy the new attributes on the old attrs object |
| 9778 | forEach(src, function(value, key) { |
| 9779 | // Check if we already set this attribute in the loop above. |
| 9780 | // `dst` will never contain hasOwnProperty as DOM parser won't let it. |
| 9781 | // You will get an "InvalidCharacterError: DOM Exception 5" error if you |
| 9782 | // have an attribute like "has-own-property" or "data-has-own-property", etc. |
| 9783 | if (!dst.hasOwnProperty(key) && key.charAt(0) !== '$') { |
| 9784 | dst[key] = value; |
| 9785 | |
| 9786 | if (key !== 'class' && key !== 'style') { |
| 9787 | dstAttr[key] = srcAttr[key]; |
| 9788 | } |
| 9789 | } |
| 9790 | }); |
| 9791 | } |
| 9792 | |
| 9793 | |
| 9794 | function compileTemplateUrl(directives, $compileNode, tAttrs, |
no test coverage detected