Removed redundant HTML response type check for preview code

This commit is contained in:
Andrew Bastin
2020-06-22 03:36:34 -04:00
parent d81306ac1a
commit d31da4a0ec

View File

@@ -151,23 +151,18 @@ export default {
togglePreview() { togglePreview() {
this.previewEnabled = !this.previewEnabled this.previewEnabled = !this.previewEnabled
if (this.previewEnabled) { if (this.previewEnabled) {
// If you want to add 'preview' support for other response types, if (this.$refs.previewFrame.getAttribute("data-previewing-url") === this.url) return
// just add them here. // Use DOMParser to parse document HTML.
if (this.responseType === "text/html") { const previewDocument = new DOMParser().parseFromString(
// If the preview already has that URL loaded, let's not bother re-loading it all. this.responseBodyText,
if (this.$refs.previewFrame.getAttribute("data-previewing-url") === this.url) return this.responseType
// Use DOMParser to parse document HTML. )
const previewDocument = new DOMParser().parseFromString( // Inject <base href="..."> tag to head, to fix relative CSS/HTML paths.
this.responseBodyText, previewDocument.head.innerHTML =
this.responseType `<base href="${this.url}">` + previewDocument.head.innerHTML
) // Finally, set the iframe source to the resulting HTML.
// Inject <base href="..."> tag to head, to fix relative CSS/HTML paths. this.$refs.previewFrame.srcdoc = previewDocument.documentElement.outerHTML
previewDocument.head.innerHTML = this.$refs.previewFrame.setAttribute("data-previewing-url", this.url)
`<base href="${this.url}">` + previewDocument.head.innerHTML
// Finally, set the iframe source to the resulting HTML.
this.$refs.previewFrame.srcdoc = previewDocument.documentElement.outerHTML
this.$refs.previewFrame.setAttribute("data-previewing-url", this.url)
}
} }
}, },
}, },