]> git.donarmstrong.com Git - roundcube.git/blob - program/js/editor.js
a3aef72a2f33a56e122f5d7ec504c038e620dd6f
[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(skin_path, editor_lang, spellcheck, mode)
18 {
19   var ret, conf = {
20       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_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 (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' + (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' + (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       accessibility_focus: false,
52       oninit: 'rcmail_editor_callback'
53     });
54
55   // support external configuration settings e.g. from skin
56   if (window.rcmail_editor_settings)
57     $.extend(conf, window.rcmail_editor_settings);
58
59   tinyMCE.init(conf);
60 }
61
62 // react to real individual tinyMCE editor init
63 function rcmail_editor_callback()
64 {
65   var elem = rcube_find_object('_from'),
66     fe = rcmail.env.compose_focus_elem;
67
68   if (elem && elem.type == 'select-one') {
69     rcmail.change_identity(elem);
70     // Focus previously focused element
71     if (fe && fe.id != rcmail.env.composebody) {
72       window.focus(); // for WebKit (#1486674)
73       fe.focus();
74     }
75   }
76
77   // set tabIndex and set focus to element that was focused before
78   rcmail_editor_tabindex(fe && fe.id == rcmail.env.composebody);
79   // Trigger resize (needed for proper editor resizing in some browsers using default skin)
80   $(window).resize();
81 }
82
83 // set tabIndex on tinyMCE editor
84 function rcmail_editor_tabindex(focus)
85 {
86   if (rcmail.env.task == 'mail') {
87     var editor = tinyMCE.get(rcmail.env.composebody);
88     if (editor) {
89       var textarea = editor.getElement();
90       var node = editor.getContentAreaContainer().childNodes[0];
91       if (textarea && node)
92         node.tabIndex = textarea.tabIndex;
93       if (focus)
94         editor.getWin().focus();
95     }
96   }
97 }
98
99 // switch html/plain mode
100 function rcmail_toggle_editor(select, textAreaId, flagElement)
101 {
102   var flag, ishtml;
103
104   if (select.tagName != 'SELECT')
105     ishtml = select.checked;
106   else
107     ishtml = select.value == 'html';
108
109   var res = rcmail.command('toggle-editor', {id:textAreaId, mode:ishtml?'html':'plain'});
110
111   if (ishtml) {
112     // #1486593
113     setTimeout("rcmail_editor_tabindex(true);", 500);
114     if (flagElement && (flag = rcube_find_object(flagElement)))
115       flag.value = '1';
116   }
117   else {
118     if (!res && select.tagName == 'SELECT')
119       select.value = 'html';
120     if (flagElement && (flag = rcube_find_object(flagElement)))
121       flag.value = '0';
122
123     if (rcmail.env.composebody)
124       rcube_find_object(rcmail.env.composebody).focus();
125   }
126 }