Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Update append to support adding scripts #3

Open
Daniel15 opened this Issue · 0 comments

1 participant

@Daniel15
Owner

Rough code, needs testing:

    /**
     * Append some HTML to the element
     */
    append: function(html)
    {
        var newContent = document.createElement('div');
        newContent.innerHTML = html;
        while (newContent.firstChild)
        {
            var newEl = newContent.firstChild;

            // Check if this element is a script
            if (newContent.firstChild.tagName && newContent.firstChild.tagName.toUpperCase() == 'SCRIPT')
            {
                // Check if it's an external script
                if (newEl.src)
                {

                    // Moving existing elements doesn't seem to work properly. We need to create a
                    // brand new script tag and insert that.
                    var newScript = document.createElement('script');
                    newScript.src = newEl.src;
                    this.element.appendChild(newScript);

                }
                else
                {
                    // Inline script, so just execute it
                    eval('with (window) { ' + newEl.innerHTML + "}");
                }

                newContent.removeChild(newEl);
            }
            else
            {
                this.element.appendChild(newEl);
            }
        }
        return this;
    },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.