summaryrefslogtreecommitdiff
path: root/frontend/beta/js/YUI-extensions/tree/TreeSorter.js
authorGiulio Cesare Solaroli <giulio.cesare@clipperz.com>2011-10-02 23:56:18 (UTC)
committer Giulio Cesare Solaroli <giulio.cesare@clipperz.com>2011-10-02 23:56:18 (UTC)
commitef68436ac04da078ffdcacd7e1f785473a303d45 (patch) (unidiff)
treec403752d66a2c4775f00affd4fa8431b29c5b68c /frontend/beta/js/YUI-extensions/tree/TreeSorter.js
parent597ecfbc0249d83e1b856cbd558340c01237a360 (diff)
downloadclipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.zip
clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.gz
clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.bz2
First version of the newly restructured repository
Diffstat (limited to 'frontend/beta/js/YUI-extensions/tree/TreeSorter.js') (more/less context) (show whitespace changes)
-rw-r--r--frontend/beta/js/YUI-extensions/tree/TreeSorter.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/frontend/beta/js/YUI-extensions/tree/TreeSorter.js b/frontend/beta/js/YUI-extensions/tree/TreeSorter.js
new file mode 100644
index 0000000..9960703
--- a/dev/null
+++ b/frontend/beta/js/YUI-extensions/tree/TreeSorter.js
@@ -0,0 +1,49 @@
1YAHOO.ext.tree.TreeSorter = function(tree, config){
2 YAHOO.ext.util.Config.apply(this, config);
3 tree.on('beforechildrenrendered', this.doSort, this, true);
4 tree.on('append', this.updateSort, this, true);
5 tree.on('insert', this.updateSort, this, true);
6
7 var dsc = this.dir && this.dir.toLowerCase() == 'desc';
8 var p = this.property || 'text';
9 var sortType = this.sortType;
10 var fs = this.folderSort;
11 var cs = this.caseSensitive === true;
12
13 this.sortFn = function(n1, n2){
14 if(fs){
15 if(n1.leaf && !n2.leaf){
16 return 1;
17 }
18 if(!n1.leaf && n2.leaf){
19 return -1;
20 }
21 }
22 var v1 = sortType ? sortType(n1) : (cs ? n1[p] : n1[p].toUpperCase());
23 var v2 = sortType ? sortType(n2) : (cs ? n2[p] : n2[p].toUpperCase());
24 if(v1 < v2){
25 return dsc ? +1 : -1;
26 }else if(v1 > v2){
27 return dsc ? -1 : +1;
28 }else{
29 return 0;
30 }
31 };
32};
33
34YAHOO.ext.tree.TreeSorter.prototype = {
35 doSort : function(node){
36 node.sort(this.sortFn);
37 },
38
39 compareNodes : function(n1, n2){
40
41 return (n1.text.toUpperCase() > n2.text.toUpperCase() ? 1 : -1);
42 },
43
44 updateSort : function(tree, node){
45 if(node.childrenRendered){
46 this.doSort.defer(1, this, [node]);
47 }
48 }
49};