Skip to content

Commit

Permalink
Clean up spellchecker initialization
Browse files Browse the repository at this point in the history
We don't need the global variable, so we got rid of it.
Also since we're passing the config details encoded anyway, we can also
use an array instead of a list of key-value pairs, and we can skip the
quoting, too.
  • Loading branch information
pabzm committed Jul 10, 2024
1 parent e8036cf commit 03c7037
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
24 changes: 13 additions & 11 deletions program/actions/mail/compose.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,17 +513,19 @@ public static function spellchecker_init()

// include GoogieSpell
$rcmail->output->include_script('googiespell.js');
$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->set_env('googiespell_conf', [
'asset_url' => $rcmail->output->asset_url($rcmail->output->get_skin_path()),
'base_url' => $rcmail->url(['_task' => 'utils', '_action' => 'spell', '_remote' => 1]),
'use_dict' => !empty($dictionary) ? 'true' : 'false',
'lang_chck_spell' => $rcmail->gettext('checkspelling'),
'lang_rsm_edt' => $rcmail->gettext('resumeediting'),
'lang_close' => $rcmail->gettext('close'),
'lang_revert' => $rcmail->gettext('revertto'),
'lang_no_error_found' => $rcmail->gettext('nospellerrors'),
'lang_learn_word' => $rcmail->gettext('addtodict'),
'languages' => $spellcheck_langs,
'currentLanguage' => $lang,
]);

$rcmail->output->add_label('checking');
$rcmail->output->set_env('spell_langs', $spellcheck_langs);
Expand Down
4 changes: 2 additions & 2 deletions program/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ function rcube_webmail() {
// initialize HTML editor
this.editor_init(null, this.env.composebody);

if (window.googie) {
if (!!this.editor.spellchecker) {
this.env.compose_commands.push('spellcheck');
this.enable_command('spellcheck', true);
}
Expand Down Expand Up @@ -4170,7 +4170,7 @@ function rcube_webmail() {

// re-enable commands that operate on the compose body
ref.enable_command('toggle-editor', 'insert-response', true);
ref.enable_command('spellcheck', !!window.googie);
ref.enable_command('spellcheck', !!ref.editor.spellchecker);
ref.enable_command('insert-sig', !!(ref.env.signatures && ref.env.identity && ref.env.signatures[ref.env.identity]));

ref.triggerEvent('compose-encrypted', { active: false });
Expand Down
38 changes: 19 additions & 19 deletions program/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,12 @@ function rcube_text_editor(config, id) {
};

this.init = function () {
this.googiespell_init();
if (window.googie) {
config.spellchecker = window.googie;
}
var googie = this.googiespell_init();

// register spellchecker for plain text editor
this.spellcheck_observer = function () {};
if (config.spellchecker) {
this.spellchecker = config.spellchecker;
if (googie) {
this.spellchecker = googie;
if (config.spellcheck_observer) {
this.spellchecker.spelling_state_observer = this.spellcheck_observer = config.spellcheck_observer;
}
Expand Down Expand Up @@ -957,23 +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) {
if (!window.GoogieSpell || !rcmail.env.googiespell_conf) {
return;
}
window.googie = new window.GoogieSpell(
rcmail.env.googiespell_asset_url + '/images/googiespell/',
rcmail.env.googiespell_base_url + '&lang=',
rcmail.env.googiespell_use_dict
var conf = rcmail.env.googiespell_conf;
var googie = new window.GoogieSpell(
conf.asset_url + '/images/googiespell/',
conf.base_url + '&lang=',
conf.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.lang_chck_spell = conf.lang_chck_spell;
googie.lang_rsm_edt = conf.lang_rsm_edt;
googie.lang_close = conf.lang_close;
googie.lang_revert = conf.lang_revert;
googie.lang_no_error_found = conf.lang_no_error_found;
googie.lang_learn_word = conf.lang_learn_word;
googie.setLanguages(conf.languages);
googie.setCurrentLanguage(conf.currentLanguage);
googie.setDecoration(false);
googie.decorateTextarea(rcmail.env.composebody);

return googie;
};
}

0 comments on commit 03c7037

Please sign in to comment.