Changeset 667

Show
Ignore:
Timestamp:
02/18/08 09:46:14 (10 months ago)
Author:
ma..@jesperkristensen.dk
Message:

misc code style fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/config-service/src/chrome/chromeFiles/content/config.js

    r666 r667  
    22// used anywhere within this file and versioning.js 
    33 
    4 function Config() 
    5 
     4function Config() { 
    65  this._scripts = null; 
    76  this._configFile = this._scriptDir; 
     
    1514 
    1615Config.prototype = { 
    17   addObserver: function(observer, script) 
    18   { 
     16  addObserver: function(observer, script) { 
    1917    var observers = script ? script._observers : this._observers; 
    2018    observers.push(observer); 
    2119  }, 
    2220 
    23   removeObserver: function(observer, script) 
    24   { 
     21  removeObserver: function(observer, script) { 
    2522    var observers = script ? script._observers : this._observers; 
    2623    var index = observers.indexOf(observer); 
     
    2926  }, 
    3027 
    31   _notifyObservers: function(script, event, data) 
    32   { 
     28  _notifyObservers: function(script, event, data) { 
    3329    var observers = this._observers.concat(script._observers); 
    3430    for (var i = 0, observer; observer = observers[i]; i++) 
     
    3632  }, 
    3733 
    38   _changed: function(script, event, data) 
    39   { 
     34  _changed: function(script, event, data) { 
    4035    this._save(); 
    4136    this._notifyObservers(script, event, data); 
    4237  }, 
    4338 
    44   installIsUpdate: function(script) 
    45   { 
     39  installIsUpdate: function(script) { 
    4640    return this._find(script) > -1; 
    4741  }, 
    4842 
    49   _find: function(aScript) 
    50   { 
     43  _find: function(aScript) { 
    5144    namespace = aScript._namespace.toLowerCase(); 
    5245    name = aScript._name.toLowerCase(); 
     
    5952  }, 
    6053 
    61   _load: function() 
    62   { 
     54  _load: function() { 
    6355    var domParser = Components.classes["@mozilla.org/xmlextras/domparser;1"] 
    6456                              .createInstance(Components.interfaces.nsIDOMParser); 
     
    9183          scriptResource._filename = childNode.getAttribute("filename"); 
    9284          scriptResource._mimetype = childNode.getAttribute("mimetype"); 
    93           scriptResource._charset = childNode.getAttribute("charset"); 
     85          scriptResource._charset = childNode.getAttribute("charset"); 
    9486          script._resources.push(scriptResource); 
    9587          break; 
     
    108100  }, 
    109101 
    110   _save: function() 
    111   { 
     102  _save: function() { 
    112103    var doc = Components.classes["@mozilla.org/xmlextras/domparser;1"] 
    113104      .createInstance(Components.interfaces.nsIDOMParser) 
     
    141132      } 
    142133 
    143       for (var j = 0; j< scriptObj._resources.length; j++) { 
     134      for (var j = 0; j < scriptObj._resources.length; j++) { 
    144135        var imp = scriptObj._resources[j]; 
    145136        var resourceNode = doc.createElement("Resource"); 
     
    148139        resourceNode.setAttribute("filename", imp._filename); 
    149140        resourceNode.setAttribute("mimetype", imp._mimetype); 
    150         if (imp._charset) { 
     141        if (imp._charset) 
    151142          resourceNode.setAttribute("charset", imp._charset); 
    152         } 
    153143 
    154144        scriptNode.appendChild(doc.createTextNode("\n\t\t")); 
     
    178168  }, 
    179169 
    180   parse: function(source, uri) 
    181   { 
     170  parse: function(source, uri) { 
    182171    var ioservice = Components.classes["@mozilla.org/network/io-service;1"] 
    183172                              .getService(Components.interfaces.nsIIOService); 
     
    206195 
    207196      while ((result = lines[lnIdx++])) { 
    208         if (result.indexOf("// ==/UserScript==") == 0) { 
     197        if (result.indexOf("// ==/UserScript==") == 0) 
    209198          break; 
    210         } 
    211199 
    212200        var match = result.match(/\/\/ \@(\S+)\s+([^\n]+)/); 
     
    260248 
    261249    // if no meta info, default to reasonable values 
    262     if (script._name == null) { 
     250    if (script._name == null) 
    263251      script._name = parseScriptName(uri); 
    264     } 
    265  
    266     if (script._namespace == null) { 
     252 
     253    if (script._namespace == null) 
    267254      script._namespace = uri.host; 
    268     } 
    269255 
    270256    if (!script._description) 
    271257      script._description = ""; 
    272258 
    273     if (script._includes.length == 0) { 
     259    if (script._includes.length == 0) 
    274260      script._includes.push("*"); 
    275     } 
    276261 
    277262    return script; 
    278263  }, 
    279264 
    280   install: function(script) 
    281   { 
     265  install: function(script) { 
    282266    GM_log("> Config.install"); 
    283267 
     
    301285  }, 
    302286 
    303   uninstall: function(script, uninstallPrefs) 
    304   { 
     287  uninstall: function(script, uninstallPrefs) { 
    305288    var idx = this._find(script); 
    306289    this._scripts.splice(idx, 1); 
     
    327310   *                    the script will be moved. 
    328311   */ 
    329   move: function(script, destination) 
    330   { 
     312  move: function(script, destination) { 
    331313    var from = this._scripts.indexOf(script); 
    332314    var to = -1; 
     
    352334  }, 
    353335 
    354   get _scriptDir() 
    355   { 
     336  get _scriptDir() { 
    356337    var newDir = this._newScriptDir; 
    357338    if (newDir.exists()) 
     
    375356  }, 
    376357 
    377   get _newScriptDir() 
    378   { 
     358  get _newScriptDir() { 
    379359    var file = Components.classes["@mozilla.org/file/directory_service;1"] 
    380360                         .getService(Components.interfaces.nsIProperties) 
     
    384364  }, 
    385365 
    386   get _oldScriptDir() 
    387   { 
     366  get _oldScriptDir() { 
    388367    var file = getContentDir(); 
    389368    file.append("scripts"); 
     
    391370  }, 
    392371 
    393   get scripts() 
    394   { 
     372  get scripts() { 
    395373    return this._scripts.concat(); 
    396374  }, 
    397375 
    398   getScriptsForUrl: function(url, includeDisabled) 
    399   { 
     376  getScriptsForUrl: function(url, includeDisabled) { 
    400377    var scripts = []; 
    401378 
     
    425402  .loadSubScript("chrome://greasemonkey/content/versioning.js"); 
    426403 
    427 function Script(config) 
    428 
     404function Script(config) { 
    429405  this._config = config; 
    430406  this._observers = []; 
     
    464440  get resources() { return this._resources.concat(); }, 
    465441 
    466   get _file() 
    467   { 
     442  get _file() { 
    468443    var file = this._basedirFile; 
    469444    file.append(this._filename); 
     
    473448  get editFile() { return this._file; }, 
    474449 
    475   get _basedirFile() 
    476   { 
     450  get _basedirFile() { 
    477451    var file = this._config._scriptDir; 
    478452    file.append(this._basedir); 
     
    483457  get textContent() { return getContents(this._file); }, 
    484458 
    485   _initFileName: function(name, useExt) 
    486   { 
     459  _initFileName: function(name, useExt) { 
    487460    var ext = ""; 
    488461    name = name.toLowerCase(); 
     
    511484  }, 
    512485 
    513   _initFile: function(tempFile) 
    514   { 
     486  _initFile: function(tempFile) { 
    515487    var file = this._config._scriptDir; 
    516488    var name = this._initFileName(this._name, false); 
     
    534506}; 
    535507 
    536 function ScriptRequire(script) 
    537 
     508function ScriptRequire(script) { 
    538509  this._script = script; 
    539510 
     
    544515 
    545516ScriptRequire.prototype = { 
    546   get _file() 
    547   { 
     517  get _file() { 
    548518    var file = this._script._basedirFile; 
    549519    file.append(this._filename); 
     
    554524  get textContent() { return getContents(this._file); }, 
    555525 
    556   _initFile: function() 
    557   { 
     526  _initFile: function() { 
    558527    var name = this._downloadUrl.substr(this._downloadUrl.lastIndexOf("/") + 1); 
    559528    if(name.indexOf("?") > 0) 
     
    577546}; 
    578547 
    579 function ScriptResource(script) 
    580 
     548function ScriptResource(script) { 
    581549  this._script = script; 
    582550 
     
    593561  get name() { return this._name; }, 
    594562 
    595   get _file() 
    596   { 
     563  get _file() { 
    597564    var file = this._script._basedirFile; 
    598565    file.append(this._filename); 
     
    602569  get textContent() { return getContents(this._file); }, 
    603570 
    604   get dataContent() 
    605   { 
     571  get dataContent() { 
    606572    var appSvc = Components.classes["@mozilla.org/appshell/appShellService;1"] 
    607573                           .getService(Components.interfaces.nsIAppShellService); 
     
    622588 
    623589  get urlToDownload() { return this._downloadUrl; }, 
    624   setDownloadedFile: function(tempFile, mimetype, charset) 
    625   { 
     590  setDownloadedFile: function(tempFile, mimetype, charset) { 
    626591    this._tempFile = tempFile; 
    627592    this._mimetype = mimetype; 
  • branches/config-service/src/chrome/chromeFiles/content/versioning.js

    r662 r667  
    66 * any necessary upgrades. 
    77 */ 
    8 Config.prototype._updateVersion = function() 
    9 
     8Config.prototype._updateVersion = function() { 
    109  log("> GM_updateVersion"); 
    1110 
     
    1312  var initialized = GM_prefRoot.getValue("version", "0.0"); 
    1413 
    15   if (GM_compareVersions(initialized, "0.3") == -1) { 
     14  if (GM_compareVersions(initialized, "0.3") == -1) 
    1615    this._pointThreeMigrate(); 
    17   } 
    1816 
    19   if (GM_compareVersions(initialized, "0.4.2") == -1) { 
     17  if (GM_compareVersions(initialized, "0.4.2") == -1) 
    2018    this._pointFourMigrate(); 
    21   } 
    2219 
    23   if (GM_compareVersions(initialized, "0.8") == -1) { 
     20  if (GM_compareVersions(initialized, "0.8") == -1) 
    2421    this._pointEightBackup(); 
    25   } 
    2622 
    2723  // update the currently initialized version so we don't do this work again. 
     
    4036 * paranoid and backup the folder the first time 0.8 runs. 
    4137 */ 
    42 Config.prototype._pointEightBackup = function() 
    43 
     38Config.prototype._pointEightBackup = function() { 
    4439  var scriptDir = this._newScriptDir; 
    4540  var scriptDirBackup = scriptDir.clone(); 
    4641  scriptDirBackup.leafName += "_08bak"; 
    47   if (scriptDir.exists() && !scriptDirBackup.exists()) { 
     42  if (scriptDir.exists() && !scriptDirBackup.exists()) 
    4843    scriptDir.copyTo(scriptDirBackup.parent, scriptDirBackup.leafName); 
    49   } 
    5044}; 
    5145 
     
    5347 * Copies the entire scripts directory to the new location, if it exists. 
    5448 */ 
    55 Config.prototype._pointFourMigrate = function() 
    56 
     49Config.prototype._pointFourMigrate = function() { 
    5750  log("> GM_pointFourMigrate"); 
    5851 
     
    6659 * Migrates the configuration directory from the old format to the new one 
    6760 */ 
    68 Config.prototype._pointThreeMigrate = function() 
    69 
     61Config.prototype._pointThreeMigrate = function() { 
    7062  log("> GM_pointThreeMigrate"); 
    7163 
     
    7668 
    7769  log("config file exists: " + configExists); 
    78   if (!configExists) { 
     70  if (!configExists) 
    7971    return; 
    80   } 
    8172 
    8273  // back up the config directory 
     
    9283 
    9384    // update the format of the config.xml file and move each file 
    94     var script = null; 
    95     var scriptFile = null; 
    9685    var doc = document.implementation.createDocument("", "", null); 
    9786 
     
    10493    var nodes = document.evaluate("/UserScriptConfig/Script", doc, null, 
    10594        XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); 
    106     var node; 
    10795 
    108     for (var i = 0; (node = nodes.snapshotItem(i)); i++) { 
    109       if (node.hasAttribute("id")) { 
     96    for (var i = 0, node; node = nodes.snapshotItem(i); i++) 
     97      if (node.hasAttribute("id")) 
    11098        node.setAttribute("filename", node.getAttribute("id")); 
    111       } 
    112     } 
    11399 
    114100    // save the config file 
     
    124110    log("config reloaded, moving files."); 
    125111 
    126     for (var i = 0; (script = this._scripts[i]); i++) { 
     112    for (var i = 0, script = null; script = this._scripts[i]; i++) { 
    127113      if (script._filename.match(/^\d+$/)) { 
    128114        var scriptFile = this._oldScriptDir;