From 50f8c259c4137bb716217c7d92486a2c2ff0440d Mon Sep 17 00:00:00 2001 From: Rishav Agarwal Date: Thu, 2 Mar 2017 00:26:18 +0530 Subject: [PATCH] Added sort function to move folders to top. Also fixes icon not working properly --- assets/js/scancode.js | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/assets/js/scancode.js b/assets/js/scancode.js index 0581aff8..69938a54 100644 --- a/assets/js/scancode.js +++ b/assets/js/scancode.js @@ -249,14 +249,33 @@ $(document).ready(function () { var jstree = $('#jstree').jstree({ "types": { - "folder": { + "directory": { "icon": "glyphicon glyphicon-folder-close" }, "file": { "icon": "glyphicon glyphicon-file" } }, - "plugins": [ "types"] + "plugins": [ "types" , "sort"], + //A sort function to sort the tree so that folders come first + "sort": function(a,b){ + x = this.get_node(a) + y = this.get_node(b) + if(x.type == "directory"){ + if(y.type == "directory"){ + //if both the nodes are directory, alphabetic wise priority is given + return (x.text>y.text) ? 1 : -1 + }else{ + return -1 + } + }else{ + if(y.type == "directory"){ + return 1 + }else{ + return (x.text>y.text) ? 1 : -1 + } + } + } }) .on('open_node.jstree', function (evt, data) { data.instance.set_icon( @@ -289,6 +308,11 @@ $(document).ready(function () { // The xhr.dt event occurs whenever new json data is loaded .on('xhr.dt', function (event, settings, json, xhr) { scanData = new ScanData(json); + //Fixing jsTreeData + for(var i=0;i