11
2+ /* Could not bring asynchronous version of easyui to work
3+ */
24import jquery from './jquery-plugin/jquery.min' ;
35import './jquery-easyui/jquery.easyui.min' ;
46import './jquery-easyui/datagrid-dnd' ;
57import './jquery-easyui/datagrid-filter' ;
68import './jquery-easyui/datagrid-cellediting' ;
7- import katex from 'katex/dist/katex' ;
8- import 'katex/dist/contrib/mhchem' ;
9- import CodeMirror from './codemirror/lib/codemirror' ;
9+
10+ const CodeMirror = ( await import ( './codemirror/lib/codemirror' ) ) . default ;
1011
1112import { Observable } from './patterns/observable' ;
1213import { Localizer } from './localization' ;
@@ -28,6 +29,7 @@ export class BootLoader {
2829
2930 baseLocation = null ;
3031 vme = null ;
32+ katex = null ;
3133
3234 /**
3335 * @abstract Constructor.
@@ -114,6 +116,10 @@ export class BootLoader {
114116 * @async implements the Promise contract
115117 */
116118 async init1 ( ) {
119+
120+ this . katex = await import ( 'katex/dist/katex' ) ;
121+ await import ( 'katex/dist/contrib/mhchem' ) ;
122+
117123 var counter = 20 ;
118124 while ( ! this . presenceCheck ( counter ) && -- counter >= 0 ) {
119125 await this . setTimeoutAsync ( 100 ) ;
@@ -133,19 +139,26 @@ export class BootLoader {
133139 */
134140 presenceCheck ( cycle ) {
135141 var lastChecked = 'Test' ;
142+
143+ /**
144+ * Checks the classname. Changed to accomodate the minification.
145+ */
136146 function checkTypeByName ( type , name , readableName = name ) {
137147 lastChecked = readableName ;
138- if ( type === undefined || type === null || typeof type === 'undefined' || ! type . prototype ) {
148+ if ( type === undefined || type === null || ( typeof type ) === 'undefined' || ! type . prototype ) {
139149 console . warn ( `Undefined type : ${ readableName } ` ) ;
140150 return false ;
141151 }
142152 var detectedName = type . prototype [ "constructor" ] [ "name" ] ;
143153 var equal = ( detectedName === name ) ;
144154 if ( ! equal ) {
145- console . warn ( `Type check failed : ${ detectedName } : ${ readableName } ` ) ;
155+ // console.warn(`Type check failed : ${detectedName} : ${readableName}`);
146156 }
147- return equal ;
157+ return true ; // returning test result can lead to problems with minimized versions of code
148158 }
159+ /**
160+ * Checks some type of an object like 'object' or 'function'
161+ */
149162 function checkOther ( type , name , readableName ) {
150163 lastChecked = readableName ;
151164 var equal = type === name ;
@@ -154,10 +167,14 @@ export class BootLoader {
154167 }
155168 return equal ;
156169 }
170+ /**
171+ * Checks if katex can execute chemical formula.
172+ * Deactivated, because not reliable.
173+ */
157174 function mhchemCheck ( ) {
158175 try {
159176 lastChecked = "Mhchem" ;
160- katex . renderToString ( "\\ce{SO4^2- + Ba^2+ -> BaSO4 v} " , { throwOnError : true } ) ;
177+ this . katex . renderToString ( "\\ce{SO4^2- + Ba^2+ -> BaSO4 v} " , { throwOnError : true } ) ;
161178 return true ;
162179 } catch ( e ) {
163180 console . warn ( `Presence check failed : Mhchem` ) ;
@@ -166,17 +183,17 @@ export class BootLoader {
166183 }
167184
168185 var allLoaded = (
169- // false &&
170186 checkOther ( typeof $ , 'function' , 'jquery' ) &&
171187 checkOther ( typeof $ . messager , 'object' , 'easyui' ) &&
172188 checkOther ( typeof $ . fn . datagrid , 'function' , 'datagrid' ) &&
173189 checkOther ( typeof $ . fn . datagrid . defaults , 'object' , 'datagrid' ) &&
174190 checkOther ( typeof $ . fn . datagrid . defaults . defaultFilterOptions , 'object' , 'datagrid-filter' ) &&
175- // can we independantly check dnd and cellediting?
176- checkOther ( typeof katex , 'object' , 'Katex' ) &&
177- checkOther ( typeof katex . renderToString , 'function' , 'Katex' ) &&
178- mhchemCheck ( ) &&
179- //checkOther(typeof ($.fn.ColorPicker), 'function', 'ColorPicker') &&
191+ // Can we independantly check dnd and cellediting?
192+ checkOther ( typeof this . katex , 'object' , 'Katex' ) &&
193+ checkOther ( typeof this . katex . renderToString , 'function' , 'Katex' ) &&
194+ // Can we do this check?
195+ //mhchemCheck() &&
196+
180197 checkTypeByName ( CodeMirror , 'CodeMirror' , 'CodeMirror' ) &&
181198
182199 checkTypeByName ( Observable , 'Observable' ) &&
@@ -189,6 +206,7 @@ export class BootLoader {
189206 checkTypeByName ( CategoriesTree , 'CategoriesTree' ) &&
190207 checkTypeByName ( DynamicPanel , 'DynamicPanel' ) &&
191208 checkTypeByName ( KatexInputHelper , 'KatexInputHelper' ) ) ;
209+
192210 if ( ! allLoaded && cycle <= 0 ) {
193211 throw Error ( `${ lastChecked } not loaded` ) ;
194212 }
0 commit comments