commit | author | age
|
a0109c
|
1 |
/* |
S |
2 |
+-----------------------------------------------------------------------+ |
e019f2
|
3 |
| Roundcube editor js library | |
a0109c
|
4 |
| | |
e019f2
|
5 |
| This file is part of the Roundcube web development suite | |
7fe381
|
6 |
| Copyright (C) 2006-2012, The Roundcube Dev Team | |
T |
7 |
| | |
|
8 |
| Licensed under the GNU General Public License version 3 or | |
|
9 |
| any later version with exceptions for skins & plugins. | |
|
10 |
| See the README file for a full license statement. | |
a0109c
|
11 |
| | |
S |
12 |
+-----------------------------------------------------------------------+ |
|
13 |
| Author: Eric Stadtherr <estadtherr@gmail.com> | |
|
14 |
+-----------------------------------------------------------------------+ |
|
15 |
*/ |
|
16 |
|
b8ae50
|
17 |
// Initialize HTML editor |
66df08
|
18 |
function rcmail_editor_init(config) |
4ca10b
|
19 |
{ |
2d889e
|
20 |
var ret, conf = { |
e0a5ce
|
21 |
mode: 'textareas', |
A |
22 |
editor_selector: 'mce_editor', |
|
23 |
apply_source_formatting: true, |
|
24 |
theme: 'advanced', |
66df08
|
25 |
language: config.lang, |
A |
26 |
content_css: config.skin_path + '/editor_content.css', |
e0a5ce
|
27 |
theme_advanced_toolbar_location: 'top', |
A |
28 |
theme_advanced_toolbar_align: 'left', |
|
29 |
theme_advanced_buttons3: '', |
ea3021
|
30 |
theme_advanced_statusbar_location: 'none', |
2d889e
|
31 |
extended_valid_elements: 'font[face|size|color|style],span[id|class|align|style]', |
e0a5ce
|
32 |
relative_urls: false, |
A |
33 |
remove_script_host: false, |
2d889e
|
34 |
gecko_spellcheck: true, |
A |
35 |
convert_urls: false, // #1486944 |
8f142e
|
36 |
external_image_list: window.rcmail_editor_images, |
2d889e
|
37 |
rc_client: rcmail |
A |
38 |
}; |
|
39 |
|
66df08
|
40 |
if (config.mode == 'identity') |
2d889e
|
41 |
$.extend(conf, { |
A |
42 |
plugins: 'paste,tabfocus', |
|
43 |
theme_advanced_buttons1: 'bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,separator,outdent,indent,charmap,hr,link,unlink,code,forecolor', |
d675ab
|
44 |
theme_advanced_buttons2: 'fontselect,fontsizeselect' |
b8ae50
|
45 |
}); |
4be86f
|
46 |
else { // mail compose |
2d889e
|
47 |
$.extend(conf, { |
5f8d59
|
48 |
plugins: 'paste,emotions,media,nonbreaking,table,searchreplace,visualchars,directionality,inlinepopups,tabfocus' + (config.spellcheck ? ',spellchecker' : ''), |
e0a5ce
|
49 |
theme_advanced_buttons1: 'bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,outdent,indent,ltr,rtl,blockquote,|,forecolor,backcolor,fontselect,fontsizeselect', |
4be86f
|
50 |
theme_advanced_buttons2: 'link,unlink,table,|,emotions,charmap,image,media,|,code,search,undo,redo', |
e0a5ce
|
51 |
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'), |
ec86ad
|
52 |
spellchecker_rpc_url: '?_task=utils&_action=spell_html&_remote=1', |
66df08
|
53 |
spellchecker_enable_learn_rpc: config.spelldict, |
2d889e
|
54 |
accessibility_focus: false, |
e0a5ce
|
55 |
oninit: 'rcmail_editor_callback' |
b8ae50
|
56 |
}); |
2d889e
|
57 |
|
4be86f
|
58 |
// add handler for spellcheck button state update |
A |
59 |
conf.setup = function(ed) { |
|
60 |
ed.onSetProgressState.add(function(ed, active) { |
|
61 |
if (!active) |
|
62 |
rcmail.spellcheck_state(); |
|
63 |
}); |
|
64 |
} |
|
65 |
} |
|
66 |
|
2d889e
|
67 |
// support external configuration settings e.g. from skin |
A |
68 |
if (window.rcmail_editor_settings) |
|
69 |
$.extend(conf, window.rcmail_editor_settings); |
|
70 |
|
|
71 |
tinyMCE.init(conf); |
4ca10b
|
72 |
} |
b8ae50
|
73 |
|
A |
74 |
// react to real individual tinyMCE editor init |
b2f3e6
|
75 |
function rcmail_editor_callback() |
b8ae50
|
76 |
{ |
c288f9
|
77 |
var elem = rcube_find_object('_from'), |
A |
78 |
fe = rcmail.env.compose_focus_elem; |
|
79 |
|
7e263e
|
80 |
if (rcmail.env.default_font) |
A |
81 |
$(tinyMCE.get(rcmail.env.composebody).getBody()).css('font-family', rcmail.env.default_font); |
|
82 |
|
edc49e
|
83 |
if (rcmail.env.default_font_size) |
D |
84 |
$(tinyMCE.get(rcmail.env.composebody).getBody()).css('font-size', rcmail.env.default_font_size); |
|
85 |
|
d3d1e3
|
86 |
if (elem && elem.type == 'select-one') { |
1f019c
|
87 |
rcmail.change_identity(elem); |
882b0f
|
88 |
// Focus previously focused element |
43fb35
|
89 |
if (fe && fe.id != rcmail.env.composebody) { |
ad9dac
|
90 |
// use setTimeout() for IE9 (#1488541) |
AM |
91 |
window.setTimeout(function() { |
|
92 |
window.focus(); // for WebKit (#1486674) |
|
93 |
fe.focus(); |
|
94 |
}, 10); |
43fb35
|
95 |
} |
882b0f
|
96 |
} |
c288f9
|
97 |
|
5cff85
|
98 |
// set tabIndex and set focus to element that was focused before |
c288f9
|
99 |
rcmail_editor_tabindex(fe && fe.id == rcmail.env.composebody); |
eb9eff
|
100 |
// Trigger resize (needed for proper editor resizing in some browsers using default skin) |
A |
101 |
$(window).resize(); |
665cc5
|
102 |
} |
A |
103 |
|
|
104 |
// set tabIndex on tinyMCE editor |
5cff85
|
105 |
function rcmail_editor_tabindex(focus) |
665cc5
|
106 |
{ |
A |
107 |
if (rcmail.env.task == 'mail') { |
a01b3b
|
108 |
var editor = tinyMCE.get(rcmail.env.composebody); |
4cdc70
|
109 |
if (editor) { |
A |
110 |
var textarea = editor.getElement(); |
|
111 |
var node = editor.getContentAreaContainer().childNodes[0]; |
|
112 |
if (textarea && node) |
|
113 |
node.tabIndex = textarea.tabIndex; |
5cff85
|
114 |
if (focus) |
59c404
|
115 |
editor.getBody().focus(); |
4cdc70
|
116 |
} |
665cc5
|
117 |
} |
b8ae50
|
118 |
} |
A |
119 |
|
|
120 |
// switch html/plain mode |
5821ff
|
121 |
function rcmail_toggle_editor(select, textAreaId, flagElement) |
b8ae50
|
122 |
{ |
5821ff
|
123 |
var flag, ishtml; |
A |
124 |
|
|
125 |
if (select.tagName != 'SELECT') |
|
126 |
ishtml = select.checked; |
|
127 |
else |
|
128 |
ishtml = select.value == 'html'; |
b8ae50
|
129 |
|
3940ba
|
130 |
var res = rcmail.command('toggle-editor', {id:textAreaId, mode:ishtml?'html':'plain'}); |
832594
|
131 |
|
3940ba
|
132 |
if (ishtml) { |
4cdc70
|
133 |
// #1486593 |
5cff85
|
134 |
setTimeout("rcmail_editor_tabindex(true);", 500); |
b8ae50
|
135 |
if (flagElement && (flag = rcube_find_object(flagElement))) |
A |
136 |
flag.value = '1'; |
087c7d
|
137 |
} |
14d494
|
138 |
else if (res) { |
b8ae50
|
139 |
if (flagElement && (flag = rcube_find_object(flagElement))) |
A |
140 |
flag.value = '0'; |
5cff85
|
141 |
|
bdf6de
|
142 |
if (rcmail.env.composebody) |
A |
143 |
rcube_find_object(rcmail.env.composebody).focus(); |
087c7d
|
144 |
} |
14d494
|
145 |
else { // !res |
A |
146 |
if (select.tagName == 'SELECT') |
|
147 |
select.value = 'html'; |
|
148 |
else if (select.tagName == 'INPUT') |
|
149 |
select.checked = true; |
|
150 |
} |
087c7d
|
151 |
} |
8f142e
|
152 |
|
A |
153 |
// editor callbeck for images listing |
|
154 |
function rcmail_editor_images() |
|
155 |
{ |
|
156 |
var i, files = rcmail.env.attachments, list = []; |
|
157 |
|
|
158 |
for (i in files) { |
|
159 |
att = files[i]; |
|
160 |
if (att.complete && att.mimetype.indexOf('image/') == 0) { |
|
161 |
list.push([att.name, rcmail.env.comm_path+'&_action=display-attachment&_file='+i+'&_id='+rcmail.env.compose_id]); |
|
162 |
} |
|
163 |
} |
|
164 |
|
|
165 |
return list; |
|
166 |
}; |