2 +-----------------------------------------------------------------------+
3 | RoundCube editor js library |
5 | This file is part of the RoundCube web development suite |
6 | Copyright (C) 2006, RoundCube Dev, - Switzerland |
7 | Licensed under the GNU GPL |
9 +-----------------------------------------------------------------------+
10 | Author: Eric Stadtherr <estadtherr@gmail.com> |
11 +-----------------------------------------------------------------------+
13 $Id: editor.js 000 2006-05-18 19:12:28Z roundcube $
16 // Initialize the message editor
18 function rcmail_editor_init(skin_path, editor_lang)
20 tinyMCE.init({ mode : "textareas",
21 editor_selector : "mce_editor",
22 accessibility_focus : false,
23 apply_source_formatting : true,
25 language : editor_lang,
26 plugins : "emotions,media,nonbreaking,table,searchreplace,visualchars,directionality",
27 theme_advanced_buttons1 : "bold,italic,underline,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,outdent,indent,separator,link,unlink,emotions,charmap,code,forecolor,backcolor,fontselect,fontsizeselect, separator,undo,redo,image,media,ltr,rtl",
28 theme_advanced_buttons2 : "",
29 theme_advanced_buttons3 : "",
30 theme_advanced_toolbar_location : "top",
31 theme_advanced_toolbar_align : "left",
32 extended_valid_elements : "font[face|size|color|style],span[id|class|align|style]",
33 content_css : skin_path + "/editor_content.css",
34 external_image_list_url : "editor_images.js"
38 // Toggle between the HTML and Plain Text editors
40 function rcmail_toggle_editor(toggler)
42 var selectedEditor = toggler.value;
44 // determine the currently displayed editor
45 var htmlFlag = document.getElementsByName('_is_html')[0];
46 var isHtml = htmlFlag.value;
48 if (((selectedEditor == 'plain') && (isHtml == "0")) ||
49 ((selectedEditor == 'html') && (isHtml == "1")))
54 // do the appropriate conversion
56 var composeElement = document.getElementById('compose-body');
58 if (selectedEditor == 'html')
60 var existingPlainText = composeElement.value;
61 var htmlText = "<pre>" + existingPlainText + "</pre>";
62 composeElement.value = htmlText;
63 tinyMCE.execCommand('mceAddControl', true, 'compose-body');
68 rcmail.set_busy(true, 'converting');
69 var thisMCE = tinyMCE.get('compose-body');
70 var existingHtml = thisMCE.getContent();
71 rcmail_html2plain(existingHtml);
72 tinyMCE.execCommand('mceRemoveControl', true, 'compose-body');
77 function rcmail_html2plain(htmlText)
79 var http_request = new rcube_http_request();
81 http_request.onerror = function(o) { rcmail_handle_toggle_error(o); };
82 http_request.oncomplete = function(o) { rcmail_set_text_value(o); };
83 var url = rcmail.env.bin_path+'html2text.php';
84 console.log('HTTP request: ' + url);
85 http_request.POST(url, htmlText, 'application/octet-stream');
88 function rcmail_set_text_value(httpRequest)
90 rcmail.set_busy(false);
91 var composeElement = document.getElementById('compose-body');
92 composeElement.value = httpRequest.get_text();
95 function rcmail_handle_toggle_error(httpRequest)
97 alert('html2text request returned with error ' + httpRequest.xmlhttp.status);