From 6fa5b437a48485927e5d90abe061ee723f3b45c2 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 20 Jan 2014 18:46:28 +0100 Subject: Update to TinyMCE 4.x --- program/steps/mail/sendmail.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'program/steps/mail/sendmail.inc') diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc index 0619d630b..005c25427 100644 --- a/program/steps/mail/sendmail.inc +++ b/program/steps/mail/sendmail.inc @@ -722,11 +722,11 @@ function rcmail_get_identity($id) /** * go from this: - * Cool + * Cool * * to this: * - * Cool + * Cool */ function rcmail_fix_emoticon_paths($mime_message) { @@ -737,7 +737,7 @@ function rcmail_fix_emoticon_paths($mime_message) // remove any null-byte characters before parsing $body = preg_replace('/\x00/', '', $body); - $searchstr = 'program/js/tiny_mce/plugins/emotions/img/'; + $searchstr = 'program/js/tinymce/plugins/emoticons/img/'; $offset = 0; // keep track of added images, so they're only added once -- cgit v1.2.3 From 89d6ce68463b92641946551b07ec49b023d56d90 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Thu, 1 May 2014 11:48:29 +0200 Subject: Update to TinyMCE 4.x --- program/js/app.js | 5 ++ program/js/editor.js | 94 +++++++++++++--------------- program/lib/Roundcube/rcube_spellchecker.php | 13 +++- program/steps/mail/compose.inc | 2 +- program/steps/mail/sendmail.inc | 7 ++- program/steps/utils/spell_html.inc | 30 ++++----- skins/classic/common.css | 4 ++ skins/classic/functions.js | 7 +-- skins/larry/ui.js | 2 +- 9 files changed, 84 insertions(+), 80 deletions(-) (limited to 'program/steps/mail/sendmail.inc') diff --git a/program/js/app.js b/program/js/app.js index 1baedac33..0588eb45b 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -3358,8 +3358,11 @@ function rcube_webmail() { this.stop_spellchecking(); + var flag = $('[name="_is_html"]'); + if (props.mode == 'html') { this.plain2html($('#'+props.id).val(), props.id); + flag.val(1); tinymce.execCommand('mceAddEditor', false, props.id); if (this.env.default_font) @@ -3376,6 +3379,8 @@ function rcube_webmail() } this.html2plain(existingHtml, props.id); } + + flag.val(0); tinymce.execCommand('mceRemoveEditor', false, props.id); } diff --git a/program/js/editor.js b/program/js/editor.js index 632ff9918..8a6e88433 100644 --- a/program/js/editor.js +++ b/program/js/editor.js @@ -19,7 +19,6 @@ function rcmail_editor_init(config) { var ret, conf = { selector: '.mce_editor', - apply_source_formatting: true, theme: 'modern', language: config.lang, content_css: config.skin_path + '/editor_content.css', @@ -28,36 +27,37 @@ function rcmail_editor_init(config) extended_valid_elements: 'font[face|size|color|style],span[id|class|align|style]', relative_urls: false, remove_script_host: false, - gecko_spellcheck: true, convert_urls: false, // #1486944 - external_image_list: window.rcmail_editor_images, //TODO - rc_client: rcmail + image_list: window.rcmail_editor_images, + image_description: false, + paste_webkit_style: "color font-size font-family", + paste_data_images: true }; if (config.mode == 'identity') $.extend(conf, { plugins: ['charmap code hr link paste tabfocus textcolor'], toolbar: 'bold italic underline alignleft aligncenter alignright alignjustify' - + ' | outdent indent charmap hr link unlink code forecolor' - + ' | fontselect fontsizeselect' + + ' | outdent indent charmap hr link unlink code forecolor' + + ' | fontselect fontsizeselect' }); else { // mail compose $.extend(conf, { - plugins: ['charmap code directionality emoticons link image media nonbreaking paste table tabfocus textcolor searchreplace' + (config.spellcheck ? ' spellchecker' : '')], + plugins: ['charmap code directionality emoticons link image media nonbreaking' + + ' paste table tabfocus textcolor searchreplace' + (config.spellcheck ? ' spellchecker' : '')], toolbar: 'bold italic underline | alignleft aligncenter alignright alignjustify' - + ' | bullist numlist outdent indent ltr rtl blockquote | forecolor backcolor | fontselect fontsizeselect' - + ' | link unlink table | emoticons charmap image media | code searchreplace undo redo', -// 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'), - spellchecker_rpc_url: '?_task=utils&_action=spell_html&_remote=1', - spellchecker_enable_learn_rpc: config.spelldict, + + ' | bullist numlist outdent indent ltr rtl blockquote | forecolor backcolor | fontselect fontsizeselect' + + ' | link unlink table | emoticons charmap image media | code searchreplace undo redo', + spellchecker_rpc_url: '../../../../../?_task=utils&_action=spell_html&_remote=1', + spellchecker_enable_learn_rpc: config.spelldict, //TODO accessibility_focus: false }); conf.setup = function(ed) { ed.on('init', rcmail_editor_callback); // add handler for spellcheck button state update - ed.on('SetProgressState', function(args) { - if (!args.active) + ed.on('ProgressState', function(args) { + if (!args.state) rcmail.spellcheck_state(); }); ed.on('keypress', function() { @@ -90,7 +90,10 @@ function rcmail_editor_callback() $(tinymce.get(rcmail.env.composebody).getBody()).css(css); if (elem && elem.type == 'select-one') { - rcmail.change_identity(elem); + // insert signature (only for the first time) + if (!rcmail.env.identities_initialized) + rcmail.change_identity(elem); + // Focus previously focused element if (fe && fe.id != rcmail.env.composebody) { // use setTimeout() for IE9 (#1488541) @@ -103,8 +106,8 @@ function rcmail_editor_callback() // set tabIndex and set focus to element that was focused before rcmail_editor_tabindex(fe && fe.id == rcmail.env.composebody); - // Trigger resize (needed for proper editor resizing in some browsers using default skin) - $(window).resize(); + // Trigger resize (needed for proper editor resizing in some browsers) + window.setTimeout(function() { $(window).resize(); }, 100); } // set tabIndex on tinymce editor @@ -113,8 +116,9 @@ function rcmail_editor_tabindex(focus) if (rcmail.env.task == 'mail') { var editor = tinymce.get(rcmail.env.composebody); if (editor) { - var textarea = editor.getElement(); - var node = editor.getContentAreaContainer().childNodes[0]; + var textarea = editor.getElement(), + node = editor.getContentAreaContainer().childNodes[0]; + if (textarea && node) node.tabIndex = textarea.tabIndex; if (focus) @@ -124,49 +128,37 @@ function rcmail_editor_tabindex(focus) } // switch html/plain mode -function rcmail_toggle_editor(select, textAreaId, flagElement) +function rcmail_toggle_editor(select, textAreaId) { - var flag, ishtml; - - if (select.tagName != 'SELECT') - ishtml = select.checked; - else - ishtml = select.value == 'html'; - - var res = rcmail.command('toggle-editor', {id:textAreaId, mode:ishtml?'html':'plain'}); - - if (ishtml) { - // #1486593 - setTimeout("rcmail_editor_tabindex(true);", 500); - if (flagElement && (flag = rcube_find_object(flagElement))) - flag.value = '1'; - } - else if (res) { - if (flagElement && (flag = rcube_find_object(flagElement))) - flag.value = '0'; + var ishtml = select.tagName != 'SELECT' ? select.checked : select.value == 'html', + res = rcmail.command('toggle-editor', {id: textAreaId, mode: ishtml ? 'html' : 'plain'}); - if (rcmail.env.composebody) - rcube_find_object(rcmail.env.composebody).focus(); - } - else { // !res + if (!res) { if (select.tagName == 'SELECT') select.value = 'html'; else if (select.tagName == 'INPUT') select.checked = true; } + else if (ishtml) { + // #1486593 + setTimeout("rcmail_editor_tabindex(true);", 500); + } + else if (rcmail.env.composebody) { + rcube_find_object(rcmail.env.composebody).focus(); + } } -// editor callbeck for images listing -function rcmail_editor_images() +// editor callback for images listing +function rcmail_editor_images(callback) { - var i, files = rcmail.env.attachments, list = []; + var i, file, list = []; - for (i in files) { - att = files[i]; - if (att.complete && att.mimetype.startsWith('image/')) { - list.push([att.name, rcmail.env.comm_path+'&_id='+rcmail.env.compose_id+'&_action=display-attachment&_file='+i]); + for (i in rcmail.env.attachments) { + file = rcmail.env.attachments[i]; + if (file.complete && file.mimetype.startsWith('image/')) { + list.push({title: file.name, value: rcmail.env.comm_path+'&_id='+rcmail.env.compose_id+'&_action=display-attachment&_file='+i}); } } - return list; -}; + callback(list); +} diff --git a/program/lib/Roundcube/rcube_spellchecker.php b/program/lib/Roundcube/rcube_spellchecker.php index 5b77bda02..3d15eb660 100644 --- a/program/lib/Roundcube/rcube_spellchecker.php +++ b/program/lib/Roundcube/rcube_spellchecker.php @@ -226,7 +226,18 @@ class rcube_spellchecker else { $word = mb_substr($this->content, $item[1], $item[2], RCUBE_CHARSET); } - $result[$word] = is_array($item[4]) ? implode("\t", $item[4]) : $item[4]; + + if (is_array($item[4])) { + $suggestions = $item[4]; + } + else if (empty($item[4])) { + $suggestions = array(); + } + else { + $suggestions = explode("\t", $item[4]); + } + + $result[$word] = $suggestions; } return $result; diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc index db001d54e..db485fda8 100644 --- a/program/steps/mail/compose.inc +++ b/program/steps/mail/compose.inc @@ -1675,7 +1675,7 @@ function rcmail_editor_selector($attrib) if (empty($attrib['name'])) $attrib['name'] = 'editorSelect'; - $attrib['onchange'] = "return rcmail_toggle_editor(this, '".$attrib['editorid']."', '_is_html')"; + $attrib['onchange'] = "return rcmail_toggle_editor(this, '".$attrib['editorid']."')"; $select = new html_select($attrib); diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc index 005c25427..5bddc249a 100644 --- a/program/steps/mail/sendmail.inc +++ b/program/steps/mail/sendmail.inc @@ -273,9 +273,10 @@ if ($isHtml) { } // append doctype and html/body wrappers - $message_body = '' - . "\r\n\r\n" - . $message_body; + $bstyle = !empty($bstyle) ? (" style='" . implode($bstyle, '; ') . "'") : ''; + $message_body = '' + . '' + . "\r\n" . $message_body; } if (!$savedraft) { diff --git a/program/steps/utils/spell_html.inc b/program/steps/utils/spell_html.inc index 27b14acef..b31d6ed86 100644 --- a/program/steps/utils/spell_html.inc +++ b/program/steps/utils/spell_html.inc @@ -19,31 +19,23 @@ +-----------------------------------------------------------------------+ */ -// read input data -$data = file_get_contents('php://input'); -// Decode JSON input -$request = json_decode($data, true); +$lang = rcube_utils::get_input_value('lang', rcube_utils::INPUT_POST); +$data = rcube_utils::get_input_value('text', rcube_utils::INPUT_POST); +$data = html_entity_decode($data, ENT_QUOTES, RCUBE_CHARSET); $result = array(); -$lang = $request['params'][0]; -$data = $request['params'][1]; -$data = implode("\n", (array) $data); - -$result['id'] = $request['id']; - $spellchecker = new rcube_spellchecker($lang); -if ($request['method'] == 'checkWords') { - $result['result'] = $spellchecker->get_words($data); -} -else if ($request['method'] == 'getSuggestions') { - $result['result'] = $spellchecker->get_suggestions($data); -} -else if ($request['method'] == 'learnWord') { +if ($method == 'learnWord') { $spellchecker->add_word($data); $result['result'] = true; } +else if ($data) { + if (!$spellchecker->check($data)) { + $result['words'] = $spellchecker->get(); + } +} if ($error = $spellchecker->error()) { rcube::raise_error(array('code' => 500, 'type' => 'php', @@ -51,12 +43,12 @@ if ($error = $spellchecker->error()) { 'message' => sprintf("Spell check engine error: " . $error)), true, false); - echo '{"error":{"errstr":"' . addslashes($error) . '","errfile":"","errline":null,"errcontext":"","level":"FATAL"}}'; + echo json_encode(array('error' => $error)); exit; } // send output -header("Content-Type: text/xml; charset=".RCUBE_CHARSET); +header("Content-Type: application/json; charset=".RCUBE_CHARSET); echo json_encode($result); exit; diff --git a/skins/classic/common.css b/skins/classic/common.css index 10bc91c09..390522fe8 100644 --- a/skins/classic/common.css +++ b/skins/classic/common.css @@ -597,6 +597,10 @@ img.uploading height: 16px; } +.mce-btn button { + height: 28px; +} + /***** common table settings ******/ table.records-table thead tr td diff --git a/skins/classic/functions.js b/skins/classic/functions.js index 07df6391c..aaaf393e7 100644 --- a/skins/classic/functions.js +++ b/skins/classic/functions.js @@ -543,10 +543,9 @@ resize_compose_body: function() w = div.width() - 2, h = div.height(), x = bw.ie || bw.opera ? 4 : 0; - $('#compose-body_tbl').width((w+3)+'px').height(''); - $('#compose-body_ifr').width((w+3)+'px').height((h-54)+'px'); - $('#compose-body').width((w-x)+'px').height(h+'px'); - $('#googie_edit_layer').height(h+'px'); + $('#compose-body_ifr').width(w+3).height(h-2 - $('div.mce-toolbar').height()); + $('#compose-body').width(w-x).height(h); + $('#googie_edit_layer').height(h); }, resize_compose_body_ev: function() diff --git a/skins/larry/ui.js b/skins/larry/ui.js index a173ffd1d..c85c37257 100644 --- a/skins/larry/ui.js +++ b/skins/larry/ui.js @@ -528,7 +528,7 @@ function rcube_mail_ui() body.width(w).height(h); $('#composebodycontainer > div').width(w+8).css('margin-top', '1px'); - $('#composebody_ifr').height(h + 4 - $('.mce-toolbar-grp').height()); + $('#composebody_ifr').height(h + 4 - $('div.mce-toolbar').height()); $('#googie_edit_layer').height(h - 8); // $('#composebodycontainer')[(btns ? 'addClass' : 'removeClass')]('buttons'); // $('#composeformbuttons')[(btns ? 'show' : 'hide')](); -- cgit v1.2.3 From f56e70bd049bde916c368f3f79df702a73ad63db Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 28 May 2014 15:19:49 +0200 Subject: TinyMCE4: Fix spellchecker resume --- program/js/app.js | 8 +++----- program/steps/mail/sendmail.inc | 8 +++++++- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'program/steps/mail/sendmail.inc') diff --git a/program/js/app.js b/program/js/app.js index b0b2cb15c..b88ed28c3 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -3592,11 +3592,9 @@ function rcube_webmail() { if (ishtml) { var ed = tinymce.get(this.env.composebody); - sp = ed.plugins.spellchecker; - - sp.active = 1; - sp._markWords(data); - ed.nodeChanged(); + ed.settings.spellchecker_callback = function(name, text, done, error) { done(data); }; + ed.execCommand('mceSpellCheck'); + ed.settings.spellchecker_callback = null; } else { var sp = this.env.spellcheck; diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc index 5bddc249a..2255acc13 100644 --- a/program/steps/mail/sendmail.inc +++ b/program/steps/mail/sendmail.inc @@ -301,7 +301,13 @@ if (!$savedraft) { $COMPOSE['spell_checked'] = true; if (!$spell_result) { - $result = $isHtml ? $spellchecker->get_words() : $spellchecker->get_xml(); + if ($isHtml) { + $result['words'] = $spellchecker->get(); + $result['dictionary'] = (bool) $RCMAIL->config->get('spellcheck_dictionary'); + } + else { + $result = $spellchecker->get_xml(); + } $OUTPUT->show_message('mispellingsfound', 'error'); $OUTPUT->command('spellcheck_resume', $isHtml, $result); -- cgit v1.2.3