From 3940ba65be1993c4a2c2be4599f53d3018228783 Mon Sep 17 00:00:00 2001 From: alecpl Date: Wed, 30 Jun 2010 08:40:39 +0000 Subject: [PATCH] - 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) --- program/js/app.js | 30 +++- program/js/editor.js | 24 +-- skins/default/functions.js | 258 ++++++++++++++------------- skins/default/templates/compose.html | 14 +- 4 files changed, 168 insertions(+), 158 deletions(-) diff --git a/program/js/app.js b/program/js/app.js index 3543ed3ce..a3b2b27ac 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -225,7 +225,7 @@ function rcube_webmail() } } else if (this.env.action == 'compose') { - this.enable_command('send-attachment', 'remove-attachment', 'send', true); + this.enable_command('send-attachment', 'remove-attachment', 'send', 'toggle-editor', true); if (this.env.spellcheck) { this.env.spellcheck.spelling_state_observer = function(s){ ref.set_spellcheck_state(s); }; @@ -321,7 +321,7 @@ function rcube_webmail() } else if (this.env.action=='edit-identity' || this.env.action=='add-identity') { this.enable_command('add', this.env.identities_level < 2); - this.enable_command('save', 'delete', 'edit', true); + this.enable_command('save', 'delete', 'edit', 'toggle-editor', true); } else if (this.env.action=='folders') this.enable_command('subscribe', 'unsubscribe', 'create-folder', 'rename-folder', 'delete-folder', 'enable-threading', 'disable-threading', true); @@ -978,7 +978,6 @@ function rcube_webmail() // unified command call (command name == function name) default: var func = command.replace('-', '_'); - alert(func); if (this[func] && typeof this[func] == 'function') this[func](props); break; @@ -2808,6 +2807,30 @@ function rcube_webmail() return true; }; + this.toggle_editor = function(props) + { + if (props.mode == 'html') { + this.display_spellcheck_controls(false); + this.plain2html($('#'+props.id).val(), props.id); + tinyMCE.execCommand('mceAddControl', false, props.id); + } + else { + var thisMCE = tinyMCE.get(props.id), + existingHtml = thisMCE.getContent(); + + if (existingHtml) { + if (!confirm(this.get_label('editorwarning'))) { + return false; + } + this.html2plain(existingHtml, props.id); + } + tinyMCE.execCommand('mceRemoveControl', false, props.id); + this.display_spellcheck_controls(true); + } + + return true; + }; + this.stop_spellchecking = function() { if (this.env.spellcheck && !this.spellcheck_ready) { @@ -5116,3 +5139,4 @@ function rcube_webmail() rcube_webmail.prototype.addEventListener = rcube_event_engine.prototype.addEventListener; rcube_webmail.prototype.removeEventListener = rcube_event_engine.prototype.removeEventListener; rcube_webmail.prototype.triggerEvent = rcube_event_engine.prototype.triggerEvent; + diff --git a/program/js/editor.js b/program/js/editor.js index a5e3af3d5..fd128cb8f 100644 --- a/program/js/editor.js +++ b/program/js/editor.js @@ -95,7 +95,6 @@ function rcmail_editor_tabindex() // switch html/plain mode function rcmail_toggle_editor(select, textAreaId, flagElement) { - var composeElement = document.getElementById(textAreaId); var flag, ishtml; if (select.tagName != 'SELECT') @@ -103,32 +102,17 @@ function rcmail_toggle_editor(select, textAreaId, flagElement) else ishtml = select.value == 'html'; - if (ishtml) { - rcmail.display_spellcheck_controls(false); + var res = rcmail.command('toggle-editor', {id:textAreaId, mode:ishtml?'html':'plain'}); - rcmail.plain2html(composeElement.value, textAreaId); - tinyMCE.execCommand('mceAddControl', false, textAreaId); + if (ishtml) { // #1486593 setTimeout("rcmail_editor_tabindex();", 500); if (flagElement && (flag = rcube_find_object(flagElement))) flag.value = '1'; } else { - var thisMCE = tinyMCE.get(textAreaId); - var existingHtml = thisMCE.getContent(); - - if (existingHtml) { - if (!confirm(rcmail.get_label('editorwarning'))) { - if (select.tagName == 'SELECT') - select.value = 'html'; - return false; - } - - rcmail.html2plain(existingHtml, textAreaId); - } - - tinyMCE.execCommand('mceRemoveControl', false, textAreaId); - rcmail.display_spellcheck_controls(true); + if (!res && select.tagName == 'SELECT') + select.value = 'html'; if (flagElement && (flag = rcube_find_object(flagElement))) flag.value = '0'; } diff --git a/skins/default/functions.js b/skins/default/functions.js index 3a97448ac..258742e69 100644 --- a/skins/default/functions.js +++ b/skins/default/functions.js @@ -22,129 +22,7 @@ function rcube_show_advanced(visible) } /** - * Mail Composing - */ - -function rcmail_show_header_form(id) -{ - var row, s, - link = document.getElementById(id + '-link'); - - if ((s = rcmail_next_sibling(link))) - s.style.display = 'none'; - else if ((s = rcmail_prev_sibling(link))) - s.style.display = 'none'; - - link.style.display = 'none'; - - if ((row = document.getElementById('compose-' + id))) { - var div = document.getElementById('compose-div'), - headers_div = document.getElementById('compose-headers-div'); - row.style.display = (document.all && !window.opera) ? 'block' : 'table-row'; - div.style.top = (parseInt(headers_div.offsetHeight, 10) + 1) + 'px'; - rcmail_resize_compose_body(); - } - - return false; -} - -function rcmail_hide_header_form(id) -{ - var row, ns, - link = document.getElementById(id + '-link'), - parent = link.parentNode, - links = parent.getElementsByTagName('a'); - - link.style.display = ''; - - for (var i=0; i - + @@ -55,11 +55,11 @@ - + | - + | - + @@ -68,7 +68,7 @@ - + @@ -76,7 +76,7 @@ - + @@ -84,7 +84,7 @@ - +