]> git.donarmstrong.com Git - roundcube.git/blob - program/js/editor.js
Imported Upstream version 0.3
[roundcube.git] / program / js / editor.js
1 /*
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  +-----------------------------------------------------------------------+
12
13  $Id: editor.js 000 2006-05-18 19:12:28Z roundcube $
14 */
15
16 // Initialize HTML editor
17 function rcmail_editor_init(skin_path, editor_lang, spellcheck, mode)
18 {
19   if (mode == 'identity')
20     tinyMCE.init({
21       mode : 'textareas',
22       editor_selector : 'mce_editor',
23       apply_source_formatting : true,
24       theme : 'advanced',
25       language : editor_lang,
26       content_css : skin_path + '/editor_content.css',
27       theme_advanced_toolbar_location : 'top',
28       theme_advanced_toolbar_align : 'left',
29       theme_advanced_buttons1 : 'bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,separator,outdent,indent,charmap,hr,link,unlink,code,forecolor',
30       theme_advanced_buttons2 : ',fontselect,fontsizeselect',
31       theme_advanced_buttons3 : '',
32       relative_urls : false,
33       remove_script_host : false,
34       gecko_spellcheck : true
35     });
36   else // mail compose
37     tinyMCE.init({ 
38       mode : 'textareas',
39       editor_selector : 'mce_editor',
40       accessibility_focus : false,
41       apply_source_formatting : true,
42       theme : 'advanced',
43       language : editor_lang,
44       plugins : 'emotions,media,nonbreaking,table,searchreplace,visualchars,directionality' + (spellcheck ? ',spellchecker' : ''),
45       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',
46       theme_advanced_buttons2 : '',
47       theme_advanced_buttons3 : '',
48       theme_advanced_toolbar_location : 'top',
49       theme_advanced_toolbar_align : 'left',
50       extended_valid_elements : 'font[face|size|color|style],span[id|class|align|style]',
51       content_css : skin_path + '/editor_content.css',
52       external_image_list_url : 'program/js/editor_images.js',
53       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'),
54       gecko_spellcheck : true,
55       relative_urls : false,
56       remove_script_host : false,
57       rc_client: rcmail,
58       oninit : 'rcmail_editor_callback'
59     });
60 }
61
62 // react to real individual tinyMCE editor init
63 function rcmail_editor_callback(editor)
64 {
65   var input_from = rcube_find_object('_from');
66   if (input_from && input_from.type=='select-one')
67     rcmail.change_identity(input_from);
68   // set tabIndex
69   rcmail_editor_tabindex()
70 }
71
72 // set tabIndex on tinyMCE editor
73 function rcmail_editor_tabindex()
74 {
75   if (rcmail.env.task == 'mail') {
76     var editor = tinyMCE.get(rcmail.env.composebody);
77     var textarea = editor.getElement();
78     var node = editor.getContentAreaContainer().childNodes[0];
79     if (textarea && node)
80       node.tabIndex = textarea.tabIndex;
81   }
82 }
83
84 // switch html/plain mode
85 function rcmail_toggle_editor(ishtml, textAreaId, flagElement)
86 {
87   var composeElement = document.getElementById(textAreaId);
88   var flag;
89
90   if (ishtml)
91     {
92     rcmail.display_spellcheck_controls(false);
93
94     rcmail.plain2html(composeElement.value, textAreaId);
95     tinyMCE.execCommand('mceAddControl', true, textAreaId);
96     rcmail_editor_tabindex();
97     if (flagElement && (flag = rcube_find_object(flagElement)))
98       flag.value = '1';
99     }
100   else
101     {
102     if (!confirm(rcmail.get_label('editorwarning')))
103       return false;
104
105     var thisMCE = tinyMCE.get(textAreaId);
106     var existingHtml = thisMCE.getContent();
107     rcmail.html2plain(existingHtml, textAreaId);
108     tinyMCE.execCommand('mceRemoveControl', true, textAreaId);
109     rcmail.display_spellcheck_controls(true);
110     if (flagElement && (flag = rcube_find_object(flagElement)))
111       flag.value = '0';
112     }
113 };