refactored script resource declaration to allow for bundling, made script loading async, refactored RichTextEditor to use new method
This commit is contained in:
		| @ -198,32 +198,49 @@ Oqtane.Interop = { | ||||
|             script.onerror = rej(); | ||||
|         }); | ||||
|     }, | ||||
|     loadScript: async function (url, integrity, crossorigin) { | ||||
|         const promise = new Promise((resolve, reject) => { | ||||
|  | ||||
|             if (loadjs.isDefined(url)) { | ||||
|                 resolve(true); | ||||
|                 return; | ||||
|     includeScripts: async function (scripts) { | ||||
|         const bundles = []; | ||||
|         for (let s = 0; s < scripts.length; s++) { | ||||
|             if (scripts[s].bundle === '') { | ||||
|                 scripts[s].bundle = scripts[s].href; | ||||
|             } | ||||
|  | ||||
|             loadjs(url, url, { | ||||
|                 async: false, | ||||
|                 returnPromise: true, | ||||
|                 before: function (path, element) { | ||||
|                     if (path === url && integrity !== '') { | ||||
|                         element.integrity = integrity; | ||||
|                     } | ||||
|                     if (path === url && crossorigin !== '') { | ||||
|                         element.crossOrigin = crossorigin; | ||||
|                     } | ||||
|             if (!bundles.includes(scripts[s].bundle)) { | ||||
|                 bundles.push(scripts[s].bundle); | ||||
|             } | ||||
|         } | ||||
|         const urls = []; | ||||
|         for (let b = 0; b < bundles.length; b++) { | ||||
|             for (let s = 0; s < scripts.length; s++) { | ||||
|                 if (scripts[s].bundle === bundles[b]) { | ||||
|                     urls.push(scripts[s].href); | ||||
|                 } | ||||
|             }) | ||||
|             .then(function () { resolve(true) }) | ||||
|             .catch(function (pathsNotFound) { reject(false) }); | ||||
|         }); | ||||
|  | ||||
|         const result = await promise; | ||||
|         return; | ||||
|             } | ||||
|             const promise = new Promise((resolve, reject) => { | ||||
|                 if (loadjs.isDefined(bundles[b])) { | ||||
|                     resolve(true); | ||||
|                 } | ||||
|                 else { | ||||
|                     loadjs(urls, bundles[b], { | ||||
|                         async: true, | ||||
|                         returnPromise: true, | ||||
|                         before: function (path, element) { | ||||
|                             for (let s = 0; s < scripts.length; s++) { | ||||
|                                 if (path === scripts[s].href && scripts[s].integrity !== '') { | ||||
|                                     element.integrity = scripts[s].integrity; | ||||
|                                 } | ||||
|                                 if (path === scripts[s].href && scripts[s].crossorigin !== '') { | ||||
|                                     element.crossOrigin = scripts[s].crossorigin; | ||||
|                                 } | ||||
|                             } | ||||
|                         } | ||||
|                     }) | ||||
|                     .then(function () { resolve(true) }) | ||||
|                     .catch(function (pathsNotFound) { reject(false) }); | ||||
|                 } | ||||
|             }); | ||||
|             await promise; | ||||
|             urls = []; | ||||
|         } | ||||
|     }, | ||||
|     getAbsoluteUrl: function (url) { | ||||
|         var a = document.createElement('a'); | ||||
| @ -343,31 +360,5 @@ Oqtane.Interop = { | ||||
|         setInterval(function () { | ||||
|             window.location.href = url; | ||||
|         }, wait * 1000); | ||||
|     }, | ||||
|     loadBootstrapJS: async function () { | ||||
|         if (!loadjs.isDefined('Bootstrap')) { | ||||
|             const bootstrap = loadjs(['https://code.jquery.com/jquery-3.3.1.slim.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js', 'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js'], 'Bootstrap', { | ||||
|                 async: false, | ||||
|                 returnPromise: true, | ||||
|                 before: function (path, element) { | ||||
|                     if (path === 'https://code.jquery.com/jquery-3.3.1.slim.min.js') { | ||||
|                         element.integrity = 'sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo'; | ||||
|                         element.crossOrigin = 'anonymous'; | ||||
|                     } | ||||
|                     if (path === 'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js') { | ||||
|                         element.integrity = 'sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1'; | ||||
|                         element.crossOrigin = 'anonymous'; | ||||
|                     } | ||||
|                     if (path === 'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js') { | ||||
|                         element.integrity = 'sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM'; | ||||
|                         element.crossOrigin = 'anonymous'; | ||||
|                     } | ||||
|                 } | ||||
|             }) | ||||
|             .then(function () { }) | ||||
|             .catch(function (pathsNotFound) { }); | ||||
|  | ||||
|             await bootstrap; | ||||
|         } | ||||
|     } | ||||
| }; | ||||
|  | ||||
| @ -5,15 +5,7 @@ Oqtane.RichTextEditor = { | ||||
|         quillElement, toolBar, readOnly, | ||||
|         placeholder, theme, debugLevel) { | ||||
|  | ||||
|         if (!loadjs.isDefined('Quill')) { | ||||
|             const loadQuill = loadjs(['js/quill1.3.6.min.js', 'js/quill-blot-formatter.min.js'], 'Quill', | ||||
|                 { async: true, returnPromise: true }) | ||||
|                 .then(function () { | ||||
|                     Quill.register('modules/blotFormatter', QuillBlotFormatter.default); | ||||
|                 }) | ||||
|                 .catch(function (pathsNotFound) { }); | ||||
|             await loadQuill; | ||||
|         } | ||||
|         Quill.register('modules/blotFormatter', QuillBlotFormatter.default); | ||||
|  | ||||
|         var options = { | ||||
|             debug: debugLevel, | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Shaun Walker
					Shaun Walker