GithubHelp home page GithubHelp logo

mikesir87 / ng-context-menu Goto Github PK

View Code? Open in Web Editor NEW

This project forked from slively/ng-context-menu

0.0 2.0 0.0 549 KB

An AngularJS directive to display a context menu when a right-click event is triggered.

Home Page: http://ianwalter.github.io/ng-context-menu/

License: MIT License

JavaScript 96.25% HTML 3.22% CSS 0.52%

ng-context-menu's Introduction

An AngularJS directive to display a context menu when a right-click event is triggered

Looking for a new owner/maintainer

Please email me (my email is on my profile page: https://github.com/ianwalter)


Code Climate Circle CI


Implementation steps

Step 1: Install ng-context-menu

Install using Bower:

bower install ng-context-menu --save

Include ng-context-menu.min.js in your app.

Step 2: Load the ng-context-menu module

var app = angular.module('menu-demo', ['ngRoute', 'ng-context-menu'])

Step 3: Add the context-menu directive to a DOM element

Note that the data-target attribute value must match the id of the menu in the next step.

<div context-menu class="panel panel-default position-fixed"
     data-target="menu-{{ $index }}"
     ng-class="{ 'highlight': highlight, 'expanded' : expanded }">
  ...
</div>

Step 4: Add the markup of the menu you want to be displayed

Customize the menu to your needs. It may look something like:

<div class="dropdown position-fixed" id="menu-{{ $index }}">
  <ul class="dropdown-menu" role="menu">
    <li>
      <a class="pointer" role="menuitem" tabindex="1"
         ng-click="panel.highlight = true">
         Select Panel {{ $index + 1 }}
      </a>
    </li>
    <li>
      <a class="pointer" role="menuitem" tabindex="2"
         ng-click="panel.highlight = false">
         Deselect Panel  {{ $index + 1 }}
      </a>
    </li>
    <li>
      <a class="pointer" role="menuitem" tabindex="3"
         ng-click="panel.expanded = true">
         Expand Panel {{ $index + 1 }}
      </a>
    </li>
    <li>
      <a class="pointer" role="menuitem" tabindex="4"
         ng-click="panel.expanded = false">
         Contract Panel {{ $index + 1 }}
      </a>
    </li>
    <li>
      <a class="pointer" role="menuitem" tabindex="5"
         ng-click="addPanel()">
         Add a panel
      </a>
    </li>
    <li>
      <a href="https://github.com/ianwalter/ng-context-menu"
         role="menuitem"
         tabindex="-1">
         ng-context-menu on GitHub
      </a>
    </li>
  </ul>
</div>

Step 5: Make sure your menu is has the position: fixed CSS property

As you can see in the demo, I just created a class called position-fixed and added the property:

.position-fixed {
  position: fixed;
}

Options

Disabling the contextmenu

If you need to disable the contextmenu in certain circumstances, you can add an expression to the context-menu-disabled attribute. If the expression evaluates to true, the contextmenu will be disabled, for example, context-menu-disabled="1 === 1"

Open callback

You can add a callback function to the context-menu property which will be called when the menu is opened:

<div context-menu="onShow()">
<!-- ... -->
</div>

Close callback

Add the following attribute to the context-menu element: context-menu-close which should be a function that will be called whenever the context menu is closed.

<div context-menu context-menu-close="onClose()">
<!-- ... -->
</div>

Margin bottom

Add the following attribute to the context-menu element: context-menu-margin-bottom to keep the context menu away from the bottom of the page at least by this attribute value in pixels.

<div context-menu context-menu-margin-bottom="10">
<!-- ... -->
</div>


I hope you find this useful!
โŒ Ian

ng-context-menu's People

Contributors

busterbeans avatar hypercubed avatar jrobic avatar notherdev avatar andrewburgess avatar bitdeli-chef avatar mikesir87 avatar mkefd avatar tilt avatar alexk111 avatar coolweb avatar hupfis avatar

Watchers

 avatar James Cloos avatar

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.