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 |
{ |
S |
20 |
tinyMCE.init({ mode : 'specific_textareas', |
|
21 |
accessibility_focus : false, |
|
22 |
apply_source_formatting : true, |
|
23 |
theme : 'advanced', |
|
24 |
plugins : 'emotions,media,nonbreaking,table,searchreplace,spellchecker,visualchars', |
|
25 |
theme_advanced_buttons1 : 'bold,italic,underline,strikethrough,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,outdent,indent,separator,link,unlink,emotions,forecolor,backcolor,formatselect,fontselect,fontsizeselect', |
|
26 |
theme_advanced_buttons2 : 'undo,redo,image,media,hr,charmap,code,nonbreaking,visualchars,separator,search,replace,spellchecker,separator,tablecontrols', |
|
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', |
4315b0
|
32 |
editor_css : skin_path + '/editor_ui.css', |
S |
33 |
external_image_list_url : 'program/js/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]; |
S |
66 |
var currentEditor = htmlFlag.value; |
a0109c
|
67 |
|
2c6337
|
68 |
if (selectedEditor == currentEditor) |
S |
69 |
{ |
|
70 |
return; |
|
71 |
} |
a0109c
|
72 |
|
2c6337
|
73 |
// do the appropriate conversion |
a0109c
|
74 |
|
2c6337
|
75 |
var composeElement = document.getElementById('compose-body'); |
a0109c
|
76 |
|
2c6337
|
77 |
if (selectedEditor == 'html') |
S |
78 |
{ |
|
79 |
var existingPlainText = composeElement.value; |
|
80 |
var htmlText = "<pre>" + existingPlainText + "</pre>"; |
|
81 |
composeElement.value = htmlText; |
|
82 |
tinyMCE.execCommand('mceAddControl', true, '_message'); |
|
83 |
htmlFlag.value = "1"; |
|
84 |
} |
|
85 |
else |
|
86 |
{ |
|
87 |
rcmail.set_busy(true, 'converting'); |
|
88 |
var thisMCE = tinyMCE.getInstanceById('_message'); |
|
89 |
var existingHtml = tinyMCE.getContent(); |
|
90 |
rcmail_html2plain(existingHtml); |
|
91 |
tinyMCE.execCommand('mceRemoveControl', true, '_message'); |
|
92 |
htmlFlag.value = "0"; |
|
93 |
} |
|
94 |
} |
a0109c
|
95 |
|
S |
96 |
function rcmail_html2plain(htmlText) |
2c6337
|
97 |
{ |
S |
98 |
var http_request = new rcube_http_request(); |
a0109c
|
99 |
|
2c6337
|
100 |
http_request.onerror = function(o) { rcmail_handle_toggle_error(o); }; |
S |
101 |
http_request.oncomplete = function(o) { rcmail_set_text_value(o); }; |
809428
|
102 |
var url = rcmail.env.bin_path+'html2text.php'; |
S |
103 |
console.log('HTTP request: ' + url); |
2c6337
|
104 |
http_request.POST(url, htmlText, 'application/octet-stream'); |
S |
105 |
} |
a0109c
|
106 |
|
S |
107 |
function rcmail_set_text_value(httpRequest) |
2c6337
|
108 |
{ |
S |
109 |
rcmail.set_busy(false); |
|
110 |
var composeElement = document.getElementById('compose-body'); |
|
111 |
composeElement.value = httpRequest.get_text(); |
|
112 |
} |
a0109c
|
113 |
|
S |
114 |
function rcmail_handle_toggle_error(httpRequest) |
2c6337
|
115 |
{ |
S |
116 |
alert('html2text request returned with error ' + httpRequest.xmlhttp.status); |
|
117 |
} |