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