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