From bf1972dc1e8ffbeaddfa53df1d49bc5a2177f09c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Go=C5=82e=CC=A8biowski?= Date: Sun, 24 Nov 2013 21:13:51 +0100 Subject: [PATCH] fix(ngSanitize): prefer textContent to innerText to avoid layout trashing innerText depends on styling as it doesn't display hidden elements. Therefore, it's better to use textContent not to cause unnecessary reflows. However, IE<9 don't support textContent so the innerText fallback is necessary. --- src/ngSanitize/sanitize.js | 7 ++++- test/ngSanitize/sanitizeSpec.js | 52 +++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/ngSanitize/sanitize.js b/src/ngSanitize/sanitize.js index e669e77a63b1..1e424d693134 100644 --- a/src/ngSanitize/sanitize.js +++ b/src/ngSanitize/sanitize.js @@ -378,7 +378,12 @@ function decodeEntities(value) { var content = parts[2]; if (content) { hiddenPre.innerHTML=content.replace(/text', handler); + expect(text).toEqual('INNER_TEXT'); + }); + }); + it('should use textContent if available', function() { + window.hiddenPre = { + textContent: 'TEXT_CONTENT', + innerText: 'INNER_TEXT' + }; + inject(function($sanitize) { + htmlParser('text', handler); + expect(text).toEqual('TEXT_CONTENT'); + }); + }); + it('should use textContent even if empty', function() { + window.hiddenPre = { + textContent: '', + innerText: 'INNER_TEXT' + }; + inject(function($sanitize) { + htmlParser('text', handler); + expect(text).toEqual(''); + }); + }); +});