214 |
214 |
215 var loaded_components = {}; |
215 var loaded_components = {}; |
216 var _load_component_running = false; |
216 var _load_component_running = false; |
217 function load_component(file) |
217 function load_component(file) |
218 { |
218 { |
|
219 var multiple = false; |
|
220 if ( typeof(file) == 'object' ) |
|
221 { |
|
222 if ( ENANO_JSRES_COMPRESSED ) |
|
223 { |
|
224 multiple = true; |
|
225 for ( var i = 0; i < file.length; i++ ) |
|
226 { |
|
227 file[i] = (file[i].replace(/\.js$/, '')) + '.js'; |
|
228 if ( loaded_components[file[i]] ) |
|
229 { |
|
230 file[i] = false; |
|
231 } |
|
232 } |
|
233 var file2 = []; |
|
234 for ( var i = 0; i < file.length; i++ ) |
|
235 { |
|
236 if ( file[i] ) |
|
237 file2.push(file[i]); |
|
238 } |
|
239 file = file2; |
|
240 delete(file2); |
|
241 if ( file.length < 1 ) |
|
242 { |
|
243 return true; |
|
244 } |
|
245 var file_flat = implode(',', file); |
|
246 } |
|
247 else |
|
248 { |
|
249 for ( var i = 0; i < file.length; i++ ) |
|
250 { |
|
251 load_component(file[i]); |
|
252 } |
|
253 return true; |
|
254 } |
|
255 } |
219 _load_component_running = true; |
256 _load_component_running = true; |
220 file = file.replace(/\.js$/, ''); |
257 if ( !multiple ) |
221 |
258 { |
222 if ( loaded_components[file + '.js'] ) |
259 file = file.replace(/\.js$/, ''); |
223 { |
260 |
224 // already loaded |
261 if ( loaded_components[file + '.js'] ) |
225 return true; |
262 { |
226 } |
263 // already loaded |
227 |
264 return true; |
228 console.info('Loading component %s via AJAX', file); |
265 } |
229 |
266 } |
230 load_show_win(file); |
267 |
|
268 console.info('Loading component %s via AJAX', ( multiple ? file_flat : file )); |
|
269 |
|
270 load_show_win(( multiple ? file_flat : file )); |
231 |
271 |
232 // get an XHR instance |
272 // get an XHR instance |
233 var ajax = ajaxMakeXHR(); |
273 var ajax = ajaxMakeXHR(); |
234 |
274 |
235 file = file + '.js'; |
275 if ( !multiple ) |
236 var uri = ( ENANO_JSRES_COMPRESSED ) ? scriptPath + '/includes/clientside/jsres.php?f=' + file : scriptPath + '/includes/clientside/static/' + file; |
276 file = file + '.js'; |
|
277 var uri = ( ENANO_JSRES_COMPRESSED ) ? scriptPath + '/includes/clientside/jsres.php?f=' + (multiple ? file_flat : file ) : scriptPath + '/includes/clientside/static/' + file; |
237 try |
278 try |
238 { |
279 { |
239 ajax.open('GET', uri, false); |
280 ajax.open('GET', uri, false); |
240 ajax.onreadystatechange = function() |
281 ajax.onreadystatechange = function() |
241 { |
282 { |
265 console.info("Component loader exception is shown below."); |
306 console.info("Component loader exception is shown below."); |
266 console.debug(e); |
307 console.debug(e); |
267 throw('load_component(): XHR for component ' + file + ' failed'); |
308 throw('load_component(): XHR for component ' + file + ' failed'); |
268 } |
309 } |
269 |
310 |
270 loaded_components[file] = true; |
311 if ( !multiple ) |
|
312 { |
|
313 loaded_components[file] = true; |
|
314 } |
271 _load_component_running = false; |
315 _load_component_running = false; |
272 return true; |
316 return true; |
273 } |
317 } |
274 |
318 |
275 function load_show_win(file) |
319 function load_show_win(file) |
278 if ( document.getElementById('_js_load_component') ) |
322 if ( document.getElementById('_js_load_component') ) |
279 { |
323 { |
280 document.getElementById('_js_load_component').innerHTML = img + msg_loading_component.replace('%component%', file); |
324 document.getElementById('_js_load_component').innerHTML = img + msg_loading_component.replace('%component%', file); |
281 return; |
325 return; |
282 } |
326 } |
283 file = file.replace(/\.js$/, ''); |
327 file = file.replace(/\.js$/, '').replace(/\.js,/g, ', '); |
284 var ld = document.createElement('div'); |
328 var ld = document.createElement('div'); |
285 ld.style.padding = '10px'; |
329 ld.style.padding = '10px'; |
286 ld.style.height = '12px'; |
330 ld.style.height = '12px'; |
287 ld.style.position = 'fixed'; |
331 ld.style.position = 'fixed'; |
288 ld.style.right = '5px'; |
332 ld.style.right = '5px'; |