feat(external-script): detect more than one script dom, fixed #146

This commit is contained in:
qingwei.li 2017-04-12 23:51:16 +08:00
parent 920f624b5c
commit 94d6603c06

View File

@ -1,16 +1,20 @@
function handleExternalScript () {
const container = Docsify.dom.getNode('#main')
const script = Docsify.dom.find(container, 'script')
const scripts = Docsify.dom.findAll(container, 'script')
if (script && script.src) {
const newScript = document.createElement('script')
for (let i = scripts.length; i--;) {
const script = scripts[i]
;['src', 'async', 'defer'].forEach(attribute => {
newScript[attribute] = script[attribute]
})
if (script && script.src) {
const newScript = document.createElement('script')
script.parentNode.insertBefore(newScript, script)
script.parentNode.removeChild(script)
;['src', 'async', 'defer'].forEach(attribute => {
newScript[attribute] = script[attribute]
})
script.parentNode.insertBefore(newScript, script)
script.parentNode.removeChild(script)
}
}
}