Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid removing all scripts #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions livepreview/static/livepreview/js/livepreview_fe.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ $(document).ready(function() {
function stripScripts(s) {
var div = document.createElement('div');
div.innerHTML = s;
var scripts = div.getElementsByTagName('script');
var scripts = div.querySelectorAll('.js-livepreview-script script');
var i = scripts.length;
while (i--) {
scripts[i].parentNode.removeChild(scripts[i]);
Expand Down Expand Up @@ -38,10 +38,6 @@ $(document).ready(function() {
success: function (data, textStatus, jqXHR) {
if(window.currentDom !== data) {
window.currentDom = data
// Select the entire BODY
var $body = $("body")
// Remove everything EXCEPT <script> tags.
$body.find("*:not(script)").remove()
// Strip the ajax'd template data: no <scripts> allowed
data = stripScripts(data)
// Start a new DOMParser with the ajax'd template
Expand All @@ -50,10 +46,8 @@ $(document).ready(function() {
var htmlDoc = parser.parseFromString(data, 'text/html');
// Get only the <body> from the ajax'd template
var body = htmlDoc.querySelector('body')
// Get just the innerHTML from the ajax'd templates' body
var html = body.innerHTML
// Replace our DOM with the Ajax'd DOM.
$body.html(html)
$("body").html(body.innerHTML)
// Update the page title now.
var title = htmlDoc.querySelector('title')
$("title").html(title.innerHTML)
Expand All @@ -73,4 +67,4 @@ $(document).ready(function() {
}
})
}, livePreviewSettings.interval_time)
});
});