Changeset 2275 in subversion


Ignore:
Timestamp:
Feb 6, 2009 8:54:21 AM (4 years ago)
Author:
thomasb
Message:

Add event system to rcmail app + (almost) get rid of rcube_layer

Location:
branches/devel-api
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-api/program/js/app.js

    r2265 r2275  
    1111 |          Charles McNulty <charles@charlesmcnulty.com>                 | 
    1212 +-----------------------------------------------------------------------+ 
    13  | Requires: common.js, list.js                                          | 
     13 | Requires: jquery.js, common.js, list.js                               | 
    1414 +-----------------------------------------------------------------------+ 
    1515 
     
    1919 
    2020function rcube_webmail() 
    21   { 
     21{ 
    2222  this.env = new Object(); 
    2323  this.labels = new Object(); 
     
    120120  // execute the given script on load 
    121121  this.add_onload = function(f) 
    122     { 
    123       this.onloads[this.onloads.length] = f; 
    124     }; 
     122  { 
     123    this.onloads[this.onloads.length] = f; 
     124  }; 
    125125 
    126126  // initialize webmail client 
     
    524524      return ret !== null ? ret : (obj ? false : true); 
    525525    } 
     526     
     527    // trigger plugin hook 
     528    var event_ret = this.triggerEvent('before'+command, props); 
     529    if (typeof event_ret != 'undefined') { 
     530      // abort if one the handlers returned false 
     531      if (event_ret === false) 
     532        return false; 
     533      else 
     534        props = event_ret; 
     535    } 
    526536 
    527537    // process internal command 
     
    535545      case 'logout': 
    536546        this.goto_url('logout', '', true); 
    537         break;       
     547        break; 
    538548 
    539549      // commands to switch task 
     
    10851095 
    10861096      } 
     1097       
     1098    this.triggerEvent('after'+command, props); 
    10871099 
    10881100    return obj ? false : true; 
     
    11801192  this.doc_mouse_up = function(e) 
    11811193  { 
    1182     var model, li; 
     1194    var model, list, li; 
    11831195     
    11841196    if (this.message_list) { 
    11851197      this.message_list.blur(); 
     1198      list = this.message_list; 
    11861199      model = this.env.mailboxes; 
    11871200    } 
    11881201    else if (this.contact_list) { 
    11891202      this.contact_list.blur(); 
     1203      list = this.contact_list; 
    11901204      model = this.env.address_sources; 
    11911205    } 
     
    11991213      this.command('moveto', model[this.env.last_folder_target].id); 
    12001214      this.env.last_folder_target = null; 
     1215      list.draglayer.hide(); 
    12011216    } 
    12021217  }; 
     
    12541269          this.env.last_folder_target = k; 
    12551270        } 
    1256         else 
     1271        else { 
    12571272          $(this.get_folder_li(k)).removeClass('droptarget'); 
     1273          this.env.last_folder_target = null; 
     1274        } 
    12581275      } 
    12591276    } 
     
    24182435        highlight = document.getElementById('rcmksearchSelected'); 
    24192436        if (!highlight) 
    2420           highlight = this.ksearch_pane.ul.firstChild; 
     2437          highlight = this.ksearch_pane.__ul.firstChild; 
    24212438         
    24222439        if (highlight) 
     
    24942511      return; 
    24952512       
    2496     if (this.ksearch_pane && this.ksearch_pane.visible) 
    2497       this.ksearch_pane.show(0); 
     2513    if (this.ksearch_pane && this.ksearch_pane.is(":visible")) 
     2514      this.ksearch_pane.hide(); 
    24982515 
    24992516    // get string from current cursor pos to last comma 
     
    25392556      // create results pane if not present 
    25402557      if (!this.ksearch_pane) { 
    2541         ul = document.createElement('UL'); 
    2542         this.ksearch_pane = new rcube_layer('rcmKSearchpane', {vis:0, zindex:30000}); 
    2543         this.ksearch_pane.elm.appendChild(ul); 
    2544         this.ksearch_pane.ul = ul; 
    2545       } 
    2546       else 
    2547         ul = this.ksearch_pane.ul; 
     2558        ul = $('<ul>'); 
     2559        this.ksearch_pane = $('<div>').attr('id', 'rcmKSearchpane').css({ position:'absolute', 'z-index':30000 }).append(ul).appendTo(document.body); 
     2560        this.ksearch_pane.__ul = ul[0]; 
     2561      } 
    25482562 
    25492563      // remove all search results 
     2564      ul = this.ksearch_pane.__ul; 
    25502565      ul.innerHTML = ''; 
    25512566             
     
    25782593      // move the results pane right under the input box and make it visible 
    25792594      var pos = $(this.ksearch_input).offset(); 
    2580       this.ksearch_pane.move(pos.left, pos.top + this.ksearch_input.offsetHeight); 
    2581       this.ksearch_pane.show(1); 
     2595      this.ksearch_pane.css({ left:pos.left+'px', top:(pos.top + this.ksearch_input.offsetHeight)+'px' }).show(); 
    25822596    } 
    25832597    // hide results pane 
     
    26122626     
    26132627    if (this.ksearch_pane) 
    2614       this.ksearch_pane.show(0); 
     2628      this.ksearch_pane.hide(); 
    26152629    }; 
    26162630 
     
    39653979    }; 
    39663980     
    3967   }  // end object rcube_webmail 
    3968  
     3981}  // end object rcube_webmail 
     3982 
     3983 
     3984// copy event engine prototype 
     3985rcube_webmail.prototype.addEventListener = rcube_event_engine.prototype.addEventListener; 
     3986rcube_webmail.prototype.removeEventListener = rcube_event_engine.prototype.removeEventListener; 
     3987rcube_webmail.prototype.triggerEvent = rcube_event_engine.prototype.triggerEvent; 
     3988 
  • branches/devel-api/program/js/common.js

    r2228 r2275  
    9494 
    9595 
    96 // static functions for event handling 
     96// static functions for DOM event handling 
    9797var rcube_event = { 
    9898 
     
    235235 
    236236 
    237 var rcube_layer_objects = new Array(); 
     237/** 
     238 * rcmail objects event interface 
     239 */ 
     240function rcube_event_engine() 
     241{ 
     242  this._events = {}; 
     243} 
     244 
     245rcube_event_engine.prototype = { 
     246 
     247/** 
     248 * Setter for object event handlers 
     249 * 
     250 * @param {String}   Event name 
     251 * @param {Function} Handler function 
     252 * @return Listener ID (used to remove this handler later on) 
     253 */ 
     254addEventListener: function(evt, func, obj) 
     255{ 
     256  if (!this._events) 
     257    this._events = {}; 
     258  if (!this._events[evt]) 
     259    this._events[evt] = []; 
     260     
     261  var e = {func:func, obj:obj ? obj : window}; 
     262  this._events[evt][this._events[evt].length] = e; 
     263}, 
     264 
     265/** 
     266 * Removes a specific event listener 
     267 * 
     268 * @param {String} Event name 
     269 * @param {Int}    Listener ID to remove 
     270 */ 
     271removeEventListener: function(evt, func, obj) 
     272{ 
     273  if (typeof obj == 'undefined') 
     274    obj = window; 
     275     
     276  for (var h,i=0; this._events && this._events[evt] && i < this._events[evt].length; i++) 
     277    if ((h = this._events[evt][i]) && h.func == func && h.obj == obj) 
     278      this._events[evt][i] = null; 
     279}, 
     280 
     281/** 
     282 * This will execute all registered event handlers 
     283 * 
     284 * @param {String} Event to trigger 
     285 * @param {Object} Event object/arguments 
     286 */ 
     287triggerEvent: function(evt, e) 
     288{ 
     289  var ret, h; 
     290  if (typeof e == 'undefined') 
     291    e = {}; 
     292  if (typeof e == 'object') 
     293    e.event = evt; 
     294   
     295  if (this._events && this._events[evt] && !this._event_exec) { 
     296    this._event_exec = true; 
     297    for (var i=0; i < this._events[evt].length; i++) { 
     298      if ((h = this._events[evt][i])) { 
     299        if (typeof h.func == 'function') 
     300          ret = h.func.call ? h.func.call(h.obj, this, e) : h.func(this, e); 
     301        else if (typeof h.obj[h.func] == 'function') 
     302          ret = h.obj[h.func](this, e); 
     303               
     304        // cancel event execution 
     305        if (typeof ret != 'undefined' && !ret) 
     306          break; 
     307      } 
     308    } 
     309  } 
     310 
     311  this._event_exec = false; 
     312  return ret; 
     313} 
     314 
     315}  // end rcube_event_engine.prototype 
     316 
    238317 
    239318 
     
    244323 */ 
    245324function rcube_layer(id, attributes) 
    246   { 
     325{ 
    247326  this.name = id; 
    248327   
     
    311390  this.visible = (this.css.visibility=='visible' || this.css.visibility=='show' || this.css.visibility=='inherit') ? true : false; 
    312391 
    313   this.id = rcube_layer_objects.length; 
    314   this.obj = 'rcube_layer_objects['+this.id+']'; 
    315   rcube_layer_objects[this.id] = this; 
    316  
    317392 
    318393  // ********* layer object methods ********* 
     
    328403    } 
    329404 
    330  
    331   // move the layer for a specific step 
    332   this.shift = function(x,y) 
    333     { 
    334     x = Math.round(x*100)/100; 
    335     y = Math.round(y*100)/100; 
    336     this.move(this.x+x, this.y+y); 
    337     } 
    338  
    339  
    340405  // change the layers width and height 
    341406  this.resize = function(w,h) 
     
    345410    this.width = w; 
    346411    this.height = h; 
    347     } 
    348  
    349  
    350   // cut the layer (top,width,height,left) 
    351   this.clip = function(t,w,h,l) 
    352     { 
    353     this.css.clip='rect('+t+' '+w+' '+h+' '+l+')'; 
    354     this.clip_height = h; 
    355     this.clip_width = w; 
    356412    } 
    357413 
     
    384440    } 
    385441 
    386  
    387   // set the given color to the layer background 
    388   this.set_bgcolor = function(c) 
    389     { 
    390     if(!c || c=='#') 
    391       c = 'transparent'; 
    392  
    393     this.css.backgroundColor = c; 
    394     } 
    395  
    396  
    397   // set the opacity of a layer to the given ammount (in %) 
    398   this.set_opacity = function(v) 
    399     { 
    400     if(!bw.opacity) 
    401       return; 
    402  
    403     var op = v<=1 ? Math.round(v*100) : parseInt(v); 
    404  
    405     if(bw.ie) 
    406       this.css.filter = 'alpha(opacity:'+op+')'; 
    407     else if(bw.safari) 
    408       { 
    409       this.css.opacity = op/100; 
    410       this.css.KhtmlOpacity = op/100; 
    411       } 
    412     else if(bw.mz) 
    413       this.css.MozOpacity = op/100; 
    414     } 
    415   } 
     442} 
    416443 
    417444 
  • branches/devel-api/program/js/list.js

    r2260 r2275  
    5252  this.dblclick_time = 600; 
    5353  this.row_init = function(){}; 
    54   this.events = { click:[], dblclick:[], select:[], keypress:[], dragstart:[], dragmove:[], dragend:[] }; 
    5554   
    5655  // overwrite default paramaters 
     
    306305  // row was double clicked 
    307306  if (this.rows && dblclicked && this.in_selection(id)) 
    308     this.trigger_event('dblclick'); 
     307    this.triggerEvent('dblclick'); 
    309308  else 
    310     this.trigger_event('click'); 
     309    this.triggerEvent('click'); 
    311310 
    312311  if (!this.drag_active) 
     
    406405  // trigger event if selection changed 
    407406  if (this.selection.join(',') != select_before) 
    408     this.trigger_event('select'); 
     407    this.triggerEvent('select'); 
    409408 
    410409  if (this.last_selected != 0 && this.rows[this.last_selected]) 
     
    518517  // trigger event if selection changed 
    519518  if (this.selection.join(',') != select_before) 
    520     this.trigger_event('select'); 
     519    this.triggerEvent('select'); 
    521520 
    522521  this.focus(); 
     
    554553 
    555554  if (num_select && !this.selection.length) 
    556     this.trigger_event('select'); 
     555    this.triggerEvent('select'); 
    557556}, 
    558557 
     
    634633      this.shiftkey = e.shiftKey; 
    635634      this.key_pressed = keyCode; 
    636       this.trigger_event('keypress'); 
     635      this.triggerEvent('keypress'); 
    637636       
    638637      if (this.key_pressed == this.BACKSPACE_KEY) 
     
    719718   
    720719    if (!this.draglayer) 
    721       this.draglayer = new rcube_layer('rcmdraglayer', {x:0, y:0, vis:0, zindex:2000}); 
     720      this.draglayer = $('<div>').attr('id', 'rcmdraglayer').css({ position:'absolute', display:'none', 'z-index':2000 }).appendTo(document.body); 
    722721   
    723722    // get subjects of selectedd messages 
     
    734733      if (this.rows[this.selection[n]].obj) 
    735734      { 
     735        if (n == 0) 
     736          this.drag_start_pos = $(this.rows[this.selection[n]].obj).offset(); 
     737         
    736738        obj = this.rows[this.selection[n]].obj; 
    737739        subject = ''; 
     
    754756    } 
    755757 
    756     this.draglayer.write(names); 
    757     this.draglayer.show(1); 
     758    this.draglayer.html(names); 
     759    this.draglayer.show(); 
    758760 
    759761    this.drag_active = true; 
    760     this.trigger_event('dragstart'); 
     762    this.triggerEvent('dragstart'); 
    761763  } 
    762764 
     
    764766  { 
    765767    var pos = rcube_event.get_mouse_pos(e); 
    766     this.draglayer.move(pos.x+20, pos.y-5); 
    767     this.trigger_event('dragmove', e); 
     768    this.draglayer.css({ left:(pos.x+20)+'px', top:(pos.y-5)+'px' }); 
     769    this.triggerEvent('dragmove', e); 
    768770  } 
    769771 
     
    781783  document.onmousemove = null; 
    782784 
    783   if (this.draglayer && this.draglayer.visible) 
    784     this.draglayer.show(0); 
     785  if (this.draglayer && this.draglayer.is(':visible')) { 
     786    if (this.drag_start_pos) 
     787      this.draglayer.animate(this.drag_start_pos, 300, 'swing').hide(20); 
     788    else 
     789      this.draglayer.hide(); 
     790  } 
    785791 
    786792  this.drag_active = false; 
    787   this.trigger_event('dragend'); 
     793  this.triggerEvent('dragend'); 
    788794 
    789795  rcube_event.remove_listener({element:document, event:'mousemove', object:this, method:'drag_mouse_move'}); 
     
    817823   
    818824  return rcube_event.cancel(e); 
    819 }, 
    820  
    821  
    822  
    823 /** 
    824  * Setter for object event handlers 
    825  * 
    826  * @param {String}   Event name 
    827  * @param {Function} Handler function 
    828  * @return Listener ID (used to remove this handler later on) 
    829  */ 
    830 addEventListener: function(evt, handler) 
    831 { 
    832   if (this.events[evt]) { 
    833     var handle = this.events[evt].length; 
    834     this.events[evt][handle] = handler; 
    835     return handle; 
    836   } 
    837   else 
    838     return false; 
    839 }, 
    840  
    841  
    842 /** 
    843  * Removes a specific event listener 
    844  * 
    845  * @param {String} Event name 
    846  * @param {Int}    Listener ID to remove 
    847  */ 
    848 removeEventListener: function(evt, handle) 
    849 { 
    850   if (this.events[evt] && this.events[evt][handle]) 
    851     this.events[evt][handle] = null; 
    852 }, 
    853  
    854  
    855 /** 
    856  * This will execute all registered event handlers 
    857  * @private 
    858  */ 
    859 trigger_event: function(evt, p) 
    860 { 
    861   if (this.events[evt] && this.events[evt].length) { 
    862     for (var i=0; i<this.events[evt].length; i++) 
    863       if (typeof(this.events[evt][i]) == 'function') 
    864         this.events[evt][i](this, p); 
    865   } 
    866825} 
    867826 
    868  
    869827}; 
    870828 
     829rcube_list_widget.prototype.addEventListener = rcube_event_engine.prototype.addEventListener; 
     830rcube_list_widget.prototype.removeEventListener = rcube_event_engine.prototype.removeEventListener; 
     831rcube_list_widget.prototype.triggerEvent = rcube_event_engine.prototype.triggerEvent; 
  • branches/devel-api/skins/default/functions.js

    r2196 r2275  
    129129function rcube_mail_ui() 
    130130{ 
    131   this.markmenu = new rcube_layer('markmessagemenu'); 
     131  this.markmenu = $('#markmessagemenu'); 
    132132} 
    133133 
     
    137137{ 
    138138  if (typeof show == 'undefined') 
    139     show = this.markmenu.visible ? false : true; 
     139    show = this.markmenu.is(':visible') ? false : true; 
    140140   
    141141  var ref = rcube_find_object('markreadbutton'); 
    142142  if (show && ref) 
    143     this.markmenu.move(ref.offsetLeft, ref.offsetTop + ref.offsetHeight); 
     143    this.markmenu.css({ left:ref.offsetLeft, top:(ref.offsetTop + ref.offsetHeight) }); 
    144144   
    145   this.markmenu.show(show); 
     145  this.markmenu[show?'show':'hide'](); 
    146146}, 
    147147 
    148148body_mouseup: function(evt, p) 
    149149{ 
    150   if (this.markmenu && this.markmenu.visible && rcube_event.get_target(evt) != rcube_find_object('markreadbutton')) 
     150  if (this.markmenu && this.markmenu.is(':visible') && rcube_event.get_target(evt) != rcube_find_object('markreadbutton')) 
    151151    this.show_markmenu(false); 
    152152}, 
     
    154154body_keypress: function(evt, p) 
    155155{ 
    156   if (rcube_event.get_keycode(evt) == 27 && this.markmenu && this.markmenu.visible) 
     156  if (rcube_event.get_keycode(evt) == 27 && this.markmenu && this.markmenu.is(':visible')) 
    157157    this.show_markmenu(false); 
    158158} 
  • branches/devel-api/skins/default/mail.css

    r2197 r2275  
    5050  left: 90px; 
    5151  width: auto; 
    52   visibility: hidden; 
     52  display: none; 
    5353  background-color: #F9F9F9; 
    5454  border: 1px solid #CCC; 
Note: See TracChangeset for help on using the changeset viewer.