author | Giulio 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) |
commit | ef68436ac04da078ffdcacd7e1f785473a303d45 (patch) (side-by-side diff) | |
tree | c403752d66a2c4775f00affd4fa8431b29c5b68c /frontend/beta/js/YUI-extensions/tree/TreeSorter.js | |
parent | 597ecfbc0249d83e1b856cbd558340c01237a360 (diff) | |
download | clipperz-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.js | 49 |
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 @@ +YAHOO.ext.tree.TreeSorter = function(tree, config){
+ YAHOO.ext.util.Config.apply(this, config);
+ tree.on('beforechildrenrendered', this.doSort, this, true);
+ tree.on('append', this.updateSort, this, true);
+ tree.on('insert', this.updateSort, this, true);
+
+ var dsc = this.dir && this.dir.toLowerCase() == 'desc';
+ var p = this.property || 'text';
+ var sortType = this.sortType;
+ var fs = this.folderSort;
+ var cs = this.caseSensitive === true;
+
+ this.sortFn = function(n1, n2){
+ if(fs){
+ if(n1.leaf && !n2.leaf){
+ return 1;
+ }
+ if(!n1.leaf && n2.leaf){
+ return -1;
+ }
+ }
+ var v1 = sortType ? sortType(n1) : (cs ? n1[p] : n1[p].toUpperCase());
+ var v2 = sortType ? sortType(n2) : (cs ? n2[p] : n2[p].toUpperCase());
+ if(v1 < v2){
+ return dsc ? +1 : -1;
+ }else if(v1 > v2){
+ return dsc ? -1 : +1;
+ }else{
+ return 0;
+ }
+ };
+};
+
+YAHOO.ext.tree.TreeSorter.prototype = {
+ doSort : function(node){
+ node.sort(this.sortFn);
+ },
+
+ compareNodes : function(n1, n2){
+
+ return (n1.text.toUpperCase() > n2.text.toUpperCase() ? 1 : -1);
+ },
+
+ updateSort : function(tree, node){
+ if(node.childrenRendered){
+ this.doSort.defer(1, this, [node]);
+ }
+ }
+}; |