]> git.donarmstrong.com Git - roundcube.git/blob - program/js/editor.js
Imported Upstream version 0.5.4+dfsg
[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       plugins: 'paste,tabfocus',
28       theme_advanced_toolbar_location: 'top',
29       theme_advanced_toolbar_align: 'left',
30       theme_advanced_buttons1: 'bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,separator,outdent,indent,charmap,hr,link,unlink,code,forecolor',
31       theme_advanced_buttons2: ',fontselect,fontsizeselect',
32       theme_advanced_buttons3: '',
33       relative_urls: false,
34       remove_script_host: false,
35       gecko_spellcheck: true
36     });
37   else // mail compose
38     tinyMCE.init({
39       mode: 'textareas',
40       editor_selector: 'mce_editor',
41       accessibility_focus: false,
42       apply_source_formatting: true,
43       theme: 'advanced',
44       language: editor_lang,
45       plugins: 'paste,emotions,media,nonbreaking,table,searchreplace,visualchars,directionality,tabfocus' + (spellcheck ? ',spellchecker' : ''),
46       theme_advanced_buttons1: 'bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,outdent,indent,ltr,rtl,blockquote,|,forecolor,backcolor,fontselect,fontsizeselect',
47       theme_advanced_buttons2: 'link,unlink,code,|,emotions,charmap,image,media,|,search' + (spellcheck ? ',spellchecker' : '') + ',undo,redo',
48       theme_advanced_buttons3: '',
49       theme_advanced_toolbar_location: 'top',
50       theme_advanced_toolbar_align: 'left',
51       extended_valid_elements: 'font[face|size|color|style],span[id|class|align|style]',
52       content_css: skin_path + '/editor_content.css',
53       external_image_list_url: 'program/js/editor_images.js',
54       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'),
55       spellchecker_rpc_url: '?_task=utils&_action=spell&tiny=1',
56       gecko_spellcheck: true,
57       remove_script_host: false,
58       relative_urls: false,
59       convert_urls: false, // #1486944
60       rc_client: rcmail,
61       oninit: 'rcmail_editor_callback'
62     });
63 }
64
65 // react to real individual tinyMCE editor init
66 function rcmail_editor_callback()
67 {
68   var elem = rcube_find_object('_from'),
69     fe = rcmail.env.compose_focus_elem;
70
71   if (elem && elem.type == 'select-one') {
72     rcmail.change_identity(elem);
73     // Focus previously focused element
74     if (fe && fe.id != rcmail.env.composebody) {
75       window.focus(); // for WebKit (#1486674)
76       fe.focus();
77     }
78   }
79
80   // set tabIndex and set focus to element that was focused before
81   rcmail_editor_tabindex(fe && fe.id == rcmail.env.composebody);
82   // Trigger resize (needed for proper editor resizing in some browsers using default skin)
83   $(window).resize();
84 }
85
86 // set tabIndex on tinyMCE editor
87 function rcmail_editor_tabindex(focus)
88 {
89   if (rcmail.env.task == 'mail') {
90     var editor = tinyMCE.get(rcmail.env.composebody);
91     if (editor) {
92       var textarea = editor.getElement();
93       var node = editor.getContentAreaContainer().childNodes[0];
94       if (textarea && node)
95         node.tabIndex = textarea.tabIndex;
96       if (focus)
97         editor.getWin().focus();
98     }
99   }
100 }
101
102 // switch html/plain mode
103 function rcmail_toggle_editor(select, textAreaId, flagElement)
104 {
105   var flag, ishtml;
106
107   if (select.tagName != 'SELECT')
108     ishtml = select.checked;
109   else
110     ishtml = select.value == 'html';
111
112   var res = rcmail.command('toggle-editor', {id:textAreaId, mode:ishtml?'html':'plain'});
113
114   if (ishtml) {
115     // #1486593
116     setTimeout("rcmail_editor_tabindex(true);", 500);
117     if (flagElement && (flag = rcube_find_object(flagElement)))
118       flag.value = '1';
119   }
120   else {
121     if (!res && select.tagName == 'SELECT')
122       select.value = 'html';
123     if (flagElement && (flag = rcube_find_object(flagElement)))
124       flag.value = '0';
125
126     if (rcmail.env.composebody)
127       rcube_find_object(rcmail.env.composebody).focus();
128   }
129 }