]> git.donarmstrong.com Git - roundcube.git/blob - program/js/editor.js
Imported Upstream version 0.2~stable
[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({ mode : 'textareas',
21       editor_selector : 'mce_editor',
22       apply_source_formatting : true,
23       theme : 'advanced',
24       language : editor_lang,
25       content_css : skin_path + '/editor_content.css',
26       theme_advanced_toolbar_location : 'top',
27       theme_advanced_toolbar_align : 'left',
28       theme_advanced_buttons1 : 'bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,separator,outdent,indent,charmap,hr,link,unlink,code,forecolor',
29       theme_advanced_buttons2 : ',fontselect,fontsizeselect',
30       theme_advanced_buttons3 : '',
31       gecko_spellcheck : true
32     });
33   else // mail compose
34     tinyMCE.init({ 
35       mode : 'textareas',
36       editor_selector : 'mce_editor',
37       accessibility_focus : false,
38       apply_source_formatting : true,
39       theme : 'advanced',
40       language : editor_lang,
41       plugins : 'emotions,media,nonbreaking,table,searchreplace,visualchars,directionality' + (spellcheck ? ',spellchecker' : ''),
42       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',
43       theme_advanced_buttons2 : '',
44       theme_advanced_buttons3 : '',
45       theme_advanced_toolbar_location : 'top',
46       theme_advanced_toolbar_align : 'left',
47       extended_valid_elements : 'font[face|size|color|style],span[id|class|align|style]',
48       content_css : skin_path + '/editor_content.css',
49       external_image_list_url : 'program/js/editor_images.js',
50       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'),
51       gecko_spellcheck : true,
52       rc_client: rcube_webmail_client,
53       oninit : 'rcmail_editor_callback'
54     });
55 }
56
57 // react to real individual tinyMCE editor init
58 function rcmail_editor_callback(editor)
59 {
60   var input_from = rcube_find_object('_from');
61   if(input_from && input_from.type=='select-one')
62     rcmail.change_identity(input_from);
63 }
64
65 // switch html/plain mode
66 function rcmail_toggle_editor(ishtml, textAreaId, flagElement)
67 {
68   var composeElement = document.getElementById(textAreaId);
69   var flag;
70
71   if (ishtml)
72     {
73     var existingPlainText = composeElement.value;
74     var htmlText = "<pre>" + existingPlainText + "</pre>";
75
76     rcmail.display_spellcheck_controls(false);
77     composeElement.value = htmlText;
78     tinyMCE.execCommand('mceAddControl', true, textAreaId);
79     if (flagElement && (flag = rcube_find_object(flagElement)))
80       flag.value = '1';
81     }
82   else
83     {
84     if (!confirm(rcmail.get_label('editorwarning')))
85       return false;
86
87     var thisMCE = tinyMCE.get(textAreaId);
88     var existingHtml = thisMCE.getContent();
89     rcmail.html2plain(existingHtml, textAreaId);
90     tinyMCE.execCommand('mceRemoveControl', true, textAreaId);
91     rcmail.display_spellcheck_controls(true);
92     if (flagElement && (flag = rcube_find_object(flagElement)))
93       flag.value = '0';
94     }
95 };