Created
September 1, 2022 13:12
-
-
Save BananaAcid/7e8d7b887556323f80c2d4dc33caffef to your computer and use it in GitHub Desktop.
add sripts and style and wait for them async to be loaded
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let add = (tag, url) => new Promise( (resolve) => { | |
let el = document.createElement(tag); | |
if (tag === 'link') { el.rel = 'stylesheet'; } | |
if (tag === 'link') { | |
el.href = url; | |
} | |
else if (tag === 'script') { | |
el.src = url; | |
} | |
el.addEventListener('load', resolve); | |
document.head.appendChild(el); | |
}); | |
Promise.all([ | |
add('script', '//cdn.ckeditor.com/ckeditor5/35.0.1/classic/ckeditor.js'), | |
add('style', '//cdn.ckeditor.com/ckeditor5/35.0.1/classic/ckeditor.css'), | |
]) | |
.then(async _=> { | |
let instance = ckEditorInstance = await (window as any).ClassicEditor | |
.create(document.querySelector( '#editor' ) ); | |
// update orig textarea on change, for form submit | |
instance.model.document.on('change', function(ev) { | |
instance.updateSourceElement(); | |
console.log('args', arguments); | |
self.opts.content = instance.data.get(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment