Giter Site home page Giter Site logo

knockout.contextmenu's Introduction

knockout.contextmenu Build Status Greenkeeper badge

Contextual menu, anywhere you need it

Such example

Install

npm install knockout.contextmenu --save

bower install knockout.contextmenu

With npm

Just do:

require('knockout.contextmenu');

Usage

To bind a context menu to an element:

<td data-bind="contextMenu: { 'Option 1': $root.rootMethod, 'Option 2': itemMethod, 'Option 3': anotherMethod }">

Dont forget to include the .css file.

You can also bind a boolean observable to the context menu, that will work as a 'check':

{ 
    "Boolean": someObservableBoolean, 
    "One method": $root.test 
}

You can also set dynamic 'text' and 'visible' values binding an object with the following values instead of a method:

Option Description
url Direct access to an URL.
text Set menu text.
visible Show/hide item (result must be boolean).
action Item method, mandatory if not url defined.
disabled Disable menu item.

Example:

{ 
    "Complex item": { 
        "text": $root.someObservableText(), 
        "visible": someMethod() == '1', 
        "action": $root.someAction 
    }, 
    "One method": $root.test
}

To create a separator between two menus, just create an object with the property separator with true:

{ 
    "Some item": methodOne,
    "Separator": { 
        "separator": true, 
        "visible": someMethod() 
    },
    "Just another item": methodTwo
}

Bind it with left click, if you want to:

<td data-bind="contextMenu: { 'Options': justGoHere }, bindMenuOnClick: true, bindMenuOnContextMenu: false">

Also supports observableArrays!

var menu = ko.observableArray([{ text: 'Item 1', action: doSomething }, { text: 'Item 2', action: doMore }]); 
<td data-bind="contextMenu: menu">

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.