From 23102fdc1923f3ab6844d9ab6217760347306617 Mon Sep 17 00:00:00 2001 From: MatmaRex Date: Tue, 30 Apr 2013 13:45:13 +0200 Subject: [PATCH] Make loading VE work on Opera again Once more, with feeling. The first reverted attempt was I90ea547c. Detailed comments inside. Change-Id: I1ab60665987614e5757e2b108d614b680321d8eb --- modules/ve/ve.js | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/modules/ve/ve.js b/modules/ve/ve.js index d0fe74140a..2883510589 100644 --- a/modules/ve/ve.js +++ b/modules/ve/ve.js @@ -976,10 +976,34 @@ * @returns {HTMLDocument} Document constructed from the HTML string */ ve.createDocumentFromHTML = function ( html ) { - // According to the spec we should be using DOMParser.prototype.parseFromString or - // document.implementation.createHTMLDocument, but the former only works in Firefox - // and the latter doesn't work in IE9 and below. - // So we're using the good old iframe trick. + // Here's how this function should look: + // + // var newDocument = document.implementation.createHTMLDocument( '' ); + // newDocument.open(); + // newDocument.write( html ); + // newDocument.close(); + // return newDocument; + // + // (Or possibly something involving DOMParser.prototype.parseFromString, but that's Firefox-only + // for now.) + // + // Sadly, it's impossible: + // * On IE 9, calling open()/write() on such a document throws an "Unspecified error" (sic). + // * On Firefox 20, calling open()/write() doesn't actually do anything, including writing. + // This is reported as Firefox bug 867102. + // * On Opera 12, calling open()/write() behaves as if called on window.document, replacing the + // entire contents of the page with new HTML. This is reported as Opera bug DSK-384486. + // + // Funnily, in all of those browsers it's apparently perfectly legal and possible to access the + // newly created document's DOM itself, including modifying documentElement's innerHTML, which + // would achieve our goal. But that requires some nasty magic to strip off the tag + // itself, so we're not doing that. (We can't use .outerHTML, either, as the spec disallows + // assigning to it for the root element.) + // + // There is one more way - create an