Skip to content

Commit

Permalink
Initialize googiespell in editor.js, not external file
Browse files Browse the repository at this point in the history
  • Loading branch information
pabzm committed Jul 9, 2024
1 parent f574124 commit fb5cd16
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 39 deletions.
25 changes: 11 additions & 14 deletions program/actions/mail/compose.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 7 additions & 8 deletions program/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
29 changes: 29 additions & 0 deletions program/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
};
}
17 changes: 0 additions & 17 deletions program/js/googiespell_init.js

This file was deleted.

0 comments on commit fb5cd16

Please sign in to comment.