├── .gitignore ├── assets ├── logo.jpg ├── demo-pic.jpeg └── context-menu.png ├── src ├── angel-styles.min.css ├── angel-styles.css ├── angelfire.min.js └── angelfire.js ├── LICENSE ├── demo ├── index.html └── app.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /assets/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rish-16/Angelfire/HEAD/assets/logo.jpg -------------------------------------------------------------------------------- /assets/demo-pic.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rish-16/Angelfire/HEAD/assets/demo-pic.jpeg -------------------------------------------------------------------------------- /assets/context-menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rish-16/Angelfire/HEAD/assets/context-menu.png -------------------------------------------------------------------------------- /src/angel-styles.min.css: -------------------------------------------------------------------------------- 1 | .menu{font-family:Avenir Next,Arial,Helvetica,sans-serif;min-width:150px;width:auto;z-index:1000;box-shadow:1px 1px 5px rgba(0,0,0,.2);position:fixed;display:none;background-color:#fff;border-radius:7px;overflow:hidden}.menu-options{list-style:none;padding:5px 0;z-index:1}.menu-option{font-weight:500;z-index:1;font-size:14px;padding:10px 0 10px 20px;cursor:pointer}.menu-option:hover{background:rgba(0,0,0,.2);transition:.5s} -------------------------------------------------------------------------------- /src/angel-styles.css: -------------------------------------------------------------------------------- 1 | .menu { 2 | font-family: Avenir Next, Arial, Helvetica, sans-serif; 3 | min-width: 150px; 4 | width: auto; 5 | z-index: 1000; 6 | box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2); 7 | position: fixed; 8 | display: none; 9 | background-color: white; 10 | border-radius: 7px; 11 | overflow: hidden; 12 | } 13 | 14 | .menu-options { 15 | list-style: none; 16 | padding: 5px 0; 17 | z-index: 1; 18 | } 19 | 20 | .menu-option { 21 | font-weight: 500; 22 | z-index: 1; 23 | font-size: 14px; 24 | padding: 10px 0 10px 20px; 25 | cursor: pointer; 26 | } 27 | 28 | .menu-option:hover { 29 | background: rgba(0, 0, 0, 0.2); 30 | transition: 0.5s; 31 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Rishabh Anand 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 | -------------------------------------------------------------------------------- /demo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 |Right click the image and text below:
37 |This is some text
42 | 43 | 44 | -------------------------------------------------------------------------------- /demo/app.js: -------------------------------------------------------------------------------- 1 | document.addEventListener("DOMContentLoaded", () => { 2 | console.log("App loaded") 3 | 4 | var img = document.getElementById("prof-pic") 5 | const text = document.getElementById("text") 6 | 7 | var angelfire = new Angelfire() 8 | 9 | var config = { 10 | "options": [ 11 | { 12 | "name": "Profile", 13 | "event": function() { 14 | alert("Profile clicked!") 15 | }, 16 | "styles": { 17 | "color": "royalblue" 18 | }, 19 | "onHover": { 20 | "opacity": 0.5, 21 | "background": "none", 22 | "transition": "0.5s", 23 | } 24 | }, 25 | { 26 | "name": "New Post", 27 | "event": function() { 28 | alert("New Post clicked!") 29 | } 30 | }, 31 | { 32 | "name": "Settings", 33 | "event": function() { 34 | alert("Settings clicked!") 35 | } 36 | } 37 | ], 38 | } 39 | 40 | var config2 = { 41 | "options": [ 42 | { 43 | "name": "Copy", 44 | "event": function() { 45 | alert("Copy text") 46 | } 47 | }, 48 | { 49 | "name": "Delete", 50 | "event": function() { 51 | alert("Delete text") 52 | } 53 | }, 54 | { 55 | "name": "Colour", 56 | "event": function() { 57 | alert("Choose colour") 58 | } 59 | }, 60 | { 61 | "name": "Duplicate", 62 | "event": function() { 63 | alert("Duplicate text") 64 | } 65 | } 66 | ] 67 | } 68 | 69 | angelfire.addMenu(img, config) 70 | angelfire.addMenu(text, config2) 71 | }) -------------------------------------------------------------------------------- /src/angelfire.min.js: -------------------------------------------------------------------------------- 1 | function makeid(length){var result='';var characters='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';var charactersLength=characters.length;for(var i=0;iAdd custom context menus to any webpage element with minimal coding!!!
4 |Made by Rishabh Anand for NUS Hackers OpenHack 2020
5 |🏆 Winning Submission
6 | 7 | 11 | 12 | --- 13 | 14 | ### What is it? 15 | 16 | > `Angelfire` lets you quickly build right-click-enabled context menus and drop-down menus for any element on your webpage. 17 | 18 | Check it out on the [demo page](https://af-demo.netlify.app/). 19 | 20 | **What Are Context Menus?** 21 | 22 | A context menu is what shows up when you right-click something on a webpage. It usually contains actions that can be performed on the selected element. 23 | 24 |
25 |
26 |
97 |
98 | ---
99 |
100 | ### Customisability
101 |
102 | `Angelfire` allows you to create fully-customisable context menus. In your `config` object, you can specify the key `menu-styles`:
103 |
104 | ```javascript
105 |
106 | var config = {
107 | "options": [...], // menu options
108 | "menu-styles": {
109 | "background-color": "red",
110 | "textColor": "white",
111 | }
112 | }
113 |
114 | ```
115 |
116 | **Here's a list of all valid `menu-styles` properties you can control:**
117 |
118 | | Property | Description | Default (if any) |
119 | |---------------------|---------------------------|---------------------------------------------------|
120 | | `background-color` | Background color of menu | `white` |
121 | | `color` | Colour of all options | `black` |
122 | | `border` | Adjust border around menu | `none` |
123 | | `border-radius` | Border curvature of menu | `7px` |
124 | | `width` | Width of menu | Minimum `150px`; Auto-adjusting based on content |
125 | | `box-shadow` | Shadow under menu | `1px 1px 5px rgba(0, 0, 0, 0.2)` |
126 |
127 | > **Note:** If you want support for more custom styles, leave an issue!
128 |
129 | You can also control styles for individual options by adding the `styles` and `onHover` properties to the options in the `config` object:
130 |
131 | ```javascript
132 |
133 | var config = {
134 | "options": [
135 | {
136 | "name": "Profile",
137 | "event": function() {...},
138 | "styles": { // CSS props
139 | "color": "royalblue",
140 | "background-color": "lightgray"
141 | },
142 | "onHover": { // on hover event
143 | "opacity": 0.5,
144 | "color": "gold"
145 | }
146 | },
147 | {
148 | "name": "Settings",
149 | "event": function() {...},
150 | "styles": { // anything you can do with markup text, you can do here!
151 | "color": "rebeccapurple",
152 | "font-size": "15px",
153 | "font-weight": 600
154 | }
155 | }
156 | ],
157 | "menu-styles": {...}
158 | }
159 |
160 | ```
161 |
162 | > **Note:** If you want support for more custom styles, leave an [issue](https://github.com/rish-16/Angelfire/issues)!
163 |
164 | ---
165 |
166 | ### TO-DOs
167 |
168 | There's still a lot to do with the library. Here are some future plans I have with it:
169 |
170 | - Add sub-menu support
171 | - Key-press option selection
172 | - Add icon/image support for options
173 | - Adding sections in menu
174 |
175 | ---
176 |
177 | ### License
178 |
179 | [MIT](https://github.com/rish-16/Angelfire/blob/master/LICENSE)
180 |
--------------------------------------------------------------------------------