summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2014-05-28 10:37:24 +0200
committerAleksander Machniak <alec@alec.pl>2014-05-28 10:37:24 +0200
commit2441264d00cce5cc3de0dd3923c9226f56bab5ca (patch)
tree3bb595593f3c064ff2da10f8a351fb0fc4c34671
parent20ef295ba8ff0e9fce57ee24dd7f467a366a5c88 (diff)
Improved folders sorting by name - use Intl.Collator if supported
-rw-r--r--program/include/rcmail_output_html.php1
-rw-r--r--program/js/app.js43
2 files changed, 27 insertions, 17 deletions
diff --git a/program/include/rcmail_output_html.php b/program/include/rcmail_output_html.php
index 2a90f6a01..43d73a6b4 100644
--- a/program/include/rcmail_output_html.php
+++ b/program/include/rcmail_output_html.php
@@ -68,6 +68,7 @@ class rcmail_output_html extends rcmail_output
$this->set_env('task', $task);
$this->set_env('x_frame_options', $this->config->get('x_frame_options', 'sameorigin'));
$this->set_env('standard_windows', (bool) $this->config->get('standard_windows'));
+ $this->set_env('locale', $_SESSION['language']);
// add cookie info
$this->set_env('cookie_domain', ini_get('session.cookie_domain'));
diff --git a/program/js/app.js b/program/js/app.js
index 670a8e0f5..670e78bc7 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -5898,7 +5898,8 @@ function rcube_webmail()
if (!this.gui_objects.subscriptionlist)
return false;
- var row, n, i, tmp, tmp_name, rowid, folders = [], list = [], slist = [],
+ var row, n, i, tmp, tmp_name, rowid, collator,
+ folders = [], list = [], slist = [],
tbody = this.gui_objects.subscriptionlist.tBodies[0],
refrow = $('tr', tbody).get(1),
id = 'rcmrow'+((new Date).getTime());
@@ -5925,24 +5926,32 @@ function rcube_webmail()
// add to folder/row-ID map
this.env.subscriptionrows[id] = [name, display_name, false];
- // sort folders (to find a place where to insert the row)
- // replace delimiter with \0 character to fix sorting
- // issue where 'Abc Abc' would be placed before 'Abc/def'
- var replace_from = RegExp(RegExp.escape(this.env.delimiter), 'g'),
- replace_to = String.fromCharCode(0);
-
- $.each(this.env.subscriptionrows, function(k,v) {
- if (v.length < 4) {
- var n = v[0];
- n = n.replace(replace_from, replace_to);
- v.push(n);
- }
- folders.push(v);
- });
+ // copy folders data to an array for sorting
+ $.each(this.env.subscriptionrows, function(k, v) { folders.push(v); });
+
+ try {
+ // use collator if supported (FF29, IE11, Opera15, Chrome24)
+ collator = new Intl.Collator(this.env.locale.replace('_', '-'));
+ }
+ catch (e) {};
+ // sort folders
folders.sort(function(a, b) {
- var len = a.length - 1; n1 = a[len], n2 = b[len];
- return n1 < n2 ? -1 : 1;
+ var i, f1, f2,
+ path1 = a[0].split(ref.env.delimiter),
+ path2 = b[0].split(ref.env.delimiter);
+
+ for (i=0; i<path1.length; i++) {
+ f1 = path1[i];
+ f2 = path2[i];
+
+ if (f1 !== f2) {
+ if (collator)
+ return collator.compare(f1, f2);
+ else
+ return f1 < f2 ? -1 : 1;
+ }
+ }
});
for (n in folders) {