app/js/context_menu.js
/**
 * 
 * Summary. 
 * 
 * Kive uses this API to define unique context menus for each supported entity.
 * Supported entities include: files, folders, workspace buttons, and search results. //#endregion
 * 
 * Each menu list item must define a name, a callback function when clicked, and the node context 
 * of the click event if applicable.
 * 
 */
Summary.

Kive uses this API to define unique context menus for each supported entity.
Supported entities include: files, folders, workspace buttons, and search results. //#endregion

Each menu list item must define a name, a callback function when clicked, and the node context
of the click event if applicable.
Summary . Kive uses this API to define unique context menus for each supported entity . Supported entities include : files folders workspace buttons and search results . // #endregion Each menu list item must define a name a callback function when clicked and the node context of the click event if applicable .
function spawnContextMenu(type, event, context) {
    let menu = document.getElementById("context_menu");
    let menuList = menu.getElementsByClassName("menu-options")[0];
    menuList.innerHTML = "";
    let posX = 0;
    let posY = 0;
    if (type == "file-tree") {
        menuList.appendChild(makeContextMenuOption("Rename", function () { openModal("single-input", "Rename", ["New Name: "], function (name) { updateNode(event.node, "name", name) }) }));
        menuList.appendChild(makeContextMenuOption("Delete", function () { openModal("confirmation", "Delete", ["Are you sure you want to delete this?"], function () { deleteNode(event.node) }) }));
        if (event.node.type == "folder") {
            menuList.appendChild(makeContextMenuOption("Create Folder", function() { openModal('single-input', 'New Folder', ['Folder Name: '], function (name) { createFolder(event.node, name); })}));
            menuList.appendChild(makeContextMenuOption("Import File", function () { get_file(event.node) }));
            menuList.appendChild(makeContextMenuOption("Import Folder", function () { get_folder("folder", event.node) }));
            menuList.appendChild(makeContextMenuOption("Import Web-Scrapbook", function () { get_folder("wsb", event.node) }));
            menuList.appendChild(makeContextMenuOption("Import Scrapbook", function () { get_folder("sb", event.node) }));
        }
        else if (event.node.type == "file") {
            menuList.appendChild(makeContextMenuOption("Open in Browser", function () { openInBrowser(event.node) }));
            menuList.appendChild(makeContextMenuOption("Get Info", function () { openModal("get-info", "Information", [event.node], null) }));
        }
        posX = event.click_event.pageX;
        posY = event.click_event.pageY;
    }
    else if (type == "workspace-button") {
        menuList.appendChild(makeContextMenuOption("Rename", function () { openModal("single-input", "Rename", ["New Name: "], function (name) { renameWorkspace(name, context) }) }));
        if (workspaceQueues[context].length != 0) {
            let opt = document.createElement("LI");
            opt.className = "menu-option";
            opt.appendChild(document.createTextNode('Delete'));
            opt.style.cursor = 'not-allowed';
            menuList.appendChild(opt)
        } else {
            menuList.appendChild(makeContextMenuOption("Delete", function () { openModal("confirmation", "Delete", ["Are you sure you want to delete this?"], function () { deleteWorkspace(context) })}));
        }
        posX = event.pageX;
        posY = event.pageY;
    }
    else if (type == "search-result") {
        menuList.appendChild(makeContextMenuOption("Preview", function() { renderPage(context) }));
        menuList.appendChild(makeContextMenuOption("Open in Browser", function() { openInBrowser(context) }));
        menuList.appendChild(makeContextMenuOption("Show in Tree", function() { seeSearchResultInTree(context) }));
        menuList.appendChild(makeContextMenuOption("Get Info", function () { openModal("get-info", "Information", [context], null) }));
        posX = event.pageX;
        posY = event.pageY;
    }
    let windWidth = window.innerWidth;
    let windHeight = window.innerHeight;
    menu.style.left = posX + "px";
    if (posY > windHeight / 2) {
        menu.style.top = (posY - menu.offsetHeight) + "px";
    }
    else {
        menu.style.top = posY + "px";
    }
    menu.style.display = "block";
}
function spawnContextMenu ( type , event , context ) { let menu = document . getElementById ( "context_menu" ) ; let menuList = menu . getElementsByClassName ( "menu-options" ) [ 0 ] ; menuList . innerHTML = "" ; let posX = 0 ; let posY = 0 ; if ( type == "file-tree" ) { menuList . appendChild ( makeContextMenuOption ( "Rename" , function ( ) { openModal ( "single-input" , "Rename" , [ "New Name: " ] , function ( name ) { updateNode ( event . node , "name" , name ) } ) } ) ) ; menuList . appendChild ( makeContextMenuOption ( "Delete" , function ( ) { openModal ( "confirmation" , "Delete" , [ "Are you sure you want to delete this?" ] , function ( ) { deleteNode ( event . node ) } ) } ) ) ; if ( event . node . type == "folder" ) { menuList . appendChild ( makeContextMenuOption ( "Create Folder" , function ( ) { openModal ( 'single-input' , 'New Folder' , [ 'Folder Name: ' ] , function ( name ) { createFolder ( event . node , name ) ; } ) } ) ) ; menuList . appendChild ( makeContextMenuOption ( "Import File" , function ( ) { get_file ( event . node ) } ) ) ; menuList . appendChild ( makeContextMenuOption ( "Import Folder" , function ( ) { get_folder ( "folder" , event . node ) } ) ) ; menuList . appendChild ( makeContextMenuOption ( "Import Web-Scrapbook" , function ( ) { get_folder ( "wsb" , event . node ) } ) ) ; menuList . appendChild ( makeContextMenuOption ( "Import Scrapbook" , function ( ) { get_folder ( "sb" , event . node ) } ) ) ; } else if ( event . node . type == "file" ) { menuList . appendChild ( makeContextMenuOption ( "Open in Browser" , function ( ) { openInBrowser ( event . node ) } ) ) ; menuList . appendChild ( makeContextMenuOption ( "Get Info" , function ( ) { openModal ( "get-info" , "Information" , [ event . node ] , null ) } ) ) ; } posX = event . click_event . pageX ; posY = event . click_event . pageY ; } else if ( type == "workspace-button" ) { menuList . appendChild ( makeContextMenuOption ( "Rename" , function ( ) { openModal ( "single-input" , "Rename" , [ "New Name: " ] , function ( name ) { renameWorkspace ( name , context ) } ) } ) ) ; if ( workspaceQueues [ context ] . length != 0 ) { let opt = document . createElement ( "LI" ) ; opt . className = "menu-option" ; opt . appendChild ( document . createTextNode ( 'Delete' ) ) ; opt . style . cursor = 'not-allowed' ; menuList . appendChild ( opt ) } else { menuList . appendChild ( makeContextMenuOption ( "Delete" , function ( ) { openModal ( "confirmation" , "Delete" , [ "Are you sure you want to delete this?" ] , function ( ) { deleteWorkspace ( context ) } ) } ) ) ; } posX = event . pageX ; posY = event . pageY ; } else if ( type == "search-result" ) { menuList . appendChild ( makeContextMenuOption ( "Preview" , function ( ) { renderPage ( context ) } ) ) ; menuList . appendChild ( makeContextMenuOption ( "Open in Browser" , function ( ) { openInBrowser ( context ) } ) ) ; menuList . appendChild ( makeContextMenuOption ( "Show in Tree" , function ( ) { seeSearchResultInTree ( context ) } ) ) ; menuList . appendChild ( makeContextMenuOption ( "Get Info" , function ( ) { openModal ( "get-info" , "Information" , [ context ] , null ) } ) ) ; posX = event . pageX ; posY = event . pageY ; } let windWidth = window . innerWidth ; let windHeight = window . innerHeight ; menu . style . left = posX + "px" ; if ( posY > windHeight / 2 ) { menu . style . top = ( posY - menu . offsetHeight ) + "px" ; } else { menu . style . top = posY + "px" ; } menu . style . display = "block" ; }
Summary.
Summary .
// Base context menu element // Base list element for context menu options // Initialize default positioning // If event has node associated with it (jqtree event) // Menu options for all nodes /*menuList.appendChild(makeContextMenuOption("cut", function () { alert("implement cut paste") }));*/ // Menu options for folder nodes only // Menu options for file nodes only // Set menu position based on click event // Right click on workspace button // Menu options for all workspaces // Check if backend is not indexing //menuList.appendChild(makeContextMenuOption("cut", function () { alert("implement cut paste") })); // Set menu position based on click event // Right click on search result // Menu options for all search results // Set menu position based on click event // Window height and width // Display and position context menu element