Skip to content

Instantly share code, notes, and snippets.

@BananaAcid
Created September 1, 2022 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BananaAcid/7e8d7b887556323f80c2d4dc33caffef to your computer and use it in GitHub Desktop.
Save BananaAcid/7e8d7b887556323f80c2d4dc33caffef to your computer and use it in GitHub Desktop.
add sripts and style and wait for them async to be loaded
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