From fb5cd16778ce4b8c0660ca5f68bb588bb0b16cdb Mon Sep 17 00:00:00 2001 From: Pablo Zmdl Date: Tue, 9 Jul 2024 15:09:39 +0200 Subject: [PATCH] Initialize googiespell in editor.js, not external file --- program/actions/mail/compose.php | 25 +++++++++++-------------- program/js/app.js | 15 +++++++-------- program/js/editor.js | 29 +++++++++++++++++++++++++++++ program/js/googiespell_init.js | 17 ----------------- 4 files changed, 47 insertions(+), 39 deletions(-) delete mode 100644 program/js/googiespell_init.js diff --git a/program/actions/mail/compose.php b/program/actions/mail/compose.php index 8e2a08367ee..5938717d305 100644 --- a/program/actions/mail/compose.php +++ b/program/actions/mail/compose.php @@ -513,20 +513,17 @@ public static function spellchecker_init() // include GoogieSpell $rcmail->output->include_script('googiespell.js'); - $rcmail->output->include_script('googiespell_init.js'); - $rcmail->output->command('googiespell_init', - $rcmail->output->asset_url($rcmail->output->get_skin_path()), - $rcmail->url(['_task' => 'utils', '_action' => 'spell', '_remote' => 1]), - !empty($dictionary) ? 'true' : 'false', - rcube::JQ(rcube::Q($rcmail->gettext('checkspelling'))), - rcube::JQ(rcube::Q($rcmail->gettext('resumeediting'))), - rcube::JQ(rcube::Q($rcmail->gettext('close'))), - rcube::JQ(rcube::Q($rcmail->gettext('revertto'))), - rcube::JQ(rcube::Q($rcmail->gettext('nospellerrors'))), - rcube::JQ(rcube::Q($rcmail->gettext('addtodict'))), - $spellcheck_langs, - $lang - ); + $rcmail->output->set_env('googiespell_asset_url', $rcmail->output->asset_url($rcmail->output->get_skin_path())); + $rcmail->output->set_env('googiespell_base_url', $rcmail->url(['_task' => 'utils', '_action' => 'spell', '_remote' => 1])); + $rcmail->output->set_env('googiespell_use_dict', !empty($dictionary) ? 'true' : 'false'); + $rcmail->output->set_env('googiespell_lang_chck_spell', rcube::JQ(rcube::Q($rcmail->gettext('checkspelling')))); + $rcmail->output->set_env('googiespell_lang_rsm_edt', rcube::JQ(rcube::Q($rcmail->gettext('resumeediting')))); + $rcmail->output->set_env('googiespell_lang_close', rcube::JQ(rcube::Q($rcmail->gettext('close')))); + $rcmail->output->set_env('googiespell_lang_revert', rcube::JQ(rcube::Q($rcmail->gettext('revertto')))); + $rcmail->output->set_env('googiespell_lang_no_error_found', rcube::JQ(rcube::Q($rcmail->gettext('nospellerrors')))); + $rcmail->output->set_env('googiespell_lang_learn_word', rcube::JQ(rcube::Q($rcmail->gettext('addtodict')))); + $rcmail->output->set_env('googiespell_languages', $spellcheck_langs); + $rcmail->output->set_env('googiespell_currentLanguage', $lang); $rcmail->output->add_label('checking'); $rcmail->output->set_env('spell_langs', $spellcheck_langs); diff --git a/program/js/app.js b/program/js/app.js index ed412f69e90..d512c8afab6 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -417,19 +417,18 @@ function rcube_webmail() { // add more commands (not enabled) $.merge(this.env.compose_commands, ['add-recipient', 'firstpage', 'previouspage', 'nextpage', 'lastpage']); - if (window.googie) { - this.env.editor_config.spellchecker = googie; - this.env.editor_config.spellcheck_observer = function (s) { - ref.spellcheck_state(); - }; + this.env.editor_config.spellcheck_observer = function (s) { + ref.spellcheck_state(); + }; + + // initialize HTML editor + this.editor_init(null, this.env.composebody); + if (window.googie) { this.env.compose_commands.push('spellcheck'); this.enable_command('spellcheck', true); } - // initialize HTML editor - this.editor_init(null, this.env.composebody); - // init message compose form this.init_messageform(); } else if (this.env.action == 'bounce') { diff --git a/program/js/editor.js b/program/js/editor.js index a8058bd09cf..06fe55d207d 100644 --- a/program/js/editor.js +++ b/program/js/editor.js @@ -77,6 +77,13 @@ function rcube_text_editor(config, id) { deprecation_warnings: false, }; + if (window.GoogieSpell) { + this.googiespell_init(); + if (window.googie) { + config.spellchecker = window.googie; + } + } + // register spellchecker for plain text editor this.spellcheck_observer = function () {}; if (config.spellchecker) { @@ -947,4 +954,26 @@ function rcube_text_editor(config, id) { }); }); }; + + this.googiespell_init = function () { + // Don't initialize if it's already present or dependencies are not met. + if (window.googie || !window.GoogieSpell || !rcmail.env.googiespell_asset_url) { + return; + } + window.googie = new window.GoogieSpell( + rcmail.env.googiespell_asseturl + '/images/googiespell/', + rcmail.env.googiespell_baseurl + '&lang=', + rcmail.env.googiespell_use_dict + ); + googie.lang_chck_spell = rcmail.env.googiespell_lang_chck_spell; + googie.lang_rsm_edt = rcmail.env.googiespell_lang_rsm_edt; + googie.lang_close = rcmail.env.googiespell_lang_close; + googie.lang_revert = rcmail.env.googiespell_lang_revert; + googie.lang_no_error_found = rcmail.env.googiespell_lang_no_error_found; + googie.lang_learn_word = rcmail.env.googiespell_lang_learn_word; + googie.setLanguages(rcmail.env.googiespell_languages); + googie.setCurrentLanguage(rcmail.env.googiespell_currentLanguage); + googie.setDecoration(false); + googie.decorateTextarea(rcmail.env.composebody); + }; } diff --git a/program/js/googiespell_init.js b/program/js/googiespell_init.js deleted file mode 100644 index 556ea1e4047..00000000000 --- a/program/js/googiespell_init.js +++ /dev/null @@ -1,17 +0,0 @@ -rcube_webmail.prototype.googiespell_init = function (asseturl, baseurl, use_dict, lang_chck_spell, lang_rsm_edt, lang_close, lang_revert, lang_no_error_found, lang_learn_word, languages, currentLanguage) { - window.googie = new GoogieSpell( - asseturl + '/images/googiespell/', - baseurl + '&lang=', - use_dict - ); - googie.lang_chck_spell = lang_chck_spell; - googie.lang_rsm_edt = lang_rsm_edt; - googie.lang_close = lang_close; - googie.lang_revert = lang_revert; - googie.lang_no_error_found = lang_no_error_found; - googie.lang_learn_word = lang_learn_word; - googie.setLanguages(languages); - googie.setCurrentLanguage(currentLanguage); - googie.setDecoration(false); - googie.decorateTextarea(rcmail.env.composebody); -};