thomascube
2010-04-01 1d773d71414316e0b9836a15c35576593427ee21
commit | author | age
a0109c 1 /*
S 2  +-----------------------------------------------------------------------+
3  | RoundCube editor js library                                           |
4  |                                                                       |
5  | This file is part of the RoundCube web development suite              |
6  | Copyright (C) 2006, RoundCube Dev, - Switzerland                      |
7  | Licensed under the GNU GPL                                            |
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({
A 21       mode : 'textareas',
b8ae50 22       editor_selector : 'mce_editor',
A 23       apply_source_formatting : true,
24       theme : 'advanced',
25       language : editor_lang,
26       content_css : skin_path + '/editor_content.css',
18153e 27       plugins: 'paste',
b8ae50 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 : '',
24ed41 33       relative_urls : false,
A 34       remove_script_host : false,
b8ae50 35       gecko_spellcheck : true
A 36     });
37   else // mail compose
38     tinyMCE.init({ 
39       mode : 'textareas',
40       editor_selector : 'mce_editor',
41       accessibility_focus : false,
42       apply_source_formatting : true,
43       theme : 'advanced',
44       language : editor_lang,
18153e 45       plugins : 'paste,emotions,media,nonbreaking,table,searchreplace,visualchars,directionality' + (spellcheck ? ',spellchecker' : ''),
7a48e5 46       theme_advanced_buttons1 : 'bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,outdent,indent,ltr,rtl,blockquote,|,forecolor,backcolor,fontselect,fontsizeselect',
A 47       theme_advanced_buttons2 : 'link,unlink,code,|,emotions,charmap,image,media,|,search' + (spellcheck ? ',spellchecker' : '') + ',undo,redo',
b8ae50 48       theme_advanced_buttons3 : '',
A 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       gecko_spellcheck : true,
24ed41 56       relative_urls : false,
cc97ea 57       remove_script_host : false,
4cdc70 58       rc_client : rcmail,
b8ae50 59       oninit : 'rcmail_editor_callback'
A 60     });
4ca10b 61 }
b8ae50 62
A 63 // react to real individual tinyMCE editor init
64 function rcmail_editor_callback(editor)
65 {
66   var input_from = rcube_find_object('_from');
665cc5 67   if (input_from && input_from.type=='select-one')
b8ae50 68     rcmail.change_identity(input_from);
665cc5 69   // set tabIndex
58fb65 70   rcmail_editor_tabindex();
665cc5 71 }
A 72
73 // set tabIndex on tinyMCE editor
74 function rcmail_editor_tabindex()
75 {
76   if (rcmail.env.task == 'mail') {
a01b3b 77     var editor = tinyMCE.get(rcmail.env.composebody);
4cdc70 78     if (editor) {
A 79       var textarea = editor.getElement();
80       var node = editor.getContentAreaContainer().childNodes[0];
81       if (textarea && node)
82         node.tabIndex = textarea.tabIndex;
83     }
665cc5 84   }
b8ae50 85 }
A 86
87 // switch html/plain mode
5821ff 88 function rcmail_toggle_editor(select, textAreaId, flagElement)
b8ae50 89 {
A 90   var composeElement = document.getElementById(textAreaId);
5821ff 91   var flag, ishtml;
A 92
93   if (select.tagName != 'SELECT')
94     ishtml = select.checked;
95   else
96     ishtml = select.value == 'html';
b8ae50 97
A 98   if (ishtml)
99     {
100     rcmail.display_spellcheck_controls(false);
832594 101
962085 102     rcmail.plain2html(composeElement.value, textAreaId);
4cdc70 103     tinyMCE.execCommand('mceToggleEditor', false, textAreaId);
A 104     // #1486593
105     setTimeout("rcmail_editor_tabindex();", 500);
b8ae50 106     if (flagElement && (flag = rcube_find_object(flagElement)))
A 107       flag.value = '1';
108     }
109   else
110     {
111     var thisMCE = tinyMCE.get(textAreaId);
112     var existingHtml = thisMCE.getContent();
5821ff 113
A 114     if (existingHtml) {
115       if (!confirm(rcmail.get_label('editorwarning'))) {
116         if (select.tagName == 'SELECT')
117       select.value = 'html';
118         return false;
119     }
120
121       rcmail.html2plain(existingHtml, textAreaId);
122       }
123
4cdc70 124     tinyMCE.execCommand('mceToggleEditor', false, textAreaId);
b8ae50 125     rcmail.display_spellcheck_controls(true);
A 126     if (flagElement && (flag = rcube_find_object(flagElement)))
127       flag.value = '0';
128     }
129 };