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