svncommit
2008-04-15 d9344fc349e8c5765898c90bf5061e56cd21c8a0
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
18 function rcmail_editor_init(skin_path)
2c6337 19   {
d9344f 20   tinyMCE.init({ mode : "textareas",
S 21                  editor_selector : "mce_editor",
2c6337 22                  accessibility_focus : false,
S 23                  apply_source_formatting : true,
d9344f 24                  theme : "advanced",
S 25                  plugins : "emotions,media,nonbreaking,table,searchreplace,spellchecker,visualchars",
26                  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,spellchecker",
27                  theme_advanced_buttons2 : "",
28                  theme_advanced_buttons3 : "",
29                  theme_advanced_toolbar_location : "top",
30                  theme_advanced_toolbar_align : "left",
31                  extended_valid_elements : "font[face|size|color|style],span[id|class|align|style]",
32                  content_css : skin_path + "/editor_content.css",
33                  external_image_list_url : "editor_images.js"
2c6337 34                });
S 35   }
a0109c 36
S 37 // Set the state of the HTML/Plain toggles based on the _is_html field value
38 function rcmail_set_editor_toggle_states()
2c6337 39   {
S 40   // set the editor toggle based on the state of the editor
a0109c 41
2c6337 42   var htmlFlag = document.getElementsByName('_is_html')[0];
S 43   var toggles = document.getElementsByName('_editorSelect');
44   for(var t=0; t<toggles.length; t++)
45     {
46     if (toggles[t].value == 'html')
47       {
48       toggles[t].checked = (htmlFlag.value == "1");
49       }
50     else
51       {
52       toggles[t].checked = (htmlFlag.value == "0");
53       }
a0109c 54     }
2c6337 55   }
a0109c 56
S 57 // Toggle between the HTML and Plain Text editors
58
59 function rcmail_toggle_editor(toggler)
2c6337 60   {
S 61   var selectedEditor = toggler.value;
a0109c 62
2c6337 63   // determine the currently displayed editor
a0109c 64
2c6337 65   var htmlFlag = document.getElementsByName('_is_html')[0];
66f12a 66   var isHtml = htmlFlag.value;
a0109c 67
66f12a 68   if (((selectedEditor == 'plain') && (isHtml == "0")) ||
S 69       ((selectedEditor == 'html') && (isHtml == "1")))
2c6337 70     {
S 71     return;
72     }
a0109c 73
2c6337 74   // do the appropriate conversion
a0109c 75
2c6337 76   var composeElement = document.getElementById('compose-body');
a0109c 77
2c6337 78   if (selectedEditor == 'html')
S 79     {
80     var existingPlainText = composeElement.value;
81     var htmlText = "<pre>" + existingPlainText + "</pre>";
82     composeElement.value = htmlText;
d9344f 83     tinyMCE.execCommand('mceAddControl', true, 'compose-body');
2c6337 84     htmlFlag.value = "1";
S 85     }
86   else
87     {
88     rcmail.set_busy(true, 'converting');
d9344f 89     var thisMCE = tinyMCE.get('compose-body');
S 90     var existingHtml = thisMCE.getContent();
2c6337 91     rcmail_html2plain(existingHtml);
d9344f 92     tinyMCE.execCommand('mceRemoveControl', true, 'compose-body');
2c6337 93     htmlFlag.value = "0";
S 94     }
95   }
a0109c 96
S 97 function rcmail_html2plain(htmlText)
2c6337 98   {
S 99   var http_request = new rcube_http_request();
a0109c 100
2c6337 101   http_request.onerror = function(o) { rcmail_handle_toggle_error(o); };
S 102   http_request.oncomplete = function(o) { rcmail_set_text_value(o); };
809428 103   var url = rcmail.env.bin_path+'html2text.php';
S 104   console.log('HTTP request: ' + url);
2c6337 105   http_request.POST(url, htmlText, 'application/octet-stream');
S 106   }
a0109c 107
S 108 function rcmail_set_text_value(httpRequest)
2c6337 109   {
S 110   rcmail.set_busy(false);
111   var composeElement = document.getElementById('compose-body');
112   composeElement.value = httpRequest.get_text();
113   }
a0109c 114
S 115 function rcmail_handle_toggle_error(httpRequest)
2c6337 116   {
S 117   alert('html2text request returned with error ' + httpRequest.xmlhttp.status);
118   }