Skip to content

Commit

Permalink
Add ID to inject event. Add sandbox functional example
Browse files Browse the repository at this point in the history
  • Loading branch information
replete committed Jun 22, 2024
1 parent 0272656 commit 19cef7e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
4 changes: 2 additions & 2 deletions biscuitman.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,15 @@
newScript.setAttribute('type', script.dataset.type || 'text/javascript')
if (!script.src) newScript.textContent = script.textContent
script.parentNode.replaceChild(newScript, script)
dispatch('inject', {el: script})
dispatch('inject', {el: script, ...(script.id && {id: script.id})})

// If tag has src AND tag content, inject new tag adjacent to parent after load
if (script.src && script.textContent.trim() !== '') newScript.addEventListener('load', () => {
let afterScript = d.createElement('script')
afterScript.textContent = script.textContent
if (script.id) afterScript.id = script.id + '-after'
newScript.insertAdjacentElement('afterend', afterScript)
dispatch('inject', {el: afterScript, parent: script})
dispatch('inject', {el: afterScript, parent: script, ...(afterScript.id && {id: afterScript.id})})
})
});
}
Expand Down
2 changes: 1 addition & 1 deletion dist/biscuitman.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 19cef7e

Please sign in to comment.