From 94d6603c06a37f88daca25359cc1d1f6cf604014 Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Wed, 12 Apr 2017 23:51:16 +0800 Subject: [PATCH] feat(external-script): detect more than one script dom, fixed #146 --- src/plugins/external-script.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/plugins/external-script.js b/src/plugins/external-script.js index 5b8b0dd..f27f727 100644 --- a/src/plugins/external-script.js +++ b/src/plugins/external-script.js @@ -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) + } } }