summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2009-11-03 09:58:14 +0000
committerthomascube <thomas@roundcube.net>2009-11-03 09:58:14 +0000
commit655bd9ade2d78b8f167379abc482e981c7a95e29 (patch)
tree7afef88223ca602eedcd94aea9717786290005a4 /program
parentf8a216eba9d8af6d668fb9545fc4cd682087c8ad (diff)
Cleanup top-posting feature (sorry, there are again some new texts)
Diffstat (limited to 'program')
-rw-r--r--program/js/app.js160
-rw-r--r--program/localization/de_CH/labels.inc4
-rw-r--r--program/localization/de_DE/labels.inc4
-rw-r--r--program/localization/en_US/labels.inc4
-rw-r--r--program/steps/settings/func.inc12
-rw-r--r--program/steps/settings/save_prefs.inc2
6 files changed, 98 insertions, 88 deletions
diff --git a/program/js/app.js b/program/js/app.js
index dca295646..4c8daeed2 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -472,12 +472,17 @@ function rcube_webmail()
this.init_address_input_events(input_to);
this.init_address_input_events($("[name='_cc']"));
this.init_address_input_events($("[name='_bcc']"));
+
+ if (!html_mode)
+ this.set_caret_pos(input_message, this.env.top_posting ? 0 : $(input_message).val().length);
// add signature according to selected identity
if (input_from.attr('type') == 'select-one' && $("input[name='_draft_saveid']").val() == ''
&& !html_mode) { // if we have HTML editor, signature is added in callback
this.change_identity(input_from[0]);
}
+ else if (!html_mode)
+ this.set_caret_pos(input_message, this.env.top_posting ? 0 : $(input_message).val().length);
if (input_to.val() == '')
input_to.focus();
@@ -2300,7 +2305,7 @@ function rcube_webmail()
};
this.change_identity = function(obj, show_sig)
- {
+ {
if (!obj || !obj.options)
return false;
@@ -2310,9 +2315,8 @@ function rcube_webmail()
var id = obj.options[obj.selectedIndex].value;
var input_message = $("[name='_message']");
var message = input_message.val();
- var new_message = '';
var is_html = ($("input[name='_is_html']").val() == '1');
- var sig, p, len = message.length;
+ var sig, cursor_pos, p = -1;
if (!this.env.identity)
this.env.identity = id
@@ -2323,110 +2327,108 @@ function rcube_webmail()
else
this.enable_command('insert-sig', false);
- if (!is_html && show_sig) {
+ if (!is_html) {
// remove the 'old' signature
- if (this.env.identity && this.env.signatures && this.env.signatures[this.env.identity]) {
- if (this.env.signatures[this.env.identity]['is_html'])
- sig = this.env.signatures[this.env.identity]['plain_text'];
- else
- sig = this.env.signatures[this.env.identity]['text'];
+ if (show_sig && this.env.identity && this.env.signatures && this.env.signatures[this.env.identity]) {
+ sig = this.env.signatures[this.env.identity].is_html ? this.env.signatures[this.env.identity].plain_text : this.env.signatures[this.env.identity].text;
if (sig.indexOf('-- ') != 0)
sig = '-- \n'+sig;
- p = message.lastIndexOf(sig);
- if (p >= 0) {
- if (this.env.sig_above) {
- new_message = message.substring(0, p-1);
- new_message = new_message.replace(/[\r\n]+$/, '');
- message = message.substring(p+sig.length, message.length);
- }
- else {
- message = message.substring(0, p-1) + message.substring(p+sig.length, message.length);
- }
- }
+ p = this.env.sig_above ? message.indexOf(sig) : message.lastIndexOf(sig);
+ if (p >= 0)
+ message = message.substring(0, p) + message.substring(p+sig.length, message.length);
}
- message = message.replace(/[\r\n]+$/, '');
- len = message.length;
-
// add the new signature string
- if (this.env.signatures && this.env.signatures[id]) {
- sig = this.env.signatures[id]['text'];
- if (this.env.signatures[id]['is_html'])
- sig = this.env.signatures[id]['plain_text'];
-
+ if (show_sig && this.env.signatures && this.env.signatures[id]) {
+ sig = this.env.signatures[id]['is_html'] ? this.env.signatures[id]['plain_text'] : this.env.signatures[id]['text'];
if (sig.indexOf('-- ') != 0)
sig = '-- \n'+sig;
if (this.env.sig_above) {
- message = message.replace(/^[\r\n]+/, '');
- message = new_message+'\n\n'+sig+'\n\n'+message;
+ if (p >= 0) { // in place of removed signature
+ message = message.substring(0, p) + sig + message.substring(p, message.length);
+ cursor_pos = p - 1;
+ }
+ else if (pos = this.get_caret_pos(input_message.get(0))) { // at cursor position
+ message = message.substring(0, pos) + '\n' + sig + '\n\n' + message.substring(pos, message.length);
+ cursor_pos = pos;
+ }
+ else { // on top
+ cursor_pos = 0;
+ message = '\n\n' + sig + '\n\n' + message.replace(/^[\r\n]+/, '');
+ }
}
- else
- message += '\n\n'+sig;
-
- if (len)
- len += 1;
+ else {
+ message = message.replace(/[\r\n]+$/, '');
+ cursor_pos = !this.env.top_posting && message.length ? message.length+1 : 0;
+ message += '\n\n' + sig;
}
}
- else if (show_sig)
- {
- var editor = tinyMCE.get(this.env.composebody);
+ else
+ cursor_pos = this.env.top_posting ? 0 : message.length;
- if (this.env.signatures)
- {
- // Append the signature as a div within the body
- var sigElem = editor.dom.get('_rc_sig');
- var newsig = '';
- var htmlsig = true;
+ input_message.val(message);
+
+ // move cursor before the signature
+ this.set_caret_pos(input_message.get(0), cursor_pos);
+ }
+ else if (is_html && this.env.signatures) { // html
+ var editor = tinyMCE.get(this.env.composebody);
+ var sigElem = editor.dom.get('_rc_sig');
- if (!sigElem)
- {
- // add empty line before signature on IE
- if (bw.ie)
- editor.getBody().appendChild(editor.getDoc().createElement('br'));
-
- sigElem = editor.getDoc().createElement('div');
- sigElem.setAttribute('id', '_rc_sig');
- if (this.env.sig_above) {
- editor.getBody().insertBefore(sigElem, editor.getBody().firstChild);
- editor.getBody().insertBefore(editor.getDoc().createElement('br'), editor.getBody().firstChild);
- editor.getBody().insertBefore(editor.getDoc().createElement('br'), editor.getBody().firstChild);
- }
- else
- editor.getBody().appendChild(sigElem);
+ // Append the signature as a div within the body
+ if (!sigElem) {
+ var body = editor.getBody();
+ var doc = editor.getDoc();
+
+ sigElem = doc.createElement('div');
+ sigElem.setAttribute('id', '_rc_sig');
+
+ if (this.env.sig_above) {
+ // if no existing sig and top posting then insert at caret pos
+ editor.getWin().focus(); // correct focus in IE
+
+ var node = editor.selection.getNode();
+ if (node.nodeName == 'BODY') {
+ // no real focus, insert at start
+ body.insertBefore(sigElem, body.firstChild);
+ body.insertBefore(doc.createElement('br'), body.firstChild);
}
-
- if (this.env.signatures[id])
- {
- newsig = this.env.signatures[id]['text'];
- htmlsig = this.env.signatures[id]['is_html'];
-
- if (newsig && !this.env.sig_above) {
- if (htmlsig && this.env.signatures[id]['plain_text'].indexOf('-- ')!=0)
- newsig = '<p>-- </p>' + newsig;
- else if (!htmlsig && newsig.indexOf('-- ')!=0)
- newsig = '-- \n' + newsig;
+ else {
+ body.insertBefore(sigElem, node.nextSibling);
+ body.insertBefore(doc.createElement('br'), node.nextSibling);
}
}
+ else {
+ if (bw.ie) // add empty line before signature on IE
+ body.appendChild(doc.createElement('br'));
- if (htmlsig)
- sigElem.innerHTML = newsig;
- else
- sigElem.innerHTML = '<pre>' + newsig + '</pre>';
+ body.appendChild(sigElem);
}
}
- input_message.val(message);
+ if (this.env.signatures[id]) {
+ if (this.env.signatures[id].is_html) {
+ sig = this.env.signatures[id].text;
+ if (this.env.signatures[id].plain_text.indexOf('-- ') != 0)
+ sig = '-- <br />' + sig;
+ }
+ else {
+ sig = this.env.signatures[id].text;
+ if (sig.indexOf('-- ') != 0)
+ sig = '-- \n' + sig;
+ sig = '<pre>' + sig + '</pre>';
+ }
- // move cursor before the signature
- if (!is_html)
- this.set_caret_pos(input_message.get(0), (this.env.top_posting ? 0 : len));
+ sigElem.innerHTML = sig;
+ }
+ }
this.env.identity = id;
return true;
- };
+ };
this.show_attachment_form = function(a)
{
diff --git a/program/localization/de_CH/labels.inc b/program/localization/de_CH/labels.inc
index 7b3f14def..ae41536d4 100644
--- a/program/localization/de_CH/labels.inc
+++ b/program/localization/de_CH/labels.inc
@@ -266,7 +266,9 @@ $labels['replyremovesignature'] = 'Beim Antworten die Signatur der Originalnachr
$labels['autoaddsignature'] = 'Signatur automatisch einfügen';
$labels['newmessageonly'] = 'nur bei neuen Nachrichten';
$labels['replyandforwardonly'] = 'nur bei Antworten und Weiterleitungen';
-$labels['replysignatureabove'] = 'Beim Antworten die Signatur über der Originalnachricht einfügen';
+$labels['replysignaturepos'] = 'Beim Antworten oder Weiterleiten die Signatur';
+$labels['belowquote'] = 'unter der Originalnachricht einfügen';
+$labels['abovequote'] = 'über der Originalnachricht einfügen';
$labels['insertsignature'] = 'Signatur einfügen';
$labels['folder'] = 'Ordner';
$labels['folders'] = 'Ordner';
diff --git a/program/localization/de_DE/labels.inc b/program/localization/de_DE/labels.inc
index ac53b499d..f203b1e39 100644
--- a/program/localization/de_DE/labels.inc
+++ b/program/localization/de_DE/labels.inc
@@ -265,7 +265,9 @@ $labels['replyremovesignature'] = 'Beim Antworten Signatur der Originalnachricht
$labels['autoaddsignature'] = 'Signatur automatisch einfügen';
$labels['newmessageonly'] = 'nur bei neuen Nachrichten';
$labels['replyandforwardonly'] = 'nur bei Antworten und Weiterleitungen';
-$labels['replysignatureabove'] = 'Beim Antworten die Signatur über der Originalnachricht einfügen';
+$labels['replysignaturepos'] = 'Beim Antworten die Signatur';
+$labels['belowquote'] = 'unter der Originalnachricht einfügen';
+$labels['abovequote'] = 'über der Originalnachricht einfügen';
$labels['insertsignature'] = 'Signatur einfügen';
$labels['folder'] = 'Ordner';
$labels['folders'] = 'Ordner';
diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc
index 23dcc080e..e7d99d22b 100644
--- a/program/localization/en_US/labels.inc
+++ b/program/localization/en_US/labels.inc
@@ -321,7 +321,9 @@ $labels['replyremovesignature'] = 'When replying remove original signature from
$labels['autoaddsignature'] = 'Automatically add signature';
$labels['newmessageonly'] = 'new message only';
$labels['replyandforwardonly'] = 'replies and forwards only';
-$labels['replysignatureabove'] = 'When replying or forwarding place signature above the quote';
+$labels['replysignaturepos'] = 'When replying or forwarding place signature';
+$labels['belowquote'] = 'below the quote';
+$labels['abovequote'] = 'above the quote';
$labels['insertsignature'] = 'Insert signature';
$labels['folder'] = 'Folder';
diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc
index 30a795194..fc1755665 100644
--- a/program/steps/settings/func.inc
+++ b/program/steps/settings/func.inc
@@ -452,7 +452,7 @@ function rcmail_user_prefs($current=null)
if (!isset($no_override['top_posting'])) {
$field_id = 'rcmfd_top_posting';
- $select_replymode = new html_select(array('name' => '_top_posting', 'id' => $field_id));
+ $select_replymode = new html_select(array('name' => '_top_posting', 'id' => $field_id, 'onchange' => "\$('#rcmfd_sig_above').attr('disabled',this.selectedIndex==0)"));
$select_replymode->add(rcube_label('replybottomposting'), 0);
$select_replymode->add(rcube_label('replytopposting'), 1);
@@ -472,17 +472,19 @@ function rcmail_user_prefs($current=null)
$blocks['sig']['options']['show_sig'] = array(
'title' => html::label($field_id, Q(rcube_label('autoaddsignature'))),
- 'content' => $select_show_sig->show($config['show_sig']),
+ 'content' => $select_show_sig->show($RCMAIL->config->get('show_sig', 1)),
);
}
if (!isset($no_override['sig_above'])) {
$field_id = 'rcmfd_sig_above';
- $input_sigabove = new html_checkbox(array('name' => '_sig_above', 'id' => $field_id, 'value' => 1));
+ $select_sigabove = new html_select(array('name' => '_sig_above', 'id' => $field_id, 'disabled' => !$config['top_posting']));
+ $select_sigabove->add(rcube_label('belowquote'), 0);
+ $select_sigabove->add(rcube_label('abovequote'), 1);
$blocks['sig']['options']['sig_above'] = array(
- 'title' => html::label($field_id, Q(rcube_label('replysignatureabove'))),
- 'content' => $input_sigabove->show($config['sig_above']?1:0),
+ 'title' => html::label($field_id, Q(rcube_label('replysignaturepos'))),
+ 'content' => $select_sigabove->show($config['sig_above']?1:0),
);
}
diff --git a/program/steps/settings/save_prefs.inc b/program/steps/settings/save_prefs.inc
index 824e8f6c4..531942557 100644
--- a/program/steps/settings/save_prefs.inc
+++ b/program/steps/settings/save_prefs.inc
@@ -65,7 +65,7 @@ switch ($CURR_SECTION)
'show_sig' => isset($_POST['_show_sig']) ? intval($_POST['_show_sig']) : 1,
'top_posting' => !empty($_POST['_top_posting']),
'strip_existing_sig' => isset($_POST['_strip_existing_sig']),
- 'sig_above' => isset($_POST['_sig_above']) && !empty($_POST['_top_posting']),
+ 'sig_above' => !empty($_POST['_sig_above']) && !empty($_POST['_top_posting']),
);
break;