alecpl
2012-04-10 a274fb2e20215716389ec3709f0726b7002521f3
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              |
7fe381 6  | Copyright (C) 2006-2012, The Roundcube Dev Team                       |
T 7  |                                                                       |
8  | Licensed under the GNU General Public License version 3 or            |
9  | any later version with exceptions for skins & plugins.                |
10  | See the README file for a full license statement.                     |
a0109c 11  |                                                                       |
S 12  +-----------------------------------------------------------------------+
13  | Author: Eric Stadtherr <estadtherr@gmail.com>                         |
14  +-----------------------------------------------------------------------+
2c6337 15
a0109c 16  $Id: editor.js 000 2006-05-18 19:12:28Z roundcube $
S 17 */
18
b8ae50 19 // Initialize HTML editor
66df08 20 function rcmail_editor_init(config)
4ca10b 21 {
2d889e 22   var ret, conf = {
e0a5ce 23       mode: 'textareas',
A 24       editor_selector: 'mce_editor',
25       apply_source_formatting: true,
26       theme: 'advanced',
66df08 27       language: config.lang,
A 28       content_css: config.skin_path + '/editor_content.css',
e0a5ce 29       theme_advanced_toolbar_location: 'top',
A 30       theme_advanced_toolbar_align: 'left',
31       theme_advanced_buttons3: '',
2d889e 32       extended_valid_elements: 'font[face|size|color|style],span[id|class|align|style]',
e0a5ce 33       relative_urls: false,
A 34       remove_script_host: false,
2d889e 35       gecko_spellcheck: true,
A 36       convert_urls: false, // #1486944
8f142e 37       external_image_list: window.rcmail_editor_images,
2d889e 38       rc_client: rcmail
A 39     };
40
66df08 41   if (config.mode == 'identity')
2d889e 42     $.extend(conf, {
A 43       plugins: 'paste,tabfocus',
44       theme_advanced_buttons1: 'bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,separator,outdent,indent,charmap,hr,link,unlink,code,forecolor',
90550b 45       theme_advanced_buttons2: ',fontselect,fontsizeselect'
b8ae50 46     });
4be86f 47   else { // mail compose
2d889e 48     $.extend(conf, {
66df08 49       plugins: 'paste,emotions,media,nonbreaking,table,searchreplace,visualchars,directionality,tabfocus' + (config.spellcheck ? ',spellchecker' : ''),
e0a5ce 50       theme_advanced_buttons1: 'bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,outdent,indent,ltr,rtl,blockquote,|,forecolor,backcolor,fontselect,fontsizeselect',
4be86f 51       theme_advanced_buttons2: 'link,unlink,table,|,emotions,charmap,image,media,|,code,search,undo,redo',
e0a5ce 52       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 53       spellchecker_rpc_url: '?_task=utils&_action=spell_html',
66df08 54       spellchecker_enable_learn_rpc: config.spelldict,
2d889e 55       accessibility_focus: false,
e0a5ce 56       oninit: 'rcmail_editor_callback'
b8ae50 57     });
2d889e 58
4be86f 59     // add handler for spellcheck button state update
A 60     conf.setup = function(ed) {
61       ed.onSetProgressState.add(function(ed, active) {
62         if (!active)
63           rcmail.spellcheck_state();
64       });
65     }
66   }
67
2d889e 68   // support external configuration settings e.g. from skin
A 69   if (window.rcmail_editor_settings)
70     $.extend(conf, window.rcmail_editor_settings);
71
72   tinyMCE.init(conf);
4ca10b 73 }
b8ae50 74
A 75 // react to real individual tinyMCE editor init
b2f3e6 76 function rcmail_editor_callback()
b8ae50 77 {
c288f9 78   var elem = rcube_find_object('_from'),
A 79     fe = rcmail.env.compose_focus_elem;
80
7e263e 81   if (rcmail.env.default_font)
A 82     $(tinyMCE.get(rcmail.env.composebody).getBody()).css('font-family', rcmail.env.default_font);
83
c288f9 84   if (elem && elem.type == 'select-one') {
1f019c 85     rcmail.change_identity(elem);
882b0f 86     // Focus previously focused element
43fb35 87     if (fe && fe.id != rcmail.env.composebody) {
A 88       window.focus(); // for WebKit (#1486674)
c288f9 89       fe.focus();
43fb35 90     }
882b0f 91   }
c288f9 92
5cff85 93   // set tabIndex and set focus to element that was focused before
c288f9 94   rcmail_editor_tabindex(fe && fe.id == rcmail.env.composebody);
eb9eff 95   // Trigger resize (needed for proper editor resizing in some browsers using default skin)
A 96   $(window).resize();
665cc5 97 }
A 98
99 // set tabIndex on tinyMCE editor
5cff85 100 function rcmail_editor_tabindex(focus)
665cc5 101 {
A 102   if (rcmail.env.task == 'mail') {
a01b3b 103     var editor = tinyMCE.get(rcmail.env.composebody);
4cdc70 104     if (editor) {
A 105       var textarea = editor.getElement();
106       var node = editor.getContentAreaContainer().childNodes[0];
107       if (textarea && node)
108         node.tabIndex = textarea.tabIndex;
5cff85 109       if (focus)
59c404 110         editor.getBody().focus();
4cdc70 111     }
665cc5 112   }
b8ae50 113 }
A 114
115 // switch html/plain mode
5821ff 116 function rcmail_toggle_editor(select, textAreaId, flagElement)
b8ae50 117 {
5821ff 118   var flag, ishtml;
A 119
120   if (select.tagName != 'SELECT')
121     ishtml = select.checked;
122   else
123     ishtml = select.value == 'html';
b8ae50 124
3940ba 125   var res = rcmail.command('toggle-editor', {id:textAreaId, mode:ishtml?'html':'plain'});
832594 126
3940ba 127   if (ishtml) {
4cdc70 128     // #1486593
5cff85 129     setTimeout("rcmail_editor_tabindex(true);", 500);
b8ae50 130     if (flagElement && (flag = rcube_find_object(flagElement)))
A 131       flag.value = '1';
087c7d 132   }
14d494 133   else if (res) {
b8ae50 134     if (flagElement && (flag = rcube_find_object(flagElement)))
A 135       flag.value = '0';
5cff85 136
bdf6de 137     if (rcmail.env.composebody)
A 138       rcube_find_object(rcmail.env.composebody).focus();
087c7d 139   }
14d494 140   else { // !res
A 141     if (select.tagName == 'SELECT')
142       select.value = 'html';
143     else if (select.tagName == 'INPUT')
144       select.checked = true;
145   }
087c7d 146 }
8f142e 147
A 148 // editor callbeck for images listing
149 function rcmail_editor_images()
150 {
151   var i, files = rcmail.env.attachments, list = [];
152
153   for (i in files) {
154     att = files[i];
155     if (att.complete && att.mimetype.indexOf('image/') == 0) {
156       list.push([att.name, rcmail.env.comm_path+'&_action=display-attachment&_file='+i+'&_id='+rcmail.env.compose_id]);
157     }
158   }
159
160   return list;
161 };