mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-09 02:42:47 +00:00
enable sort repo/dirent by Chinese word
This commit is contained in:
@@ -432,16 +432,22 @@ define([
|
||||
sortByName: function() {
|
||||
var dirents = this.dir;
|
||||
var el = $('#by-name');
|
||||
|
||||
dirents.comparator = function(a, b) {
|
||||
if (a.get('is_dir') && b.get('is_file')) {
|
||||
return -1;
|
||||
} else if (a.get('is_file') && b.get('is_dir')) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
var result = Common.compareTwoWord(a.get('obj_name'), b.get('obj_name'));
|
||||
if (el.hasClass('icon-caret-up')) {
|
||||
return a.get('obj_name').toLowerCase() < b.get('obj_name').toLowerCase() ? 1 : -1;
|
||||
return -result;
|
||||
} else {
|
||||
return a.get('obj_name').toLowerCase() < b.get('obj_name').toLowerCase() ? -1 : 1;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
dirents.sort();
|
||||
this.$dirent_list.empty();
|
||||
dirents.each(this.addOne, this);
|
||||
|
@@ -104,10 +104,11 @@ define([
|
||||
var repos = this.repos;
|
||||
var el = $('.by-name', this.$table);
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
||||
if (el.hasClass('icon-caret-up')) {
|
||||
return a.get('name').toLowerCase() < b.get('name').toLowerCase() ? 1 : -1;
|
||||
return -result;
|
||||
} else {
|
||||
return a.get('name').toLowerCase() < b.get('name').toLowerCase() ? -1 : 1;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
repos.sort();
|
||||
|
@@ -88,10 +88,11 @@ define([
|
||||
var repos = this.repos;
|
||||
var el = $('.by-name', this.$table);
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
||||
if (el.hasClass('icon-caret-up')) {
|
||||
return a.get('name').toLowerCase() < b.get('name').toLowerCase() ? 1 : -1;
|
||||
return -result;
|
||||
} else {
|
||||
return a.get('name').toLowerCase() < b.get('name').toLowerCase() ? -1 : 1;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
repos.sort();
|
||||
|
@@ -79,10 +79,11 @@ define([
|
||||
var repos = this.repos;
|
||||
var el = $('.by-name', this.$table);
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
||||
if (el.hasClass('icon-caret-up')) {
|
||||
return a.get('name').toLowerCase() < b.get('name').toLowerCase() ? 1 : -1;
|
||||
return -result;
|
||||
} else {
|
||||
return a.get('name').toLowerCase() < b.get('name').toLowerCase() ? -1 : 1;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
repos.sort();
|
||||
|
@@ -84,10 +84,11 @@ define([
|
||||
var repos = this.repos;
|
||||
var el = $('.by-name', this.$table);
|
||||
repos.comparator = function(a, b) { // a, b: model
|
||||
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
||||
if (el.hasClass('icon-caret-up')) {
|
||||
return a.get('name').toLowerCase() < b.get('name').toLowerCase() ? 1 : -1;
|
||||
return -result;
|
||||
} else {
|
||||
return a.get('name').toLowerCase() < b.get('name').toLowerCase() ? -1 : 1;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
repos.sort();
|
||||
|
@@ -50,12 +50,15 @@ define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'text', // Workaround for r.js, otherwise text.js will not be included
|
||||
], function($, _, text) {
|
||||
'pinyin-by-unicode'
|
||||
], function($, _, text, PinyinByUnicode) {
|
||||
return {
|
||||
INFO_TIMEOUT: 10000, // 10 secs for info msg
|
||||
SUCCESS_TIMEOUT: 3000, // 3 secs for success msg
|
||||
ERROR_TIMEOUT: 3000, // 3 secs for error msg
|
||||
|
||||
strChineseFirstPY: PinyinByUnicode.strChineseFirstPY,
|
||||
|
||||
getUrl: function(options) {
|
||||
var siteRoot = app.config.siteRoot;
|
||||
switch (options.name) {
|
||||
@@ -501,6 +504,35 @@ define([
|
||||
}
|
||||
},
|
||||
|
||||
compareTwoWord: function(a_name, b_name) {
|
||||
// compare a_name and b_name at lower case
|
||||
// if a_name >= b_name, return 1
|
||||
// if a_name < b_name, return -1
|
||||
|
||||
var a_val, b_val,
|
||||
a_uni = a_name.charCodeAt(0),
|
||||
b_uni = b_name.charCodeAt(0),
|
||||
strChineseFirstPY = this.strChineseFirstPY;
|
||||
|
||||
if ((19968 < a_uni && a_uni < 40869) && (19968 < b_uni && b_uni < 40869)) {
|
||||
// both are chinese words
|
||||
a_val = strChineseFirstPY.charAt(a_uni - 19968).toLowerCase();
|
||||
b_val = strChineseFirstPY.charAt(b_uni - 19968).toLowerCase();
|
||||
} else if ((19968 < a_uni && a_uni < 40869) && !(19968 < b_uni && b_uni < 40869)) {
|
||||
// a is chinese and b is english
|
||||
return 1;
|
||||
} else if (!(19968 < a_uni && a_uni < 40869) && (19968 < b_uni && b_uni < 40869)) {
|
||||
// a is english and b is chinese
|
||||
return -1;
|
||||
} else {
|
||||
// both are english words
|
||||
a_val = a_name.toLowerCase();
|
||||
b_val = b_name.toLowerCase();
|
||||
}
|
||||
|
||||
return a_val >= b_val ? 1 : -1;
|
||||
},
|
||||
|
||||
fileSizeFormat: function(bytes, precision) {
|
||||
var kilobyte = 1024;
|
||||
var megabyte = kilobyte * 1024;
|
||||
|
3
static/scripts/pinyin-by-unicode.js
Normal file
3
static/scripts/pinyin-by-unicode.js
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user