| 3344 | | var dir = this.getPluginDir(pluginName); |
| 3345 | | var file = pluginName + ".js"; |
| 3346 | | url = dir + "/" + file; |
| 3347 | | //try loading using new naming scheme unconditionally |
| 3348 | | loadUrl(url); |
| 3349 | | //check for file existance |
| 3350 | | Xinha.ping(url, |
| 3351 | | // on success do nothing, all OK |
| 3352 | | null, |
| 3353 | | //on fail try old naming scheme |
| 3354 | | function(){ |
| 3355 | | //clean script tag for failed url |
| 3356 | | Xinha.removeFromParent(document.getElementById(url)); |
| 3357 | | file = pluginName.replace(/([a-z])([A-Z])([a-z])/g, function (str, l1, l2, l3) { return l1 + "-" + l2.toLowerCase() + l3; }).toLowerCase() + ".js"; |
| 3358 | | url = dir + "/" + file; |
| 3359 | | //load |
| 3360 | | loadUrl(url); |
| 3361 | | //check for file existance |
| 3362 | | Xinha.ping(url, |
| 3363 | | //on success issue informational message to console |
| 3364 | | function(){Xinha.debugMsg('You are using an obsolete naming scheme for the Xinha plugin '+pluginName+'. Please rename '+file+' to '+pluginName+'.js', 'warn' );}, |
| 3365 | | //on fail inform loadPlugins() of fail and issue warning to console |
| 3366 | | function(){ |
| 3367 | | Xinha._pluginLoadStatus[pluginName] = 'failed'; |
| 3368 | | Xinha.debugMsg('Xinha was not able to find the plugin file '+url+'. Please make sure the plugin exist.', 'warn') |
| 3369 | | Xinha.removeFromParent(document.getElementById(url)); |
| 3370 | | }); |
| 3371 | | }); |
| 3372 | | } |
| 3373 | | } |
| 3374 | | |
| | 3344 | var editor = this; |
| | 3345 | multiStageLoader('start',pluginName); |
| | 3346 | } |
| | 3347 | } |
| | 3350 | |
| | 3351 | // This function will try to load a plugin in multiple passes. It tries to |
| | 3352 | // load the plugin from either the plugin or unsupported directory, using |
| | 3353 | // both naming schemes in this order: |
| | 3354 | // 1. /plugins -> CurrentNamingScheme |
| | 3355 | // 2. /plugins -> old-naming-scheme |
| | 3356 | // 3. /unsupported -> CurrentNamingScheme |
| | 3357 | // 4. /unsupported -> old-naming-scheme |
| | 3358 | |
| | 3359 | function multiStageLoader(stage,pluginName) |
| | 3360 | { |
| | 3361 | switch (stage) |
| | 3362 | { |
| | 3363 | case 'start': |
| | 3364 | var nextstage = 'old_naming'; |
| | 3365 | var dir = editor.getPluginDir(pluginName); |
| | 3366 | var file = pluginName + ".js"; |
| | 3367 | break; |
| | 3368 | case 'old_naming': |
| | 3369 | var nextstage = 'unsupported'; |
| | 3370 | var dir = editor.getPluginDir(pluginName); |
| | 3371 | var file = pluginName.replace(/([a-z])([A-Z])([a-z])/g, function (str, l1, l2, l3) { return l1 + "-" + l2.toLowerCase() + l3; }).toLowerCase() + ".js"; |
| | 3372 | var success_message = 'You are using an obsolete naming scheme for the Xinha plugin '+pluginName+'. Please rename '+file+' to '+pluginName+'.js'; |
| | 3373 | break; |
| | 3374 | case 'unsupported': |
| | 3375 | var nextstage = 'unsupported_old_name'; |
| | 3376 | var dir = editor.getPluginDir(pluginName, true); |
| | 3377 | var file = pluginName + ".js"; |
| | 3378 | var success_message = 'You are using the unsupported Xinha plugin '+pluginName+'. If you wish continued support, please see http://trac.xinha.org/ticket/1297'; |
| | 3379 | break; |
| | 3380 | case 'unsupported_old_name': |
| | 3381 | var nextstage = ''; |
| | 3382 | var dir = editor.getPluginDir(pluginName, true); |
| | 3383 | var file = pluginName.replace(/([a-z])([A-Z])([a-z])/g, function (str, l1, l2, l3) { return l1 + "-" + l2.toLowerCase() + l3; }).toLowerCase() + ".js"; |
| | 3384 | var success_message = 'You are using the unsupported Xinha plugin '+pluginName+'. If you wish continued support, please see http://trac.xinha.org/ticket/1297'; |
| | 3385 | break; |
| | 3386 | default: |
| | 3387 | Xinha._pluginLoadStatus[pluginName] = 'failed'; |
| | 3388 | Xinha.debugMsg('Xinha was not able to find the plugin '+pluginName+'. Please make sure the plugin exists.', 'warn') |
| | 3389 | return; |
| | 3390 | } |
| | 3391 | var url = dir + "/" + file; |
| | 3392 | |
| | 3393 | // This is a callback wrapper that allows us to set the plugin's status |
| | 3394 | // once it loads. |
| | 3395 | function statusCallback(pluginName) |
| | 3396 | { |
| | 3397 | window[pluginName].supported = stage.indexOf('unsupported') != 0; |
| | 3398 | callback(pluginName); |
| | 3399 | } |
| | 3400 | |
| | 3401 | // To speed things up, we start loading the script file before pinging it. |
| | 3402 | // If the load fails, we'll just clean up afterwards. |
| | 3403 | Xinha._loadback(url, statusCallback, this, pluginName); |
| | 3404 | |
| | 3405 | Xinha.ping(url, |
| | 3406 | // On success, we'll display a success message if there is one. |
| | 3407 | function() |
| | 3408 | { |
| | 3409 | if (success_message) Xinha.debugMsg(success_message); |
| | 3410 | }, |
| | 3411 | // On failure, we'll clean up the failed load and try the next stage |
| | 3412 | function() |
| | 3413 | { |
| | 3414 | Xinha.removeFromParent(document.getElementById(url)); |
| | 3415 | multiStageLoader(nextstage, pluginName); |
| | 3416 | }); |
| | 3417 | } |