mozilla

Compare Revisions

DOMParser

Change Revisions

Revision 37415:

Revision 37415 by Hsivonen on

Revision 37416:

Revision 37416 by Sephr on

Title:
DOMParser
DOMParser
Slug:
DOM/DOMParser
DOM/DOMParser
Tags:
DOM, HTML, XML, NeedsTechnicalReview, NeedsBrowserCompatibility, "Gecko DOM Reference"
DOM, HTML, XML, NeedsTechnicalReview, NeedsBrowserCompatibility, "Gecko DOM Reference"
Content:

Revision 37415
Revision 37416
n75      DOMParser HTML extension for other browsers and previous Fin75      DOMParser HTML extension for other browsers
>refox releases 
n81 * n81 *
nn87/*! @source https://gist.github.com/1129031 */
n90        "use strict";n91    "use strict";
91        92 
92        var93    var
93          DOMParser_proto = DOMParser.prototype94      DOMParser_proto = DOMParser.prototype
94        , real_parseFromString = DOMParser_proto.parseFromString95    , real_parseFromString = DOMParser_proto.parseFromString
95        ;96    ;
nn98    // Firefox/Opera/IE throw errors on unsupported types
97        try {99    try {
100        // WebKit returns null on unsupported types
98                if ((new DOMParser).parseFromString("", "text/htm101        if ((new DOMParser).parseFromString("", "text/html")) {
>l")) { 
99                        // text/html parsing is natively supporte102            // text/html parsing is natively supported
>d 
100                        return;103            return;
101                }104        }
102        } catch (ex /*if ex.result === Components.results.NS_ERRO105    } catch (ex) {}
>R_NOT_IMPLEMENTED*/) {} 
t104        DOMParser_proto.parseFromString = function(markup, type) t107    DOMParser_proto.parseFromString = function(markup, type) {
>{ 
105                if (/^\s*text\/html\s*(?:;|$)/i.test(type)) {108        if (/^\s*text\/html\s*(?:;|$)/i.test(type)) {
106                        var109            var
107                          doc = document.implementation.createHTM110              doc = document.implementation.createHTMLDocument(""
>LDocument("")>)
108                        , doc_elt = doc.documentElement111            , doc_elt = doc.documentElement
109                        , first_elt112            , first_elt
110                        ;113            ;
111                        114 
112                        doc_elt.innerHTML = markup;115            doc_elt.innerHTML = markup;
113                        first_elt = doc_elt.firstElementChild;116            first_elt = doc_elt.firstElementChild;
114                        117 
115                        if ( // are we dealing with an entire doc118            if ( // are we dealing with an entire document or a f
>ument or a fragment?>ragment?
116                                   doc_elt.childElementCount === 119                   doc_elt.childElementCount === 1
>1 
117                                && first_elt.localName.to120                && first_elt.localName.toLowerCase() === 
>LowerCase() === "html">"html"
118                        ) {121            ) {
119                                doc.replaceChild(first_elt, doc_e122                doc.replaceChild(first_elt, doc_elt);
>lt); 
120                        }123            }
121                        124 
122                        return doc;125            return doc;
123                } else {126        } else {
124                        return real_parseFromString.apply(this, a127            return real_parseFromString.apply(this, arguments);
>rguments); 
125                }
126        };128        }
129    };

Back to History