* 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)
| 10210 | * @param {object} src source attributes (from the directive template) |
| 10211 | */ |
| 10212 | function mergeTemplateAttributes(dst, src) { |
| 10213 | var srcAttr = src.$attr, |
| 10214 | dstAttr = dst.$attr; |
| 10215 | |
| 10216 | // reapply the old attributes to the new element |
| 10217 | forEach(dst, function(value, key) { |
| 10218 | if (key.charAt(0) !== '$') { |
| 10219 | if (src[key] && src[key] !== value) { |
| 10220 | if (value.length) { |
| 10221 | value += (key === 'style' ? ';' : ' ') + src[key]; |
| 10222 | } else { |
| 10223 | value = src[key]; |
| 10224 | } |
| 10225 | } |
| 10226 | dst.$set(key, value, true, srcAttr[key]); |
| 10227 | } |
| 10228 | }); |
| 10229 | |
| 10230 | // copy the new attributes on the old attrs object |
| 10231 | forEach(src, function(value, key) { |
| 10232 | // Check if we already set this attribute in the loop above. |
| 10233 | // `dst` will never contain hasOwnProperty as DOM parser won't let it. |
| 10234 | // You will get an "InvalidCharacterError: DOM Exception 5" error if you |
| 10235 | // have an attribute like "has-own-property" or "data-has-own-property", etc. |
| 10236 | if (!dst.hasOwnProperty(key) && key.charAt(0) !== '$') { |
| 10237 | dst[key] = value; |
| 10238 | |
| 10239 | if (key !== 'class' && key !== 'style') { |
| 10240 | dstAttr[key] = srcAttr[key]; |
| 10241 | } |
| 10242 | } |
| 10243 | }); |
| 10244 | } |
| 10245 | |
| 10246 | |
| 10247 | function compileTemplateUrl(directives, $compileNode, tAttrs, |
no test coverage detected