summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2011-05-31 07:38:56 +0000
committeralecpl <alec@alec.pl>2011-05-31 07:38:56 +0000
commit340546c975bca94526a3e16039895a6d0600828b (patch)
tree06d6256f1f444557068e107128575d775e447924 /program
parent644e3ad91250c0cb7b291b48e3b5cef401bffd90 (diff)
- Optimization for spellcheck_before_send: don't invoke new ajax request. While we already have mispellings, we can return them and enable spellchecker directly without querying the server again
Diffstat (limited to 'program')
-rw-r--r--program/js/app.js18
-rw-r--r--program/js/googiespell.js83
-rw-r--r--program/steps/mail/sendmail.inc5
3 files changed, 67 insertions, 39 deletions
diff --git a/program/js/app.js b/program/js/app.js
index 5f5473a1b..32d7a6332 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -3018,6 +3018,24 @@ function rcube_webmail()
}
};
+ // resume spellchecking, highlight provided mispellings without new ajax request
+ this.spellcheck_resume = function(ishtml, data)
+ {
+ if (ishtml) {
+ var ed = tinyMCE.get(this.env.composebody);
+ sp = ed.plugins.spellchecker;
+
+ sp.active = 1;
+ sp._markWords(data);
+ ed.nodeChanged();
+ }
+ else {
+ var sp = this.env.spellcheck;
+ sp.prepare(false, true);
+ sp.processData(data);
+ }
+ }
+
this.set_draft_id = function(id)
{
$("input[name='_draft_saveid']").val(id);
diff --git a/program/js/googiespell.js b/program/js/googiespell.js
index d6aea48ba..c1b04cadd 100644
--- a/program/js/googiespell.js
+++ b/program/js/googiespell.js
@@ -203,11 +203,48 @@ this.createXMLReq = function (text) {
};
this.spellCheck = function(ignore) {
+ this.prepare(ignore);
+
+ var req_text = this.escapeSpecial(this.orginal_text),
+ ref = this;
+
+ $.ajax({ type: 'POST', url: this.getUrl(),
+ data: this.createXMLReq(req_text), dataType: 'text',
+ error: function(o) {
+ if (ref.custom_ajax_error)
+ ref.custom_ajax_error(ref);
+ else
+ alert('An error was encountered on the server. Please try again later.');
+ if (ref.main_controller) {
+ $(ref.spell_span).remove();
+ ref.removeIndicator();
+ }
+ ref.checkSpellingState();
+ },
+ success: function(data) {
+ ref.processData(data);
+ if (!ref.results.length) {
+ if (!ref.custom_no_spelling_error)
+ ref.flashNoSpellingErrorState();
+ else
+ ref.custom_no_spelling_error(ref);
+ }
+ ref.removeIndicator();
+ }
+ });
+};
+
+
+//////
+// Spell checking functions
+/////
+this.prepare = function(ignore, no_indicator)
+{
this.cnt_errors_fixed = 0;
this.cnt_errors = 0;
this.setStateChanged('checking_spell');
- if (this.main_controller)
+ if (!no_indicator && this.main_controller)
this.appendIndicator(this.spell_span);
this.error_links = [];
@@ -235,44 +272,8 @@ this.spellCheck = function(ignore) {
$(this.spell_span).unbind('click');
this.orginal_text = $(this.text_area).val();
- var req_text = this.escapeSpecial(this.orginal_text);
- var ref = this;
-
- $.ajax({ type: 'POST', url: this.getUrl(),
- data: this.createXMLReq(req_text), dataType: 'text',
- error: function(o) {
- if (ref.custom_ajax_error)
- ref.custom_ajax_error(ref);
- else
- alert('An error was encountered on the server. Please try again later.');
- if (ref.main_controller) {
- $(ref.spell_span).remove();
- ref.removeIndicator();
- }
- ref.checkSpellingState();
- },
- success: function(data) {
- var r_text = data;
- ref.results = ref.parseResult(r_text);
- if (r_text.match(/<c.*>/) != null) {
- // Before parsing be sure that errors were found
- ref.showErrorsInIframe();
- ref.resumeEditingState();
- } else {
- if (!ref.custom_no_spelling_error)
- ref.flashNoSpellingErrorState();
- else
- ref.custom_no_spelling_error(ref);
- }
- ref.removeIndicator();
- }
- });
};
-
-//////
-// Spell checking functions
-/////
this.parseResult = function(r_text) {
// Returns an array: result[item] -> ['attrs'], ['suggestions']
var re_split_attr_c = /\w+="(\d+|true)"/g,
@@ -311,6 +312,14 @@ this.parseResult = function(r_text) {
return results;
};
+this.processData = function(data)
+{
+ this.results = this.parseResult(data);
+ if (this.results.length) {
+ this.showErrorsInIframe();
+ this.resumeEditingState();
+ }
+};
//////
// Error menu functions
diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc
index 80543041a..91d71a74f 100644
--- a/program/steps/mail/sendmail.inc
+++ b/program/steps/mail/sendmail.inc
@@ -411,7 +411,7 @@ if (!$savedraft) {
// Check spelling before send
if ($CONFIG['spellcheck_before_send'] && $CONFIG['enable_spellcheck']
- && empty($_SESSION['compose']['spell_checked'])
+ && empty($_SESSION['compose']['spell_checked']) && !empty($message_body)
) {
$spellchecker = new rcube_spellchecker(get_input_value('_lang', RCUBE_INPUT_GPC));
$spell_result = $spellchecker->check($message_body, $isHtml);
@@ -419,8 +419,9 @@ if (!$savedraft) {
$_SESSION['compose']['spell_checked'] = true;
if (!$spell_result) {
+ $result = $isHtml ? $spellchecker->get_words() : $spellchecker->get_xml();
$OUTPUT->show_message('mispellingsfound', 'error');
- $OUTPUT->command('command', 'spellcheck');
+ $OUTPUT->command('spellcheck_resume', $isHtml, $result);
$OUTPUT->send('iframe');
}
}