Changeset 4476 in subversion


Ignore:
Timestamp:
Feb 1, 2011 3:04:31 AM (2 years ago)
Author:
alec
Message:
  • Fix command handlers return value check, unify typeof usage
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/js/app.js

    r4454 r4476  
    1818*/ 
    1919 
    20  
    2120function rcube_webmail() 
    2221{ 
     
    6463  this.set_env = function(p, value) 
    6564  { 
    66     if (p != null && typeof(p) == 'object' && !value) 
     65    if (p != null && typeof p === 'object' && !value) 
    6766      for (var n in p) 
    6867        this.env[n] = p[n]; 
     
    429428    // @deprecated 
    430429    for (var i in this.onloads) { 
    431       if (typeof(this.onloads[i]) == 'string') 
     430      if (typeof this.onloads[i] === 'string') 
    432431        eval(this.onloads[i]); 
    433       else if (typeof(this.onloads[i]) == 'function') 
     432      else if (typeof this.onloads[i] === 'function') 
    434433        this.onloads[i](); 
    435434      } 
     
    469468 
    470469    // process external commands 
    471     if (typeof this.command_handlers[command] == 'function') { 
     470    if (typeof this.command_handlers[command] === 'function') { 
    472471      var ret = this.command_handlers[command](props, obj); 
    473       return ret !== null ? ret : (obj ? false : true); 
    474     } 
    475     else if (typeof this.command_handlers[command] == 'string') { 
     472      return ret !== undefined ? ret : (obj ? false : true); 
     473    } 
     474    else if (typeof this.command_handlers[command] === 'string') { 
    476475      var ret = window[this.command_handlers[command]](props, obj); 
    477       return ret !== null ? ret : (obj ? false : true); 
     476      return ret !== undefined ? ret : (obj ? false : true); 
    478477    } 
    479478 
     
    481480    this.triggerEvent('actionbefore', {props:props, action:command}); 
    482481    var event_ret = this.triggerEvent('before'+command, props); 
    483     if (typeof event_ret != 'undefined') { 
     482    if (event_ret !== undefined) { 
    484483      // abort if one the handlers returned false 
    485484      if (event_ret === false) 
     
    10351034      default: 
    10361035        var func = command.replace(/-/g, '_'); 
    1037         if (this[func] && typeof this[func] == 'function') 
     1036        if (this[func] && typeof this[func] === 'function') 
    10381037          this[func](props); 
    10391038        break; 
     
    14111410    if (this.buttons_sel) { 
    14121411      for (var id in this.buttons_sel) 
    1413         if (typeof id != 'function') 
     1412        if (typeof id !== 'function') 
    14141413          this.button_out(this.buttons_sel[id], id); 
    14151414      this.buttons_sel = {}; 
     
    16971696      } 
    16981697      else if (message.has_children) { 
    1699         if (typeof(message.expanded) == 'undefined' && (this.env.autoexpand_threads == 1 || (this.env.autoexpand_threads == 2 && message.unread_children))) { 
     1698        if (message.expanded === undefined && (this.env.autoexpand_threads == 1 || (this.env.autoexpand_threads == 2 && message.unread_children))) { 
    17001699          message.expanded = true; 
    17011700        } 
     
    17851784    var update, add_url = ''; 
    17861785 
    1787     if (typeof sort_col == 'undefined') 
     1786    if (sort_col === undefined) 
    17881787      sort_col = this.env.sort_col; 
    17891788    if (!sort_order) 
     
    23812380  this.copy_messages = function(mbox) 
    23822381  { 
    2383     if (mbox && typeof mbox == 'object') 
     2382    if (mbox && typeof mbox === 'object') 
    23842383      mbox = mbox.id; 
    23852384 
     
    24102409  this.move_messages = function(mbox) 
    24112410  { 
    2412     if (mbox && typeof mbox == 'object') 
     2411    if (mbox && typeof mbox === 'object') 
    24132412      mbox = mbox.id; 
    24142413 
     
    29012900    // check if all files has been uploaded 
    29022901    for (var key in this.env.attachments) { 
    2903       if (typeof this.env.attachments[key] == 'object' && !this.env.attachments[key].complete) { 
     2902      if (typeof this.env.attachments[key] === 'object' && !this.env.attachments[key].complete) { 
    29042903        alert(this.get_label('notuploadedwarning')); 
    29052904        return false; 
     
    34393438 
    34403439    // insert all members of a group 
    3441     if (typeof this.env.contacts[id] == 'object' && this.env.contacts[id].id) { 
     3440    if (typeof this.env.contacts[id] === 'object' && this.env.contacts[id].id) { 
    34423441      insert += this.env.contacts[id].name + ', '; 
    34433442      this.group2expand = $.extend({}, this.env.contacts[id]); 
     
    34453444      this.http_request('group-expand', '_source='+urlencode(this.env.contacts[id].source)+'&_gid='+urlencode(this.env.contacts[id].id), false); 
    34463445    } 
    3447     else if (typeof this.env.contacts[id] == 'string') 
     3446    else if (typeof this.env.contacts[id] === 'string') 
    34483447      insert = this.env.contacts[id] + ', '; 
    34493448 
     
    35443543      // add each result line to list 
    35453544      for (i=0; i < a_results.length; i++) { 
    3546         text = typeof a_results[i] == 'object' ? a_results[i].name : a_results[i]; 
     3545        text = typeof a_results[i] === 'object' ? a_results[i].name : a_results[i]; 
    35473546        li = document.createElement('LI'); 
    35483547        li.innerHTML = text.replace(new RegExp('('+RegExp.escape(s_val)+')', 'ig'), '##$1%%').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/##([^%]+)%%/g, '<b>$1</b>'); 
     
    44964495  { 
    44974496    for (var cmd in this.buttons) { 
    4498       if (typeof cmd != 'string') 
     4497      if (typeof cmd !== 'string') 
    44994498        continue; 
    45004499 
     
    45574556      } 
    45584557      // set class name according to button state 
    4559       else if (obj && typeof(button[state])!='undefined') { 
     4558      else if (obj && button[state] !== undefined) { 
    45604559        button.status = state; 
    45614560        obj.className = button[state]; 
     
    47524751 
    47534752    // Hide message by object, don't use for 'loading'! 
    4754     if (typeof(obj) == 'object') { 
     4753    if (typeof obj === 'object') { 
    47554754      $(obj)[fade?'fadeOut':'hide'](); 
    47564755      msg = $(obj).data('key'); 
     
    48984897  { 
    48994898    if (content && this.gui_objects.quotadisplay) { 
    4900       if (typeof(content) == 'object' && content.type == 'image') 
     4899      if (typeof content === 'object' && content.type == 'image') 
    49014900        this.percent_indicator(this.gui_objects.quotadisplay, content); 
    49024901      else 
     
    51265125  this.url = function(action, query) 
    51275126  { 
    5128     var querystring = typeof(query) == 'string' ? '&' + query : ''; 
    5129      
    5130     if (typeof action != 'string') 
     5127    var querystring = typeof query === 'string' ? '&' + query : ''; 
     5128 
     5129    if (typeof action !== 'string') 
    51315130      query = action; 
    5132     else if (!query || typeof(query) != 'object') 
     5131    else if (!query || typeof query !== 'object') 
    51335132      query = {}; 
    5134      
     5133 
    51355134    if (action) 
    51365135      query._action = action; 
    51375136    else 
    51385137      query._action = this.env.action; 
    5139      
     5138 
    51405139    var base = this.env.comm_path; 
    51415140 
     
    51455144      base = base.replace(/\_task=[a-z]+/, '_task='+RegExp.$1); 
    51465145    } 
    5147      
     5146 
    51485147    // remove undefined values 
    51495148    var param = {}; 
    51505149    for (var k in query) { 
    5151       if (typeof(query[k]) != 'undefined' && query[k] !== null) 
     5150      if (query[k] !== undefined && query[k] !== null) 
    51525151        param[k] = query[k]; 
    51535152    } 
    5154      
     5153 
    51555154    return base + '&' + $.param(param) + querystring; 
    51565155  }; 
     
    51805179    var result = this.triggerEvent('request'+action, query); 
    51815180 
    5182     if (typeof result != 'undefined') { 
     5181    if (result !== undefined) { 
    51835182      // abort if one the handlers returned false 
    51845183      if (result === false) 
     
    52045203    var url = this.url(action); 
    52055204 
    5206     if (postdata && typeof(postdata) == 'object') { 
     5205    if (postdata && typeof postdata === 'object') { 
    52075206      postdata._remote = 1; 
    52085207      postdata._unlock = (lock ? lock : 0); 
     
    52135212    // trigger plugin hook 
    52145213    var result = this.triggerEvent('request'+action, postdata); 
    5215     if (typeof result != 'undefined') { 
     5214    if (result !== undefined) { 
    52165215      // abort if one the handlers returned false 
    52175216      if (result === false) 
     
    52475246 
    52485247    // we have labels to add 
    5249     if (typeof response.texts == 'object') { 
     5248    if (typeof response.texts === 'object') { 
    52505249      for (var name in response.texts) 
    5251         if (typeof response.texts[name] == 'string') 
     5250        if (typeof response.texts[name] === 'string') 
    52525251          this.add_label(name, response.texts[name]); 
    52535252    } 
     
    54455444  this.get_caret_pos = function(obj) 
    54465445  { 
    5447     if (typeof(obj.selectionEnd)!='undefined') 
     5446    if (obj.selectionEnd !== undefined) 
    54485447      return obj.selectionEnd; 
    54495448    else if (document.selection && document.selection.createRange) { 
Note: See TracChangeset for help on using the changeset viewer.