thomascube
2010-12-17 db1a87cd6c506f2afbd1a37c64cb56ae11120b49
commit | author | age
a0109c 1 /*
S 2  +-----------------------------------------------------------------------+
e019f2 3  | Roundcube editor js library                                           |
a0109c 4  |                                                                       |
e019f2 5  | This file is part of the Roundcube web development suite              |
A 6  | Copyright (C) 2006, Roundcube Dev, - Switzerland                      |
a0109c 7  | Licensed under the GNU GPL                                            |
S 8  |                                                                       |
9  +-----------------------------------------------------------------------+
10  | Author: Eric Stadtherr <estadtherr@gmail.com>                         |
11  +-----------------------------------------------------------------------+
2c6337 12
a0109c 13  $Id: editor.js 000 2006-05-18 19:12:28Z roundcube $
S 14 */
15
b8ae50 16 // Initialize HTML editor
A 17 function rcmail_editor_init(skin_path, editor_lang, spellcheck, mode)
4ca10b 18 {
b8ae50 19   if (mode == 'identity')
665cc5 20     tinyMCE.init({
e0a5ce 21       mode: 'textareas',
A 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',
eeb34b 27       plugins: 'paste,tabfocus',
e0a5ce 28       theme_advanced_toolbar_location: 'top',
A 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
b8ae50 36     });
A 37   else // mail compose
e0a5ce 38     tinyMCE.init({
A 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'
b8ae50 62     });
4ca10b 63 }
b8ae50 64
A 65 // react to real individual tinyMCE editor init
b2f3e6 66 function rcmail_editor_callback()
b8ae50 67 {
c288f9 68   var elem = rcube_find_object('_from'),
A 69     fe = rcmail.env.compose_focus_elem;
70
71   if (elem && elem.type == 'select-one') {
1f019c 72     rcmail.change_identity(elem);
882b0f 73     // Focus previously focused element
db1a87 74     if (fe && fe.id != rcmail.env.composebody) {
T 75       window.focus(); // for WebKit (#1486674)
c288f9 76       fe.focus();
db1a87 77     }
882b0f 78   }
c288f9 79
5cff85 80   // set tabIndex and set focus to element that was focused before
c288f9 81   rcmail_editor_tabindex(fe && fe.id == rcmail.env.composebody);
eb9eff 82   // Trigger resize (needed for proper editor resizing in some browsers using default skin)
A 83   $(window).resize();
665cc5 84 }
A 85
86 // set tabIndex on tinyMCE editor
5cff85 87 function rcmail_editor_tabindex(focus)
665cc5 88 {
A 89   if (rcmail.env.task == 'mail') {
a01b3b 90     var editor = tinyMCE.get(rcmail.env.composebody);
4cdc70 91     if (editor) {
A 92       var textarea = editor.getElement();
93       var node = editor.getContentAreaContainer().childNodes[0];
94       if (textarea && node)
95         node.tabIndex = textarea.tabIndex;
5cff85 96       if (focus)
T 97         editor.getWin().focus();
4cdc70 98     }
665cc5 99   }
b8ae50 100 }
A 101
102 // switch html/plain mode
5821ff 103 function rcmail_toggle_editor(select, textAreaId, flagElement)
b8ae50 104 {
5821ff 105   var flag, ishtml;
A 106
107   if (select.tagName != 'SELECT')
108     ishtml = select.checked;
109   else
110     ishtml = select.value == 'html';
b8ae50 111
3940ba 112   var res = rcmail.command('toggle-editor', {id:textAreaId, mode:ishtml?'html':'plain'});
832594 113
3940ba 114   if (ishtml) {
4cdc70 115     // #1486593
5cff85 116     setTimeout("rcmail_editor_tabindex(true);", 500);
b8ae50 117     if (flagElement && (flag = rcube_find_object(flagElement)))
A 118       flag.value = '1';
087c7d 119   }
A 120   else {
3940ba 121     if (!res && select.tagName == 'SELECT')
5cff85 122       select.value = 'html';
b8ae50 123     if (flagElement && (flag = rcube_find_object(flagElement)))
A 124       flag.value = '0';
5cff85 125
bdf6de 126     if (rcmail.env.composebody)
A 127       rcube_find_object(rcmail.env.composebody).focus();
087c7d 128   }
A 129 }