src/aria/utils/Dom.js
function (domElt, where, html) {
            if (Aria.$window.document.body.insertAdjacentHTML) {
                this.insertAdjacentHTML = function (domElt, where, html) {
                    // PROFILING // var msr = this.$startMeasure("insertAdjacentHTML");
                    // IE, Chrome, Safari, Opera
                    // simply use insertAdjacentHTML
                    try {
                        domElt.insertAdjacentHTML(where, html);
                    } catch (ex) {
                        // insertAdjacentHTML can fail in IE with tbody, tfoot, thead or tr elements
                        // We use a simple work-around: create a complete table, get the HTML element and insert it in
                        // the DOM
                        var containerElt;
                        var newDomElt;
                        if (where == "afterBegin" || where == "beforeEnd") {
                            containerElt = domElt;
                        } else if (where == "beforeBegin" || where == "afterEnd") {
                            containerElt = domElt.parentNode;
                        } else {
                            this.$logError(this.INSERT_ADJACENT_INVALID_POSITION, [where]);
                            return;
                        }
                        newDomElt = this._createTableElement(containerElt.tagName, html, domElt.ownerDocument);
                        if (newDomElt) {
                            var previousChild = newDomElt.lastChild;
                            // now let's move the html content to the right place
                            // first put lastChild at the right place, then, move the remaining children
                            if (previousChild) {
                                this.insertAdjacentElement(domElt, where, previousChild);
                                var curChild = newDomElt.lastChild;
                                while (curChild) {
                                    containerElt.insertBefore(curChild, previousChild);
                                    previousChild = curChild;
                                    curChild = newDomElt.lastChild;
                                }
                            }
                        } else {
                            // propagate the exception
                            throw ex;
                        }
                    }
                    // PROFILING // this.$stopMeasure(msr);
                };
            } else {
                this.insertAdjacentHTML = function (domElt, where, html) {
                    // PROFILING // var msr = this.$startMeasure("insertAdjacentHTML");
                    // Firefox
                    // Note that this solution could work as well with Chrome, Safari and Opera
                    var document = domElt.ownerDocument;
                    var range = document.createRange();
                    if (where == "beforeBegin" || where == "afterEnd") {
                        range.selectNode(domElt);
                    } else {
                        range.selectNodeContents(domElt);
                    }
                    var fragment = range.createContextualFragment(html);
                    this.insertAdjacentElement(domElt, where, fragment);
                    range.detach();
                    // PROFILING // this.$stopMeasure(msr);
                };
            }

            this.insertAdjacentHTML(domElt, where, html);
        }
function (domElt, where, html) {
            if (Aria.$window.document.body.insertAdjacentHTML) {
                this.insertAdjacentHTML = function (domElt, where, html) {
                    // PROFILING // var msr = this.$startMeasure("insertAdjacentHTML");
                    // IE, Chrome, Safari, Opera
                    // simply use insertAdjacentHTML
                    try {
                        domElt.insertAdjacentHTML(where, html);
                    } catch (ex) {
                        // insertAdjacentHTML can fail in IE with tbody, tfoot, thead or tr elements
                        // We use a simple work-around: create a complete table, get the HTML element and insert it in
                        // the DOM
                        var containerElt;
                        var newDomElt;
                        if (where == "afterBegin" || where == "beforeEnd") {
                            containerElt = domElt;
                        } else if (where == "beforeBegin" || where == "afterEnd") {
                            containerElt = domElt.parentNode;
                        } else {
                            this.$logError(this.INSERT_ADJACENT_INVALID_POSITION, [where]);
                            return;
                        }
                        newDomElt = this._createTableElement(containerElt.tagName, html, domElt.ownerDocument);
                        if (newDomElt) {
                            var previousChild = newDomElt.lastChild;
                            // now let's move the html content to the right place
                            // first put lastChild at the right place, then, move the remaining children
                            if (previousChild) {
                                this.insertAdjacentElement(domElt, where, previousChild);
                                var curChild = newDomElt.lastChild;
                                while (curChild) {
                                    containerElt.insertBefore(curChild, previousChild);
                                    previousChild = curChild;
                                    curChild = newDomElt.lastChild;
                                }
                            }
                        } else {
                            // propagate the exception
                            throw ex;
                        }
                    }
                    // PROFILING // this.$stopMeasure(msr);
                };
            } else {
                this.insertAdjacentHTML = function (domElt, where, html) {
                    // PROFILING // var msr = this.$startMeasure("insertAdjacentHTML");
                    // Firefox
                    // Note that this solution could work as well with Chrome, Safari and Opera
                    var document = domElt.ownerDocument;
                    var range = document.createRange();
                    if (where == "beforeBegin" || where == "afterEnd") {
                        range.selectNode(domElt);
                    } else {
                        range.selectNodeContents(domElt);
                    }
                    var fragment = range.createContextualFragment(html);
                    this.insertAdjacentElement(domElt, where, fragment);
                    range.detach();
                    // PROFILING // this.$stopMeasure(msr);
                };
            }

            this.insertAdjacentHTML(domElt, where, html);
        }
