Skip to content

Commit

Permalink
feat(external-script): detect more than one script dom, fixed #146
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed Apr 12, 2017
1 parent 920f624 commit 94d6603
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/plugins/external-script.js
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

Expand Down

0 comments on commit 94d6603

Please sign in to comment.