Changeset 1072 for trunk


Ignore:
Timestamp:
10/08/08 18:48:29 (11 years ago)
Author:
douglas
Message:

Ticket #1297 Move certain plugins to an unsupported directory for phasing out, while still allowing them to load.

Location:
trunk
Files:
1 added
1 edited
7 moved

Legend:

Unmodified
Added
Removed
  • trunk/XinhaCore.js

    r1071 r1072  
    32943294 * @private 
    32953295 * @param {String} pluginName 
     3296 * @param {Boolean} return the directory for an unsupported plugin 
    32963297 * @returns {String} path to plugin 
    32973298 */ 
    3298 Xinha.getPluginDir = function(plugin) 
     3299Xinha.getPluginDir = function(plugin, forceUnsupported) 
    32993300{ 
    33003301  if (Xinha.externalPlugins[plugin]) 
     
    33023303    return Xinha.externalPlugins[plugin][0]; 
    33033304  } 
    3304   else 
    3305   { 
    3306     return _editor_url + "plugins/" + plugin ; 
    3307   } 
     3305  if (forceUnsupported || 
     3306      // If the plugin is fully loaded, it's supported status is already set. 
     3307      (window[plugin] && (typeof window[plugin].supported != 'undefined') && !window[plugin].supported)) 
     3308  { 
     3309    return _editor_url + "unsupported/" + plugin ; 
     3310  } 
     3311  return _editor_url + "plugins/" + plugin ; 
    33083312} 
    33093313/** Static function that loads the given plugin 
     
    33203324 
    33213325  // Might already be loaded 
    3322   if ( typeof window['pluginName'] != 'undefined' ) 
     3326  if ( typeof window[pluginName] != 'undefined' ) 
    33233327  { 
    33243328    if ( callback ) 
     
    33303334  Xinha._pluginLoadStatus[pluginName] = 'loading'; 
    33313335   
    3332   var loadUrl = function(url){ 
    3333     Xinha._loadback(url, callback ? function() { callback(pluginName); } : null); 
    3334   } 
    3335    
    33363336  if(!url) 
    33373337  { 
    33383338    if (Xinha.externalPlugins[pluginName]) 
    33393339    { 
    3340       loadUrl(Xinha.externalPlugins[pluginName][0]+Xinha.externalPlugins[pluginName][1]); 
     3340      Xinha._loadback(Xinha.externalPlugins[pluginName][0]+Xinha.externalPlugins[pluginName][1], callback, this, pluginName); 
    33413341    } 
    33423342    else 
    33433343    { 
    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  } 
    33753348   
    33763349  return false; 
     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  } 
    33773418}; 
    33783419/** Stores a status for each loading plugin that may be one of "loading","ready", or "failed" 
     
    58385879  else 
    58395880  { 
    5840     return _editor_url + "plugins/" + plugin + "/img/" + file; 
     5881    var pluginDir = window[plugin].supported ? 'plugins/' : 'unsupported/'; 
     5882    return _editor_url + pluginDir + plugin + "/img/" + file; 
    58415883  } 
    58425884}; 
Note: See TracChangeset for help on using the changeset viewer.