function ( domElt , where , html ) { if ( Aria . $window . document . body . insertAdjacentHTML ) { this . insertAdjacentHTML = function ( domElt , where , html ) { // PROFILING // var msr = this.$startMeasure("insertAdjacentHTML"); // IE, Chrome, Safari, Opera // simply use insertAdjacentHTML try { domElt . insertAdjacentHTML ( where , html ) ; } catch ( ex ) { // insertAdjacentHTML can fail in IE with tbody, tfoot, thead or tr elements // We use a simple work-around: create a complete table, get the HTML element and insert it in // the DOM var containerElt ; var newDomElt ; if ( where == "afterBegin" || where == "beforeEnd" ) { containerElt = domElt ; } else if ( where == "beforeBegin" || where == "afterEnd" ) { containerElt = domElt . parentNode ; } else { this . $logError ( this . INSERT_ADJACENT_INVALID_POSITION , [ where ] ) ; return ; } newDomElt = this . _createTableElement ( containerElt . tagName , html , domElt . ownerDocument ) ; if ( newDomElt ) { var previousChild = newDomElt . lastChild ; // now let's move the html content to the right place // first put lastChild at the right place, then, move the remaining children if ( previousChild ) { this . insertAdjacentElement ( domElt , where , previousChild ) ; var curChild = newDomElt . lastChild ; while ( curChild ) { containerElt . insertBefore ( curChild , previousChild ) ; previousChild = curChild ; curChild = newDomElt . lastChild ; } } } else { // propagate the exception throw ex ; } } // PROFILING // this.$stopMeasure(msr); } ; } else { this . insertAdjacentHTML = function ( domElt , where , html ) { // PROFILING // var msr = this.$startMeasure("insertAdjacentHTML"); // Firefox // Note that this solution could work as well with Chrome, Safari and Opera var document = domElt . ownerDocument ; var range = document . createRange ( ) ; if ( where == "beforeBegin" || where == "afterEnd" ) { range . selectNode ( domElt ) ; } else { range . selectNodeContents ( domElt ) ; } var fragment = range . createContextualFragment ( html ) ; this . insertAdjacentElement ( domElt , where , fragment ) ; range . detach ( ) ; // PROFILING // this.$stopMeasure(msr); } ; } this . insertAdjacentHTML ( domElt , where , html ) ; }
Insert the given HTML markup into the document at the specified location. This method is cross-browser
compatbile. When possible, it relies on the insertAdjacentHTML method, otherwise, it relies on ranges.
@param {HTMLElement} domElt Reference DOM element
@param {String} where maybe beforeBegin, afterBegin, beforeEnd or afterEnd
@param {String} html HTML markup to insert at that place
Insert the given HTML markup into the document at the specified location . This method is cross - browser compatbile . When possible it relies on the insertAdjacentHTML method otherwise it relies on ranges .