├── LICENSE ├── README.md ├── demo └── demo.html ├── package.json └── src ├── jquery.nu-context-menu.js └── nu-context-menu.css /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Alex Suyun 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nuContextMenu 2 | A modern context menu with font awesome support for web apps. 3 | The script is extremely light weight (2.2 kB), and it treats the menu as the primary object. 4 | This means that a single menu can be attached to multiple elements. 5 | 6 | # Installation 7 | ``` npm i jquery-nucontextmenu ``` 8 | 9 | # Code Example 10 | ``` javascript 11 | $(function() { 12 | var context = $('#node') 13 | .nuContextMenu({ 14 | 15 | hideAfterClick: true, 16 | 17 | items: '.demo-item', 18 | 19 | callback: function(key, element) { 20 | alert('Clicked ' + key + ' on ' + $(element) 21 | .attr('id')); 22 | }, 23 | 24 | menu: [ 25 | 26 | { 27 | name: 'archive', 28 | title: 'Archive', 29 | icon: 'archive', 30 | }, 31 | 32 | { 33 | name: 'mark', 34 | title: 'Mark as read', 35 | icon: 'check', 36 | }, 37 | 38 | { 39 | name: 'void' 40 | }, 41 | 42 | { 43 | name: 'delete', 44 | title: 'Delete', 45 | icon: 'trash', 46 | }, 47 | ] 48 | 49 | }); 50 | 51 | $('#node') 52 | .append('
Item 5
'); 53 | 54 | // Disable context menu 55 | // context.nuContextMenu('disable'); 56 | 57 | // Remove context menu 58 | // context.nuContextMenu('destroy'); 59 | 60 | }); 61 | ``` 62 | # Screenshots 63 | ![Screenshot] (https://cloud.githubusercontent.com/assets/13611918/10264217/117b0946-69d3-11e5-8914-e00c391065e1.png) 64 | 65 | # License 66 | The MIT License (MIT) 67 | 68 | Copyright (c) 2015 Alex Suyun 69 | 70 | Permission is hereby granted, free of charge, to any person obtaining a copy 71 | of this software and associated documentation files (the "Software"), to deal 72 | in the Software without restriction, including without limitation the rights 73 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 74 | copies of the Software, and to permit persons to whom the Software is 75 | furnished to do so, subject to the following conditions: 76 | 77 | The above copyright notice and this permission notice shall be included in all 78 | copies or substantial portions of the Software. 79 | 80 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 81 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 82 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 83 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 84 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 85 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 86 | SOFTWARE. 87 | -------------------------------------------------------------------------------- /demo/demo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | nuContextMenu Demo Page 9 | 10 | 11 | 81 | 82 | 83 | 84 |
85 |
86 |
Item 1
87 |
Item 2
88 |
Item 3
89 |
Item 4
90 |
91 |
92 | 93 | 94 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery-nucontextmenu", 3 | "version": "0.1.3", 4 | "description": "Modern context menu with font awesome support for web apps (jQuery Plugin).", 5 | "main": "src/jquery.nu-context-menu.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git@github.com:avxto/nuContextMenu.git" 12 | }, 13 | "author": "avxto" 14 | } 15 | -------------------------------------------------------------------------------- /src/jquery.nu-context-menu.js: -------------------------------------------------------------------------------- 1 | /** 2 | * nuContextMenu - jQuery Plugin 3 | * Copyright (c) 2015, Alex Suyun 4 | * Copyrights licensed under The MIT License (MIT) 5 | */ 6 | ; 7 | (function($, window, document, undefined) { 8 | 9 | 'use strict'; 10 | 11 | var plugin = 'nuContextMenu'; 12 | 13 | var defaults = { 14 | hideAfterClick: false, 15 | contextMenuClass: 'nu-context-menu', 16 | activeClass: 'active' 17 | }; 18 | 19 | var nuContextMenu = function(container, options) { 20 | this.container = $(container); 21 | this.options = $.extend({}, defaults, options); 22 | this._defaults = defaults; 23 | this._name = plugin; 24 | this.init(); 25 | }; 26 | 27 | $.extend(nuContextMenu.prototype, { 28 | init: function() { 29 | 30 | if (this.options.items) { 31 | this.items = $(this.options.items); 32 | } 33 | 34 | if (this._buildContextMenu()) { 35 | this._bindEvents(); 36 | this._menuVisible = this._menu.hasClass(this.options.activeClass); 37 | } 38 | }, 39 | 40 | _getCallback: function() { 41 | return ((this.options.callback && typeof this.options.callback === 42 | 'function') ? this.options.callback : function() {}); 43 | }, 44 | 45 | _buildContextMenu: function() { 46 | 47 | // Create context menu 48 | this._menu = $('
') 49 | .addClass(this.options.contextMenuClass) 50 | .append('