Changeset 3793 in subversion


Ignore:
Timestamp:
Jun 30, 2010 4:40:39 AM (3 years ago)
Author:
alec
Message:
  • Resize editor after switching to html mode
  • create toggle-editor command in app.js, to make possible binding to this command
  • Code cleanup in rcmail_ui (moved compose-related functions into rcmail_ui)
Location:
trunk/roundcubemail
Files:
4 edited

Legend:

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

    r3792 r3793  
    226226        } 
    227227        else if (this.env.action == 'compose') { 
    228           this.enable_command('send-attachment', 'remove-attachment', 'send', true); 
     228          this.enable_command('send-attachment', 'remove-attachment', 'send', 'toggle-editor', true); 
    229229 
    230230          if (this.env.spellcheck) { 
     
    322322        else if (this.env.action=='edit-identity' || this.env.action=='add-identity') { 
    323323          this.enable_command('add', this.env.identities_level < 2); 
    324           this.enable_command('save', 'delete', 'edit', true); 
     324          this.enable_command('save', 'delete', 'edit', 'toggle-editor', true); 
    325325        } 
    326326        else if (this.env.action=='folders') 
     
    979979      default: 
    980980        var func = command.replace('-', '_'); 
    981         alert(func); 
    982981        if (this[func] && typeof this[func] == 'function') 
    983982          this[func](props); 
     
    28092808  }; 
    28102809 
     2810  this.toggle_editor = function(props) 
     2811  { 
     2812    if (props.mode == 'html') { 
     2813      this.display_spellcheck_controls(false); 
     2814      this.plain2html($('#'+props.id).val(), props.id); 
     2815      tinyMCE.execCommand('mceAddControl', false, props.id); 
     2816    } 
     2817    else { 
     2818      var thisMCE = tinyMCE.get(props.id), 
     2819        existingHtml = thisMCE.getContent(); 
     2820 
     2821      if (existingHtml) { 
     2822        if (!confirm(this.get_label('editorwarning'))) { 
     2823          return false; 
     2824            } 
     2825        this.html2plain(existingHtml, props.id); 
     2826      } 
     2827      tinyMCE.execCommand('mceRemoveControl', false, props.id); 
     2828      this.display_spellcheck_controls(true); 
     2829    } 
     2830 
     2831    return true; 
     2832  }; 
     2833 
    28112834  this.stop_spellchecking = function() 
    28122835  { 
     
    51175140rcube_webmail.prototype.removeEventListener = rcube_event_engine.prototype.removeEventListener; 
    51185141rcube_webmail.prototype.triggerEvent = rcube_event_engine.prototype.triggerEvent; 
     5142 
  • trunk/roundcubemail/program/js/editor.js

    r3789 r3793  
    9696function rcmail_toggle_editor(select, textAreaId, flagElement) 
    9797{ 
    98   var composeElement = document.getElementById(textAreaId); 
    9998  var flag, ishtml; 
    10099 
     
    104103    ishtml = select.value == 'html'; 
    105104 
     105  var res = rcmail.command('toggle-editor', {id:textAreaId, mode:ishtml?'html':'plain'}); 
     106 
    106107  if (ishtml) { 
    107     rcmail.display_spellcheck_controls(false); 
    108  
    109     rcmail.plain2html(composeElement.value, textAreaId); 
    110     tinyMCE.execCommand('mceAddControl', false, textAreaId); 
    111108    // #1486593 
    112109    setTimeout("rcmail_editor_tabindex();", 500); 
     
    115112  } 
    116113  else { 
    117     var thisMCE = tinyMCE.get(textAreaId); 
    118     var existingHtml = thisMCE.getContent(); 
    119  
    120     if (existingHtml) { 
    121       if (!confirm(rcmail.get_label('editorwarning'))) { 
    122         if (select.tagName == 'SELECT') 
    123               select.value = 'html'; 
    124         return false; 
    125           } 
    126  
    127       rcmail.html2plain(existingHtml, textAreaId); 
    128     } 
    129  
    130     tinyMCE.execCommand('mceRemoveControl', false, textAreaId); 
    131     rcmail.display_spellcheck_controls(true); 
     114    if (!res && select.tagName == 'SELECT') 
     115          select.value = 'html'; 
    132116    if (flagElement && (flag = rcube_find_object(flagElement))) 
    133117      flag.value = '0'; 
  • trunk/roundcubemail/skins/default/functions.js

    r3789 r3793  
    2323 
    2424/** 
    25  * Mail Composing 
    26  */ 
    27  
    28 function rcmail_show_header_form(id) 
    29 { 
    30   var row, s, 
    31     link = document.getElementById(id + '-link'); 
    32  
    33   if ((s = rcmail_next_sibling(link))) 
    34     s.style.display = 'none'; 
    35   else if ((s = rcmail_prev_sibling(link))) 
    36     s.style.display = 'none'; 
    37      
    38   link.style.display = 'none'; 
    39  
    40   if ((row = document.getElementById('compose-' + id))) { 
    41     var div = document.getElementById('compose-div'), 
    42       headers_div = document.getElementById('compose-headers-div'); 
    43     row.style.display = (document.all && !window.opera) ? 'block' : 'table-row'; 
    44     div.style.top = (parseInt(headers_div.offsetHeight, 10) + 1) + 'px'; 
    45     rcmail_resize_compose_body(); 
    46   } 
    47  
    48   return false; 
    49 } 
    50  
    51 function rcmail_hide_header_form(id) 
    52 { 
    53   var row, ns, 
    54     link = document.getElementById(id + '-link'), 
    55     parent = link.parentNode, 
    56     links = parent.getElementsByTagName('a'); 
    57  
    58   link.style.display = ''; 
    59  
    60   for (var i=0; i<links.length; i++) 
    61     if (links[i].style.display != 'none') 
    62       for (var j=i+1; j<links.length; j++) 
    63             if (links[j].style.display != 'none') 
    64           if ((ns = rcmail_next_sibling(links[i]))) { 
    65                 ns.style.display = ''; 
    66                 break; 
    67               } 
    68  
    69   document.getElementById('_' + id).value = ''; 
    70  
    71   if ((row = document.getElementById('compose-' + id))) { 
    72     var div = document.getElementById('compose-div'), 
    73       headers_div = document.getElementById('compose-headers-div'); 
    74     row.style.display = 'none'; 
    75     div.style.top = (parseInt(headers_div.offsetHeight, 10) + 1) + 'px'; 
    76     rcmail_resize_compose_body(); 
    77   } 
    78  
    79   return false; 
    80 } 
    81  
    82 function rcmail_next_sibling(elm) 
    83 { 
    84   var ns = elm.nextSibling; 
    85   while (ns && ns.nodeType == 3) 
    86     ns = ns.nextSibling; 
    87   return ns; 
    88 } 
    89  
    90 function rcmail_prev_sibling(elm) 
    91 { 
    92   var ps = elm.previousSibling; 
    93   while (ps && ps.nodeType == 3) 
    94     ps = ps.previousSibling; 
    95   return ps; 
    96 } 
    97  
    98 function rcmail_init_compose_form() 
    99 { 
    100   var cc_field = document.getElementById('_cc'), 
    101     bcc_field = document.getElementById('_bcc'), 
    102     div = document.getElementById('compose-div'), 
    103     headers_div = document.getElementById('compose-headers-div'); 
    104  
    105   if (cc_field && cc_field.value != '') 
    106     rcmail_show_header_form('cc'); 
    107  
    108   if (bcc_field && bcc_field.value != '') 
    109     rcmail_show_header_form('bcc'); 
    110  
    111   // prevent from form data loss when pressing ESC key in IE 
    112   if (bw.ie) { 
    113     var form = rcube_find_object('form'); 
    114     form.onkeydown = function (e) { 
    115       if (rcube_event.get_keycode(e) == 27) 
    116         rcube_event.cancel(e); 
    117     }; 
    118   } 
    119  
    120   $(window).resize(function() { 
    121     rcmail_resize_compose_body(); 
    122   }); 
    123  
    124   $('#compose-container').resize(function() { 
    125     rcmail_resize_compose_body(); 
    126   }); 
    127  
    128   div.style.top = (parseInt(headers_div.offsetHeight, 10) + 1) + 'px'; 
    129   $(window).resize(); 
    130 } 
    131  
    132 function rcmail_resize_compose_body(elem) 
    133 { 
    134   var ed, div = $('#compose-div'), w = div.width(), h = div.height(); 
    135   w = w-4; 
    136   h = h-25; 
    137  
    138   $('#compose-body').width(w-(bw.ie || bw.opera || bw.safari ? 2 : 0)+'px').height(h+'px'); 
    139  
    140   if (window.tinyMCE && tinyMCE.get('compose-body')) { 
    141     $('#compose-body_tbl').width((w+4)+'px').height(''); 
    142     $('#compose-body_ifr').width((w+2)+'px').height((h-54)+'px'); 
    143   } 
    144 } 
    145  
    146 /** 
    147  * Mailbox view 
     25 * Mail UI 
    14826 */ 
    14927 
     
    16139    uploadform:'attachment-form' 
    16240  }; 
    163    
     41 
    16442  var obj; 
    16543  for (var k in this.popupmenus) { 
     
    18260    obj.css({ left:pos.left, top:(pos.top + (above ? -obj.height() : ref.offsetHeight)) }); 
    18361  } 
    184    
     62 
    18563  obj[show?'show':'hide'](); 
    18664}, 
     
    239117  this.searchmenu[show?'show':'hide'](); 
    240118}, 
    241   
     119 
    242120set_searchmod: function(elem) 
    243121{ 
    244122  if (!rcmail.env.search_mods) 
    245123    rcmail.env.search_mods = {}; 
    246    
     124 
    247125  if (!rcmail.env.search_mods[rcmail.env.mailbox]) 
    248126    rcmail.env.search_mods[rcmail.env.mailbox] = rcube_clone_object(rcmail.env.search_mods['*']); 
    249    
     127 
    250128  if (!elem.checked) 
    251129    delete(rcmail.env.search_mods[rcmail.env.mailbox][elem.value]); 
     
    418296    rcmail.http_post('save-pref', '_name=preview_pane&_value=0'); 
    419297  } 
     298}, 
     299 
     300/* Message composing */ 
     301init_compose_form: function() 
     302{ 
     303  var cc_field = document.getElementById('_cc'), 
     304    bcc_field = document.getElementById('_bcc'), 
     305    div = document.getElementById('compose-div'), 
     306    headers_div = document.getElementById('compose-headers-div'); 
     307 
     308  if (cc_field && cc_field.value != '') 
     309    rcmail_show_header_form('cc'); 
     310 
     311  if (bcc_field && bcc_field.value != '') 
     312    rcmail_show_header_form('bcc'); 
     313 
     314  // prevent from form data loss when pressing ESC key in IE 
     315  if (bw.ie) { 
     316    var form = rcube_find_object('form'); 
     317    form.onkeydown = function (e) { 
     318      if (rcube_event.get_keycode(e) == 27) 
     319        rcube_event.cancel(e); 
     320    }; 
     321  } 
     322 
     323  $(window).resize(function() { 
     324    rcmail_ui.resize_compose_body(); 
     325  }); 
     326 
     327  $('#compose-container').resize(function() { 
     328    rcmail_ui.resize_compose_body(); 
     329  }); 
     330 
     331  div.style.top = (parseInt(headers_div.offsetHeight, 10) + 1) + 'px'; 
     332  $(window).resize(); 
     333}, 
     334 
     335resize_compose_body: function() 
     336{ 
     337  var ed, div = $('#compose-div'), w = div.width(), h = div.height(); 
     338  w = w-4; 
     339  h = h-25; 
     340 
     341  $('#compose-body').width(w-(bw.ie || bw.opera || bw.safari ? 2 : 0)+'px').height(h+'px'); 
     342 
     343  if (window.tinyMCE && tinyMCE.get('compose-body')) { 
     344    $('#compose-body_tbl').width((w+4)+'px').height(''); 
     345    $('#compose-body_ifr').width((w+2)+'px').height((h-54)+'px'); 
     346  } 
     347}, 
     348 
     349show_header_form: function(id) 
     350{ 
     351  var row, s, 
     352    link = document.getElementById(id + '-link'); 
     353 
     354  if ((s = this.next_sibling(link))) 
     355    s.style.display = 'none'; 
     356  else if ((s = this.prev_sibling(link))) 
     357    s.style.display = 'none'; 
     358 
     359  link.style.display = 'none'; 
     360 
     361  if ((row = document.getElementById('compose-' + id))) { 
     362    var div = document.getElementById('compose-div'), 
     363      headers_div = document.getElementById('compose-headers-div'); 
     364    row.style.display = (document.all && !window.opera) ? 'block' : 'table-row'; 
     365    div.style.top = (parseInt(headers_div.offsetHeight, 10) + 1) + 'px'; 
     366    this.resize_compose_body(); 
     367  } 
     368 
     369  return false; 
     370}, 
     371 
     372hide_header_form: function(id) 
     373{ 
     374  var row, ns, 
     375    link = document.getElementById(id + '-link'), 
     376    parent = link.parentNode, 
     377    links = parent.getElementsByTagName('a'); 
     378 
     379  link.style.display = ''; 
     380 
     381  for (var i=0; i<links.length; i++) 
     382    if (links[i].style.display != 'none') 
     383      for (var j=i+1; j<links.length; j++) 
     384            if (links[j].style.display != 'none') 
     385          if ((ns = this.next_sibling(links[i]))) { 
     386                ns.style.display = ''; 
     387                break; 
     388              } 
     389 
     390  document.getElementById('_' + id).value = ''; 
     391 
     392  if ((row = document.getElementById('compose-' + id))) { 
     393    var div = document.getElementById('compose-div'), 
     394      headers_div = document.getElementById('compose-headers-div'); 
     395    row.style.display = 'none'; 
     396    div.style.top = (parseInt(headers_div.offsetHeight, 10) + 1) + 'px'; 
     397    this.resize_compose_body(); 
     398  } 
     399 
     400  return false; 
     401}, 
     402 
     403next_sibling: function(elm) 
     404{ 
     405  var ns = elm.nextSibling; 
     406  while (ns && ns.nodeType == 3) 
     407    ns = ns.nextSibling; 
     408  return ns; 
     409}, 
     410 
     411prev_sibling: function(elm) 
     412{ 
     413  var ps = elm.previousSibling; 
     414  while (ps && ps.nodeType == 3) 
     415    ps = ps.previousSibling; 
     416  return ps; 
    420417} 
    421418 
    422419}; 
     420 
    423421 
    424422var rcmail_ui; 
     
    437435    rcmail.addEventListener('menu-save', 'save_listmenu', rcmail_ui); 
    438436    rcmail.addEventListener('aftersend-attachment', 'show_uploadform', rcmail_ui); 
     437    rcmail.addEventListener('aftertoggle-editor', 'resize_compose_body', rcmail_ui); 
    439438    rcmail.gui_object('message_dragmenu', 'dragmessagemenu'); 
     439 
     440    if (rcmail.env.action == 'compose') 
     441      rcmail_ui.init_compose_form(); 
    440442  } 
    441443} 
  • trunk/roundcubemail/skins/default/templates/compose.html

    r3789 r3793  
    1414</style> 
    1515</head> 
    16 <body onload="rcmail_init_compose_form(); rcube_init_mail_ui()"> 
     16<body onload="rcube_init_mail_ui()"> 
    1717 
    1818<roundcube:include file="/includes/taskbar.html" /> 
     
    5656            </td> 
    5757            <td id="formlinks"> 
    58                         <a href="#cc" onclick="return rcmail_show_header_form('cc')" id="cc-link"><roundcube:label name="addcc" /></a> 
     58                        <a href="#cc" onclick="return rcmail_ui.show_header_form('cc')" id="cc-link"><roundcube:label name="addcc" /></a> 
    5959                        <span class="separator">|</span> 
    60                         <a href="#bcc" onclick="return rcmail_show_header_form('bcc')" id="bcc-link"><roundcube:label name="addbcc" /></a> 
     60                        <a href="#bcc" onclick="return rcmail_ui.show_header_form('bcc')" id="bcc-link"><roundcube:label name="addbcc" /></a> 
    6161                        <span class="separator">|</span> 
    62                         <a href="#reply-to" onclick="return rcmail_show_header_form('replyto')" id="replyto-link"><roundcube:label name="addreplyto" /></a> 
     62                        <a href="#reply-to" onclick="return rcmail_ui.show_header_form('replyto')" id="replyto-link"><roundcube:label name="addreplyto" /></a> 
    6363            </td> 
    6464            </tr><tr> 
     
    6969            </tr><tr id="compose-cc"> 
    7070                    <td class="title top"> 
    71                 <a href="#cc" onclick="return rcmail_hide_header_form('cc');"><img src="/images/icons/minus.gif" alt="" title="<roundcube:label name='delete' />" /></a> 
     71                <a href="#cc" onclick="return rcmail_ui.hide_header_form('cc');"><img src="/images/icons/minus.gif" alt="" title="<roundcube:label name='delete' />" /></a> 
    7272                        <label for="_cc"><roundcube:label name="cc" /></label> 
    7373            </td> 
     
    7777            </tr><tr id="compose-bcc"> 
    7878                    <td class="title top"> 
    79                 <a href="#bcc" onclick="return rcmail_hide_header_form('bcc');"><img src="/images/icons/minus.gif" alt="" title="<roundcube:label name='delete' />" /></a> 
     79                <a href="#bcc" onclick="return rcmail_ui.hide_header_form('bcc');"><img src="/images/icons/minus.gif" alt="" title="<roundcube:label name='delete' />" /></a> 
    8080                        <label for="_bcc"><roundcube:label name="bcc" /></label> 
    8181            </td> 
     
    8585            </tr><tr id="compose-replyto"> 
    8686                    <td class="title top"> 
    87                 <a href="#replyto" onclick="return rcmail_hide_header_form('replyto');"><img src="/images/icons/minus.gif" alt="" title="<roundcube:label name='delete' />" /></a> 
     87                <a href="#replyto" onclick="return rcmail_ui.hide_header_form('replyto');"><img src="/images/icons/minus.gif" alt="" title="<roundcube:label name='delete' />" /></a> 
    8888                        <label for="_replyto"><roundcube:label name="replyto" /></label> 
    8989            </td> 
Note: See TracChangeset for help on using the changeset viewer.