* 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)
| 8254 | * @param {object} src source attributes (from the directive template) |
| 8255 | */ |
| 8256 | function mergeTemplateAttributes(dst, src) { |
| 8257 | var srcAttr = src.$attr, |
| 8258 | dstAttr = dst.$attr, |
| 8259 | $element = dst.$$element; |
| 8260 | |
| 8261 | // reapply the old attributes to the new element |
| 8262 | forEach(dst, function(value, key) { |
| 8263 | if (key.charAt(0) != '$') { |
| 8264 | if (src[key] && src[key] !== value) { |
| 8265 | value += (key === 'style' ? ';' : ' ') + src[key]; |
| 8266 | } |
| 8267 | dst.$set(key, value, true, srcAttr[key]); |
| 8268 | } |
| 8269 | }); |
| 8270 | |
| 8271 | // copy the new attributes on the old attrs object |
| 8272 | forEach(src, function(value, key) { |
| 8273 | if (key == 'class') { |
| 8274 | safeAddClass($element, value); |
| 8275 | dst['class'] = (dst['class'] ? dst['class'] + ' ' : '') + value; |
| 8276 | } else if (key == 'style') { |
| 8277 | $element.attr('style', $element.attr('style') + ';' + value); |
| 8278 | dst['style'] = (dst['style'] ? dst['style'] + ';' : '') + value; |
| 8279 | // `dst` will never contain hasOwnProperty as DOM parser won't let it. |
| 8280 | // You will get an "InvalidCharacterError: DOM Exception 5" error if you |
| 8281 | // have an attribute like "has-own-property" or "data-has-own-property", etc. |
| 8282 | } else if (key.charAt(0) != '$' && !dst.hasOwnProperty(key)) { |
| 8283 | dst[key] = value; |
| 8284 | dstAttr[key] = srcAttr[key]; |
| 8285 | } |
| 8286 | }); |
| 8287 | } |
| 8288 | |
| 8289 | |
| 8290 | function compileTemplateUrl(directives, $compileNode, tAttrs, |
no test coverage detected