Changeset 1062
- Timestamp:
- 10/05/08 17:26:29 (2 months ago)
- Files:
-
- 1 modified
-
trunk/XinhaCore.js (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/XinhaCore.js
r1061 r1062 3318 3318 * @returns {Boolean} true if plugin loaded, false otherwise 3319 3319 */ 3320 Xinha.loadPlugin = function(pluginName, callback, plugin_file)3320 Xinha.loadPlugin = function(pluginName, callback, url) 3321 3321 { 3322 3322 if ( !Xinha.isSupportedBrowser ) return; … … 3333 3333 return true; 3334 3334 } 3335 /* 3336 if(!plugin_file) 3337 { 3338 var dir = this.getPluginDir(pluginName); 3339 var plugin = pluginName.replace(/([a-z])([A-Z])([a-z])/g, function (str, l1, l2, l3) { return l1 + "-" + l2.toLowerCase() + l3; }).toLowerCase() + ".js"; 3340 plugin_file = dir + "/" + plugin; 3341 } 3335 Xinha._pluginLoadStatus[pluginName] = 'loading'; 3336 3337 var loadUrl = function(url){ 3338 Xinha._loadback(url, callback ? function() { callback(pluginName); } : null); 3339 } 3340 3341 if(!url) 3342 { 3343 if (Xinha.externalPlugins[pluginName]) 3344 { 3345 loadUrl(Xinha.externalPlugins[pluginName][0]+Xinha.externalPlugins[pluginName][1]); 3346 } 3347 else 3348 { 3349 var dir = this.getPluginDir(pluginName); 3350 var file = pluginName + ".js"; 3351 url = dir + "/" + file; 3352 Xinha.ping(url, function(){loadUrl(url)}); 3353 3354 file = pluginName.replace(/([a-z])([A-Z])([a-z])/g, function (str, l1, l2, l3) { return l1 + "-" + l2.toLowerCase() + l3; }).toLowerCase() + ".js"; 3355 url = dir + "/" + file; 3356 Xinha.ping(url, function(){loadUrl(url)}); 3357 3358 /* synchronous: 3359 if (!Xinha.ping(dir + "/" + file)) 3360 { 3361 file = pluginName.replace(/([a-z])([A-Z])([a-z])/g, function (str, l1, l2, l3) { return l1 + "-" + l2.toLowerCase() + l3; }).toLowerCase() + ".js"; 3362 if (Xinha.ping(dir + "/" + file)) 3363 { 3364 url = dir + "/" + file; 3365 Xinha.externalPlugins[pluginName] = [dir,'/'+ file]; 3366 Xinha.debugMsg('You use an obsolete naming scheme for the Xinha plugin '+pluginName+'. Please rename '+file+' to '+pluginName+'.js' ); 3367 } 3368 else 3369 { 3370 Xinha.debugMsg('Xinha was not able to find the plugin file '+url+'. Please make sure the plugin exist.') 3371 Xinha._pluginLoadStatus[pluginName] = 'failed'; 3372 return true 3373 } 3374 } 3342 3375 */ 3343 3344 Xinha._loadback(plugin_file, callback ? function() { callback(pluginName); } : null); 3376 } 3377 } 3378 3379 3345 3380 return false; 3346 3381 }; … … 3380 3415 { 3381 3416 var p = nuPlugins[i]; 3382 3383 if (Xinha.externalPlugins[p]) 3384 { 3385 url = Xinha.externalPlugins[p][0]+Xinha.externalPlugins[p][1]; 3386 } 3387 else 3388 { 3389 var dir = this.getPluginDir(p); 3390 var file = p + ".js"; 3391 url = dir + "/" + file; 3392 3393 if (typeof Xinha._pluginLoadStatus[p] == 'undefined') 3394 { 3395 if (!Xinha.ping(dir + "/" + file)) 3396 { 3397 file = p.replace(/([a-z])([A-Z])([a-z])/g, function (str, l1, l2, l3) { return l1 + "-" + l2.toLowerCase() + l3; }).toLowerCase() + ".js"; 3398 if (Xinha.ping(dir + "/" + file)) 3399 { 3400 url = dir + "/" + file; 3401 Xinha.externalPlugins[p] = [dir,'/'+ file]; 3402 Xinha.debugMsg('You use an obsolete naming scheme for the Xinha plugin '+p+'. Please rename '+file+' to '+p+'.js' ); 3403 } 3404 else 3405 { 3406 Xinha.debugMsg('Xinha was not able to find the plugin file '+url+'. Please make sure the plugin exist.') 3407 Xinha._pluginLoadStatus[p] = 'failed'; 3408 continue; 3409 } 3410 } 3411 } 3412 } 3413 3417 3414 3418 if (p == 'FullScreen' && !Xinha.externalPlugins['FullScreen'] ) continue; //prevent trying to load FullScreen plugin from the plugins folder 3415 3419 3416 if ( typeof Xinha._pluginLoadStatus[p] == 'undefined' && typeof window[p] == 'undefined')3420 if ( typeof Xinha._pluginLoadStatus[p] == 'undefined') 3417 3421 { 3418 3422 // Load it 3419 Xinha._pluginLoadStatus[p] = 'loading';3420 3423 Xinha.loadPlugin(p, 3421 3424 function(plugin) 3422 3425 { 3423 3426 Xinha.setLoadingMessage (Xinha._lc("Finishing")); 3427 3424 3428 if ( typeof window[plugin] != 'undefined' ) 3425 3429 { … … 3428 3432 else 3429 3433 { 3430 // Actually, this won't happen, because if the script fails3431 // it will throw an exception preventing the callback from3432 // running. This will leave it always in the "loading" state3433 // unfortunatly that means we can't fail plugins gracefully3434 // by just skipping them.3435 3434 Xinha._pluginLoadStatus[plugin] = 'failed'; 3436 3435 } … … 3439 3438 retVal = false; 3440 3439 } 3441 else 3442 { 3443 // @todo: a simple (if) would not be better than this tortuous (switch) structure ? 3444 // if ( Xinha._pluginLoadStatus[p] !== 'failed' && Xinha._pluginLoadStatus[p] !== 'ready' ) 3445 // { 3446 // retVal = false; 3447 // } 3448 switch ( Xinha._pluginLoadStatus[p] ) 3449 { 3450 case 'failed': 3451 case 'ready' : 3452 break; 3453 3454 //case 'loading': 3455 default : 3456 retVal = false; 3457 break; 3458 } 3459 } 3460 } 3461 3440 else if ( Xinha._pluginLoadStatus[p] == 'loading') 3441 { 3442 retVal = false; 3443 } 3444 } 3445 3462 3446 // All done, just return 3463 3447 if ( retVal ) 3464 3448 { 3465 3449 return true; 3466 } 3450 } 3467 3451 3468 3452 // Waiting on plugins to load, return false now and come back a bit later … … 3470 3454 if ( callbackIfNotReady ) 3471 3455 { 3472 setTimeout(function() { if ( Xinha.loadPlugins(plugins, callbackIfNotReady) ) { callbackIfNotReady(); } }, 50); 3456 setTimeout(function() 3457 { 3458 if ( Xinha.loadPlugins(plugins, callbackIfNotReady) ) 3459 { 3460 callbackIfNotReady(); 3461 } 3462 }, 50); 3473 3463 } 3474 3464 return retVal; … … 6235 6225 req.send(null); 6236 6226 }; 6227 6228 Xinha.ping = function(url, successHandler, failHandler) 6229 { 6230 var req = null; 6231 req = Xinha.getXMLHTTPRequestObject(); 6232 6233 function callBack() 6234 { 6235 if ( req.readyState == 4 ) 6236 { 6237 if ( req.status == 200 || Xinha.isRunLocally && req.status == 0 ) 6238 { 6239 if (successHandler) successHandler(req); 6240 } 6241 else 6242 { 6243 if (failHandler) failHandler(req) 6244 } 6245 } 6246 } 6247 6248 req.onreadystatechange = callBack; 6249 req.open('HEAD', url, true); 6250 req.send(null); 6251 }; 6252 6237 6253 /** Use XMLHTTPRequest to receive some data from the server syncronously 6238 6254 * @param {String} url The address for the HTTPRequest … … 6253 6269 { 6254 6270 return ''; 6255 }6256 };6257 Xinha.ping = function(url)6258 {6259 var req = null;6260 req = Xinha.getXMLHTTPRequestObject();6261 6262 // Synchronous!6263 req.open('HEAD', url, false);6264 req.send(null);6265 if ( req.status >= 400 )6266 {6267 return false;6268 }6269 else6270 {6271 return true;6272 6271 } 6273 6272 }; … … 7316 7315 { 7317 7316 if (typeof console != 'undefined' && typeof console.log == 'function') console.log(text); 7317 if (typeof opera != 'undefined' && typeof opera.postError == 'function') opera.postError(text); 7318 7318 7319 } 7319 7320 Xinha.notImplemented = function(methodName)
