<commit_before>/*
 * TreeViewWidget JSTree WIDGET
 */
function JSTreeBrowserWidget( containerId ){

    //save parentcontrol
    this.containerControl =  $("#" + containerId );

    if ( this.containerControl.length === 0 ) {
        alert( "JSTreeBrowserWidget's container control with id:'" + containerId + "' could not be found" );
        return;
    }

    //generate unique id for control
    this.guid = "TreeBrowserWidgetjsTree";

    //generate control dynamically
    this.treeViewE = $('<div/>', {
        id: "jstree_" + this.guid
    });

    //add control to parent
    this.containerControl.append( this.treeViewE );

    //by default use visual animations to reflect changes in the three
    this._animation = true;

    //save this for later use
    var self = this;


    var copyNode = function( nodeId ) {
        console.log( "TreeBrowser copy " + nodeId );
        if ($.isFunction(self.onNodeCopy)){
            self.onNodeCopy.call(self, nodeId );
        }
    };

    var pasteNode = function( nodeId ) {
        console.log( "TreeBrowser paste " + nodeId );
        if ($.isFunction(self.onNodePaste)){
            self.onNodePaste.call(self, nodeId );
        }
    };

    var deleteNode = function( nodeId ) {
        console.log( "TreeBrowser delete " +  nodeId );
        if ($.isFunction(self.onNodeDelete)){
            self.onNodeDelete.call(self, nodeId );
        }
    };

    var editNode = function (nodeId) {
        console.log( "TreeBrowser edit " +  nodeId );
        self.treeViewE.jstree("rename",null );
    };

    var customContextMenu = function (node) {

        if ( node.hasClass("gme-loading") === true ) {
            return {};
        }

        // The default set of all items
        var items = {
            renameItem: { // The "rename" menu item
                label: "Rename",
                action: function (obj) {
                    editNode( obj.attr("nId") );
                },
                icon : "css/contextmenu/page_white_edit.png"
            },
            copyItem: { // The "delete" menu item
                label: "Copy",
                separator_before : true,
                action: function ( obj ) {
                    copyNode( obj.attr("nId") );
                },
                icon : "css/contextmenu/page_white_copy.png"
            },
            pasteItem: { // The "delete" menu item
                label: "Paste",
                action: function ( obj ) {
                    pasteNode( obj.attr("nId") );
                },
                icon : "css/contextmenu/page_white_paste.png"
            },
            deleteItem: { // The "delete" menu item
             label: "Delete",
             separator_before : true,
             action: function ( obj ) {
                 deleteNode( obj.attr("nId") );
             },
             icon : "css/contextmenu/page_white_delete.png"
            }
        };

        return items;
    };

    //contruct the tree itself using jsTree
    this.treeViewE.jstree({
        "plugins" : [ "themes", "html_data", "contextmenu", "ui", "crrm" ],
        "open_parents" : false,
        "contextmenu" : {
            "select_node" : "true",
            "show_at_node" : "true",
            "items": function(node) {
                        return customContextMenu( node );
                    }
        }
    });

    //hook up node open eventhandler
    this.treeViewE.bind("open_node.jstree", function (e, data) {
        //get the node which is about to open
        var nodeOpening = data.args[0];

        //check if parent has any children
        var nodes = jQuery.jstree._reference ( self.treeViewE )._get_children( nodeOpening );

        if ( nodes.length === 0 ) {
            //it has no children, call external function to get children
            nodeOpening = $(nodeOpening);
            console.log( "onLazyRead node:" + nodeOpening.attr("nId") );

            if ($.isFunction(self.onNodeOpen)){
                self.onNodeOpen.call(self,  nodeOpening.attr("nId"));
            }
        }
    });

    //hook up close open eventhandler
    this.treeViewE.bind("close_node.jstree", function (e, data) {
        //get the node which is about to open
        var nodeClosing = data.args[0];

        //delete children
        self.treeViewE.jstree("delete_node", nodeClosing.find('> ul > li') );<commit_msg>clean up coding style v1<commit_after>/*
 * TreeViewWidget JSTree WIDGET
 */
function JSTreeBrowserWidget( containerId ) {
    //save this for later use
    var self = this;

    //save parentcontrol
    this.containerControl =  $("#" + containerId );

    if ( this.containerControl.length === 0 ) {
        alert( "JSTreeBrowserWidget's container control with id:'" + containerId + "' could not be found" );
        return undefined;
    }

    //generate unique id for control
    this.guid = "TreeBrowserWidgetjsTree";

    //generate control dynamically
    this.treeViewE = $('<div/>', {
        id: "jstree_" + this.guid
    });

    //add control to parent
    this.containerControl.append( this.treeViewE );

    //by default use visual animations to reflect changes in the three
    this._animation = true;

    //Called when the ContexMenu's 'Copy' action is selected for the node
    var copyNode = function( nodeId ) {
        console.log( "TreeBrowser copy " + nodeId );
        if ($.isFunction(self.onNodeCopy)){
            self.onNodeCopy.call(self, nodeId );
        }
    };

    //Called when the ContexMenu's 'Paste' action is selected for the node
    var pasteNode = function( nodeId ) {
        console.log( "TreeBrowser paste " + nodeId );
        if ($.isFunction(self.onNodePaste)){
            self.onNodePaste.call(self, nodeId );
        }
    };

    //Called when the ContexMenu's 'Delete' action is selected for the node
    var deleteNode = function( nodeId ) {
        console.log( "TreeBrowser delete " +  nodeId );
        if ($.isFunction(self.onNodeDelete)){
            self.onNodeDelete.call(self, nodeId );
        }
    };

    //Called when the ContexMenu's 'Rename' action is selected for the node
    var editNode = function (nodeId) {
        console.log( "TreeBrowser edit " +  nodeId );
        self.treeViewE.jstree("rename",null );
    };

    //Called when the user right-clicks on a node and
    //the customized context menu has to be displayed
    var customContextMenu = function (node) {
        //the object will hold the available context menu actions
        var items = {};

        //context menu is available for nodes that are not currently in 'loading' state
        if ( node.hasClass("gme-loading") !== true ) {

            // The default set of available items :  Rename, Copy, Paste, Delete
            items = {
                "renameItem": { // The "rename" menu item
                    "label": "Rename",
                    "action": function (obj) {
                        editNode( obj.attr("nId") );
                    },
                    "icon" : "css/contextmenu/page_white_edit.png"
                },
                "copyItem": { // The "delete" menu item
                    "label": "Copy",
                    "separator_before" : true,
                    "action": function ( obj ) {
                        copyNode( obj.attr("nId") );
                    },
                    "icon" : "css/contextmenu/page_white_copy.png"
                },
                "pasteItem": { // The "delete" menu item
                    "label": "Paste",
                    "action": function ( obj ) {
                        pasteNode( obj.attr("nId") );
                    },
                    "icon" : "css/contextmenu/page_white_paste.png"
                },
                "deleteItem": { // The "delete" menu item
                 "label": "Delete",
                 "separator_before" : true,
                 "action": function ( obj ) {
                     deleteNode( obj.attr("nId") );
                 },
                 "icon" : "css/contextmenu/page_white_delete.png"
                }
            };
        }

        //return the complete action set for this node
        return items;
    };

    //contruct the tree itself using jsTree
    this.treeViewE.jstree({
        "plugins" : [ "themes", "html_data", "contextmenu", "ui", "crrm" ],
        "open_parents" : false,
        "contextmenu" : {
            "select_node" : "true",
            "show_at_node" : "true",
            "items": function(node) { return customContextMenu( node ); }
        }
    });

    //hook up 'node opened' EventHandler
    this.treeViewE.bind("open_node.jstree", function (e, data) {
        //get the node which is about to open
        var nodeOpening = data.args[0];

        //call event handler if exist
        if ($.isFunction(self.onNodeOpen)){
            self.onNodeOpen.call(self,  nodeOpening.attr("nId"));
        }
    });

    //hook up close open eventhandler
    this.treeViewE.bind("close_node.jstree", function (e, data) {
        //get the node which is about to open
        var nodeClosing = data.args[0];

        //delete children
        self.treeViewE.jstree("delete_node", nodeClosing.find('> ul > li') );
{'fraction_non_alphanumeric': 0.12077399717360583, 'fraction_numerical': 0.0008696597456245244, 'mean_word_length': 1.7106658809664113, 'pattern_counts': {'":': 14, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2217117', 'n_tokens_mistral': 2629, 'n_tokens_neox': 2527, 'n_words': 668}