mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-29 22:45:14 -04:00
Add natural sort option to tree view.
This commit is contained in:
parent
f723bcd7bb
commit
e9ac5b46d8
4 changed files with 89 additions and 61 deletions
|
@ -1,9 +1,10 @@
|
|||
modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/store', 'core/event', 'core/location'], function (_, $, allsettings, resource, store, event, location) {
|
||||
modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/store', 'core/event', 'core/location', 'core/util'], function (_, $, allsettings, resource, store, event, location, util) {
|
||||
|
||||
var settings = _.extend({
|
||||
enabled: false,
|
||||
show: true,
|
||||
maxSubfolders: 50
|
||||
maxSubfolders: 50,
|
||||
naturalSort: false
|
||||
}, allsettings.tree);
|
||||
var template =
|
||||
'<div class="item">' +
|
||||
|
@ -25,6 +26,14 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/s
|
|||
var storekey = 'ext/tree';
|
||||
|
||||
|
||||
function cmpFn(item1, item2) {
|
||||
|
||||
var val1 = item1.label;
|
||||
var val2 = item2.label;
|
||||
|
||||
return settings.natural ? util.naturalCmpFn(val1, val2) : util.regularCmpFn(val1, val2);
|
||||
}
|
||||
|
||||
function update(item) {
|
||||
|
||||
var $html = $(template);
|
||||
|
@ -66,6 +75,8 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/s
|
|||
|
||||
// does it have subfolders?
|
||||
if (subfolders.length) {
|
||||
subfolders.sort(cmpFn);
|
||||
|
||||
var $ul = $('<ul class="content"/>').appendTo($html);
|
||||
var counter = 0;
|
||||
_.each(subfolders, function (e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue