From 01932e72e79997164298f1570c1e030bd3fb35b3 Mon Sep 17 00:00:00 2001 From: Alexandr Borisov Date: Sun, 27 Jul 2014 15:12:41 +0400 Subject: [PATCH 1/2] fixed ie8 support by fallback to hidden iframe html creation --- lib/assets/javascripts/_dom_parser.js.coffee | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/assets/javascripts/_dom_parser.js.coffee b/lib/assets/javascripts/_dom_parser.js.coffee index 8283951..9fff39f 100644 --- a/lib/assets/javascripts/_dom_parser.js.coffee +++ b/lib/assets/javascripts/_dom_parser.js.coffee @@ -24,6 +24,18 @@ class DOMParser doc.close() doc + # fallback to ie8 support + create_document_using_iframe = (html) -> + iframe = $('') + iframe_parent = $('body') + + iframe_parent.append iframe + doc = iframe[0].contentDocument + doc.innerHTML = html + iframe.remove() + + doc + # Use create_document_using_parser if DOMParser is defined and natively # supports 'text/html' parsing (Firefox 12+, IE 10) # @@ -43,7 +55,13 @@ class DOMParser create_document_using_DOM finally unless testDoc?.body?.childNodes.length is 1 - return create_document_using_write + if @_should_fallback_to_iframe() + return create_document_using_iframe + else + return create_document_using_write + + _should_fallback_to_iframe: -> + document.implementation? and !document.implementation.createHTMLDocument window._Wiselinks ?= {} From ba85c7202d2e33c6fe26468a27c44a1e51a4f144 Mon Sep 17 00:00:00 2001 From: Alexandr Borisov Date: Sun, 27 Jul 2014 15:19:28 +0400 Subject: [PATCH 2/2] fixed coffeelint warnings for lib/assets/javascripts/_dom_parser.js.coffee --- lib/assets/javascripts/_dom_parser.js.coffee | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/assets/javascripts/_dom_parser.js.coffee b/lib/assets/javascripts/_dom_parser.js.coffee index 9fff39f..7e58cc1 100644 --- a/lib/assets/javascripts/_dom_parser.js.coffee +++ b/lib/assets/javascripts/_dom_parser.js.coffee @@ -26,7 +26,8 @@ class DOMParser # fallback to ie8 support create_document_using_iframe = (html) -> - iframe = $('') + iframe_style = 'display:none;position:absolute;z-index:-1;' + iframe = $('') iframe_parent = $('body') iframe_parent.append iframe @@ -37,15 +38,21 @@ class DOMParser doc # Use create_document_using_parser if DOMParser is defined and natively - # supports 'text/html' parsing (Firefox 12+, IE 10) + # supports 'text/html' parsing (FF 12+, IE 10) # - # Use create_document_using_DOM if create_document_using_parser throws an exception - # due to unsupported type 'text/html' (Firefox < 12, Opera) + # Use create_document_using_DOM if create_document_using_parser + # throws an exception due to unsupported type 'text/html' (FF < 12, Opera) # # Use create_document_using_write if: # - DOMParser isn't defined - # - create_document_using_parser returns null due to unsupported type 'text/html' (Chrome, Safari) - # - create_document_using_DOM doesn't create a valid HTML document (safeguarding against potential edge cases) + # - create_document_using_parser returns null + # due to unsupported type 'text/html' (Chrome, Safari) + # - create_document_using_DOM doesn't create a valid HTML document + # (safeguarding against potential edge cases) + # + # Use create_document_using_iframe if + # no document.implementation.createHTMLDocument interface + # present (IE8) try if window.DOMParser testDoc = create_document_using_parser '

test'