From a134f549bf23bc9a7827ddc023599e0b1e95f96d Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 23 Dec 2009 01:50:17 -0700 Subject: [PATCH] Track SpellChecker changes --- imp/js/compose-dimp.js | 64 +++++++++++++++++-------------- imp/js/compose.js | 70 ++++++++++++++++------------------ imp/templates/javascript_defs_dimp.php | 1 + 3 files changed, 69 insertions(+), 66 deletions(-) diff --git a/imp/js/compose-dimp.js b/imp/js/compose-dimp.js index 9eed0c756..3cef8332b 100644 --- a/imp/js/compose-dimp.js +++ b/imp/js/compose-dimp.js @@ -11,7 +11,7 @@ var DimpCompose = { // Variables defaulting to empty/false: // auto_save_interval, compose_cursor, disabled, drafts_mbox, editor_on, // is_popup, knl_p, knl_sm, mp_padding, resizebcc, resizecc, resizeto, - // row_height, rte, skip_spellcheck, spellcheck, uploading + // row_height, rte, skip_spellcheck, spellcheck, sc_submit, uploading last_msg: '', confirmCancel: function() @@ -206,7 +206,8 @@ var DimpCompose = { DIMP.conf_compose.spellcheck && DIMP.SpellCheckerObject && !DIMP.SpellCheckerObject.isActive()) { - DIMP.SpellCheckerObject.spellCheck(this.onNoSpellError.bind(this, action)); + this.sc_submit = action; + DIMP.SpellCheckerObject.spellCheck(); return; } break; @@ -343,12 +344,6 @@ var DimpCompose = { } }, - onNoSpellError: function(action) - { - this.skip_spellcheck = true; - this.uniqueSubmit(action); - }, - toggleHtmlEditor: function(noupdate) { if (!DIMP.conf_compose.rte_avail) { @@ -432,33 +427,44 @@ var DimpCompose = { initializeSpellChecker: function() { - if (!DIMP.conf_compose.rte_avail) { - return; + document.observe('SpellChecker:noerror', this._onSpellCheckNoError.bind(this)); + + if (DIMP.conf_compose.rte_avail) { + document.observe('SpellChecker:after', this._onSpellCheckAfter.bind(this)); + document.observe('SpellChecker:before', this._onSpellCheckBefore.bind(this)); } + }, - if (typeof DIMP.SpellCheckerObject != 'object') { - // If we fired before the onload that initializes the spellcheck, - // wait. - this.initializeSpellChecker.bind(this).defer(); - return; + _onSpellCheckAfter: function() + { + if (this.editor_on) { + this.rte.setData($F('composeMessage')); + $('composeMessage').next().show(); } + this.sc_submit = false; + }, - DIMP.SpellCheckerObject.onBeforeSpellCheck = function() { - if (!this.editor_on) { - return; - } - DIMP.SpellCheckerObject.htmlAreaParent = 'composeMessageParent'; + _onSpellCheckBefore: function() + { + DIMP.SpellCheckerObject.htmlAreaParent = this.editor_on + ? 'composeMessageParent' + : null; + + if (this.editor_on) { this.rte.updateElement(); $('composeMessage').next().hide(); - }.bind(this); - DIMP.SpellCheckerObject.onAfterSpellCheck = function() { - if (!this.editor_on) { - return; - } - DIMP.SpellCheckerObject.htmlAreaParent = null; - this.rte.setData($F('composeMessage')); - $('composeMessage').next().show(); - }.bind(this); + } + }, + + _onSpellCheckNoError: function() + { + if (this.sc_submit) { + this.skip_spellcheck = true; + this.uniqueSubmit(this.sc_submit); + } else { + DimpCore.showNotifications([ { type: 'horde.message', message: DIMP.text_compose.spell_noerror } ]); + this._onSpellCheckAfter(); + } }, setMessageText: function(r) diff --git a/imp/js/compose.js b/imp/js/compose.js index dc23acc56..eb0cc575a 100644 --- a/imp/js/compose.js +++ b/imp/js/compose.js @@ -8,8 +8,8 @@ var ImpCompose = { // Variables defined in compose.php: // cancel_url, spellcheck, cursor_pos, identities, last_msg, - // max_attachments, popup, redirect, reloaded, rtemode, smf_check, - // skip_spellcheck + // max_attachments, popup, redirect, reloaded, rtemode, sc_submit, + // smf_check, skip_spellcheck display_unload_warning: true, confirmCancel: function(e) @@ -177,7 +177,8 @@ var ImpCompose = { this.spellcheck && IMP.SpellCheckerObject && !IMP.SpellCheckerObject.isActive()) { - IMP.SpellCheckerObject.spellCheck(this.onNoSpellError.bind(this, actionID, e)); + this.sc_submit = { a: actionID, e: e }; + IMP.SpellCheckerObject.spellCheck(); return; } @@ -228,12 +229,6 @@ var ImpCompose = { form.submit(); }, - onNoSpellError: function(actionID, e) - { - this.skip_spellcheck = true; - this.uniqSubmit(actionID, e); - }, - _autoSaveDraft: function(r, o) { if (r.responseJSON && r.responseJSON.response) { @@ -278,33 +273,6 @@ var ImpCompose = { } }, - initializeSpellChecker: function() - { - if (typeof IMP.SpellCheckerObject != 'object') { - // If we fired before the onload that initializes the spellcheck, - // wait. - this.initializeSpellChecker.bind(this).defer(); - return; - } - - IMP.SpellCheckerObject.onBeforeSpellCheck = this._beforeSpellCheck.bind(this); - IMP.SpellCheckerObject.onAfterSpellCheck = this._afterSpellCheck.bind(this); - }, - - _beforeSpellCheck: function() - { - IMP.SpellCheckerObject.htmlAreaParent = 'composeMessageParent'; - $('composeMessage').next().hide(); - CKEDITOR.instances.composeMessage.updateElement(); - }, - - _afterSpellCheck: function() - { - IMP.SpellCheckerObject.htmlAreaParent = null; - CKEDITOR.instances.composeMessage.setData($F('composeMessage')); - $('composeMessage').next().show(); - }, - clickHandler: function(e) { if (e.isRightClick()) { @@ -397,7 +365,8 @@ var ImpCompose = { } if (this.rtemode) { - this.initializeSpellChecker(); + document.observe('SpellChecker:after', this._onAfterSpellCheck.bind(this)); + document.observe('SpellChecker:before', this._onBeforeSpellCheck.bind(this)); } if ($('to') && !$F('to')) { @@ -413,6 +382,7 @@ var ImpCompose = { document.observe('click', this.clickHandler.bindAsEventListener(this)); document.observe('change', this.changeHandler.bindAsEventListener(this)); + document.observe('SpellChecker:noerror', this._onNoErrorSpellCheck.bind(this)); if (this.auto_save) { new PeriodicalExecuter(this.uniqSubmit.bind(this, 'auto_save_draft'), this.auto_save * 60); @@ -421,6 +391,32 @@ var ImpCompose = { this.resize.bind(this).delay(0.25); }, + _onAfterSpellCheck: function() + { + CKEDITOR.instances.composeMessage.setData($F('composeMessage')); + $('composeMessage').next().show(); + this.sc_submit = null; + }, + + _onBeforeSpellCheck: function() + { + IMP.SpellCheckerObject.htmlAreaParent = 'composeMessageParent'; + $('composeMessage').next().hide(); + CKEDITOR.instances.composeMessage.updateElement(); + }, + + onNoSpellError: function() + { + if (this.sc_submit) { + this.skip_spellcheck = true; + this.uniqSubmit(this.sc_submit.a, this.sc_submit.e); + } else if (this.rtemode) { + this._onAfterSpellCheck(); + } else { + this.sc_submit = null; + } + }, + resize: function() { var d, e = this.redirect ? $('redirect') : $('compose'); diff --git a/imp/templates/javascript_defs_dimp.php b/imp/templates/javascript_defs_dimp.php index 69c4edf15..ae1e5de85 100644 --- a/imp/templates/javascript_defs_dimp.php +++ b/imp/templates/javascript_defs_dimp.php @@ -174,6 +174,7 @@ if ($compose_mode) { 'fillform' => _("You have already changed the message body, are you sure you want to drop the changes?"), 'nosubject' => _("The message does not have a Subject entered.") . "\n" . _("Send message without a Subject?"), 'remove' => _("Remove"), + 'spell_noerror' => _("No spelling errors found."), 'toggle_html' => _("Really discard all formatting information? This operation cannot be undone."), 'uploading' => _("Uploading..."), ); -- 2.11.0