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)
20 tinyMCE.init({ mode : 'specific_textareas',
21 accessibility_focus : false,
22 apply_source_formatting : true,
24 plugins : 'emotions,media,nonbreaking,table,searchreplace,spellchecker,visualchars',
25 theme_advanced_buttons1 : 'bold,italic,underline,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,outdent,indent,separator,emotions,charmap,code,forecolor,backcolor,fontselect,fontsizeselect, separator,undo,redo,image,media',
26 theme_advanced_buttons2 : '',
27 theme_advanced_buttons3 : '',
28 theme_advanced_toolbar_location : 'top',
29 theme_advanced_toolbar_align : 'left',
30 extended_valid_elements : 'font[face|size|color|style],span[id|class|align|style]',
31 content_css : skin_path + '/editor_content.css',
32 editor_css : skin_path + '/editor_ui.css',
33 external_image_list_url : 'program/js/editor_images.js'
37 // Set the state of the HTML/Plain toggles based on the _is_html field value
38 function rcmail_set_editor_toggle_states()
40 // set the editor toggle based on the state of the editor
42 var htmlFlag = document.getElementsByName('_is_html')[0];
43 var toggles = document.getElementsByName('_editorSelect');
44 for(var t=0; t<toggles.length; t++)
46 if (toggles[t].value == 'html')
48 toggles[t].checked = (htmlFlag.value == "1");
52 toggles[t].checked = (htmlFlag.value == "0");
57 // Toggle between the HTML and Plain Text editors
59 function rcmail_toggle_editor(toggler)
61 var selectedEditor = toggler.value;
63 // determine the currently displayed editor
65 var htmlFlag = document.getElementsByName('_is_html')[0];
66 var isHtml = htmlFlag.value;
68 if (((selectedEditor == 'plain') && (isHtml == "0")) ||
69 ((selectedEditor == 'html') && (isHtml == "1")))
74 // do the appropriate conversion
76 var composeElement = document.getElementById('compose-body');
78 if (selectedEditor == 'html')
80 var existingPlainText = composeElement.value;
81 var htmlText = "<pre>" + existingPlainText + "</pre>";
82 composeElement.value = htmlText;
83 tinyMCE.execCommand('mceAddControl', true, '_message');
88 rcmail.set_busy(true, 'converting');
89 var thisMCE = tinyMCE.getInstanceById('_message');
90 var existingHtml = tinyMCE.getContent();
91 rcmail_html2plain(existingHtml);
92 tinyMCE.execCommand('mceRemoveControl', true, '_message');
97 function rcmail_html2plain(htmlText)
99 var http_request = new rcube_http_request();
101 http_request.onerror = function(o) { rcmail_handle_toggle_error(o); };
102 http_request.oncomplete = function(o) { rcmail_set_text_value(o); };
103 var url = rcmail.env.bin_path+'html2text.php';
104 console.log('HTTP request: ' + url);
105 http_request.POST(url, htmlText, 'application/octet-stream');
108 function rcmail_set_text_value(httpRequest)
110 rcmail.set_busy(false);
111 var composeElement = document.getElementById('compose-body');
112 composeElement.value = httpRequest.get_text();
115 function rcmail_handle_toggle_error(httpRequest)
117 alert('html2text request returned with error ' + httpRequest.xmlhttp.status);