0.1.0 • Published 8 years ago

cs-jqtree-contextmenu v0.1.0

Weekly downloads
7
License
-
Repository
github
Last release
8 years ago

jqTreeContextMenu

A context menu "plugin" to jqTree.

Heavily modifed version of the original.

Usage

Example:

    <!-- context menu -->
    <ul id="context-menu" class="dropdown-menu">
        <li data-item="edit"><a>Edit</a></li>
        <li data-item="delete"><a>Delete</a></li>
        <li data-item="foo"><a>bar</a></li>
    </ul>  

    <!-- jqTree -->
    <div id="tree"></div>

    <script>
      $(function() {
          var data = [
              {
                   name: 'node1', id: 1,
                   children: [
                       { name: 'child1', id: 2 },
                       { name: 'child2', id: 3 }
                   ]
              },
              {
                  name: 'node2', id: 4,
                  children: [
                      { name: 'child3', id: 5 }
                  ]
              }
          ];
          $('#tree').tree({ data: data });
          $('#tree').jqTreeContextMenu({
              menu: '#context-menu',
              onContextMenuItem: function(e, node, $el){
                  console.log($el.data("item"));
                  console.log(node.name);
              }
          });
      });
    </script>
</body>

Options

NameTypeDefaultDescription
menustringundefinedA jQuery selector for the menu (ie #context-menu)
selectClickedNodebooltrueWhether or not the jqTree node should be selected when right-clicked
onContextMenuItemclosurenullCalled when a context menu item is clicked. functon(e, node, $menuItem) { }
contextMenuDeciderclosurenullCalled before the menu is shown to allow choosing the context menu (see below)
menuFadeDurationint250The time in miliseconds for the menu fade in/out effect

Examples

contextMenuDecider

Use this closure option to decide which context menu should be shown when a node is clicked:

    $('#tree').jqTreeContextMenu({
        menu: '#context-menu',
        contextMenuDecider: function(node) {
            // Return a special context menu for the "root" jqTree node...
            if (!node.parent.parent) {
                return '#context-menu-root';
            }

            // Return false and the default context menu will be shown...
            return false;
        }
    });

onContextMenuItem

Use this closure to decide what action to take when a menu item is clicked. See the use example for more detail.

Events

NameParametersDescription
cm-jqtree.item.clickevent, node, $elThis is triggered when a menu item is clicked. The $el is the menu item itself