alecpl
2008-09-12 6d89d65cd87e2bea02146a25265e017b7b85ef90
commit | author | age
a0109c 1 /*
S 2  +-----------------------------------------------------------------------+
3  | RoundCube editor js library                                           |
4  |                                                                       |
5  | This file is part of the RoundCube web development suite              |
6  | Copyright (C) 2006, RoundCube Dev, - Switzerland                      |
7  | Licensed under the GNU GPL                                            |
8  |                                                                       |
9  +-----------------------------------------------------------------------+
10  | Author: Eric Stadtherr <estadtherr@gmail.com>                         |
11  +-----------------------------------------------------------------------+
2c6337 12
a0109c 13  $Id: editor.js 000 2006-05-18 19:12:28Z roundcube $
S 14 */
15
16 // Initialize the message editor
17
4ca10b 18 function rcmail_editor_init(skin_path, editor_lang, spellcheck)
T 19 {
20   tinyMCE.init({ 
21     mode : "textareas",
22     editor_selector : "mce_editor",
23     accessibility_focus : false,
24     apply_source_formatting : true,
25     theme : "advanced",
26     language : editor_lang,
27     plugins : "emotions,media,nonbreaking,table,searchreplace,visualchars,directionality" + (spellcheck ? ",spellchecker" : ""),
28     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" + (spellcheck ? ",spellchecker" : "") + ",undo,redo,image,media,ltr,rtl",
29     theme_advanced_buttons2 : "",
30     theme_advanced_buttons3 : "",
31     theme_advanced_toolbar_location : "top",
32     theme_advanced_toolbar_align : "left",
33     extended_valid_elements : "font[face|size|color|style],span[id|class|align|style]",
34     content_css : skin_path + "/editor_content.css",
35     external_image_list_url : "program/js/editor_images.js",
36     spellchecker_languages : (rcmail.env.spellcheck_langs ? rcmail.env.spellcheck_langs : "Dansk=da,Deutsch=de,+English=en,Espanol=es,Francais=fr,Italiano=it,Nederlands=nl,Polski=pl,Portugues=pt,Suomi=fi,Svenska=sv"),
37     rc_client: rcube_webmail_client
38   });
39 }
a0109c 40
S 41 // Toggle between the HTML and Plain Text editors
42
43 function rcmail_toggle_editor(toggler)
2c6337 44   {
S 45   var selectedEditor = toggler.value;
a0109c 46
2c6337 47   // determine the currently displayed editor
S 48   var htmlFlag = document.getElementsByName('_is_html')[0];
66f12a 49   var isHtml = htmlFlag.value;
a0109c 50
66f12a 51   if (((selectedEditor == 'plain') && (isHtml == "0")) ||
S 52       ((selectedEditor == 'html') && (isHtml == "1")))
2c6337 53     {
S 54     return;
55     }
a0109c 56
2c6337 57   // do the appropriate conversion
a0109c 58
2c6337 59   var composeElement = document.getElementById('compose-body');
a0109c 60
2c6337 61   if (selectedEditor == 'html')
S 62     {
63     var existingPlainText = composeElement.value;
64     var htmlText = "<pre>" + existingPlainText + "</pre>";
65     composeElement.value = htmlText;
d9344f 66     tinyMCE.execCommand('mceAddControl', true, 'compose-body');
2c6337 67     htmlFlag.value = "1";
4ca10b 68     rcmail.display_spellcheck_controls(false);
2c6337 69     }
S 70   else
71     {
72     rcmail.set_busy(true, 'converting');
d9344f 73     var thisMCE = tinyMCE.get('compose-body');
S 74     var existingHtml = thisMCE.getContent();
2c6337 75     rcmail_html2plain(existingHtml);
d9344f 76     tinyMCE.execCommand('mceRemoveControl', true, 'compose-body');
2c6337 77     htmlFlag.value = "0";
4ca10b 78     rcmail.display_spellcheck_controls(true);
2c6337 79     }
S 80   }
a0109c 81
S 82 function rcmail_html2plain(htmlText)
2c6337 83   {
S 84   var http_request = new rcube_http_request();
a0109c 85
2c6337 86   http_request.onerror = function(o) { rcmail_handle_toggle_error(o); };
S 87   http_request.oncomplete = function(o) { rcmail_set_text_value(o); };
809428 88   var url = rcmail.env.bin_path+'html2text.php';
4ca10b 89   //console.log('HTTP request: ' + url);
2c6337 90   http_request.POST(url, htmlText, 'application/octet-stream');
S 91   }
a0109c 92
S 93 function rcmail_set_text_value(httpRequest)
2c6337 94   {
S 95   rcmail.set_busy(false);
96   var composeElement = document.getElementById('compose-body');
97   composeElement.value = httpRequest.get_text();
98   }
a0109c 99
S 100 function rcmail_handle_toggle_error(httpRequest)
2c6337 101   {
S 102   alert('html2text request returned with error ' + httpRequest.xmlhttp.status);
103   }