|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> |
| 5 | + <title>jquery.ui-contextmenu.js - Demo</title> |
| 6 | + <link type="text/css" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/start/jquery-ui.css" /> |
| 7 | + <!-- min requirements: |
| 8 | + <link type="text/css" rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" /> |
| 9 | + <script src="http://code.jquery.com/jquery-1.7.js" type="text/javascript"></script> |
| 10 | + <script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js" type="text/javascript"></script> |
| 11 | +
|
| 12 | + <script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js" type="text/javascript"></script> |
| 13 | + <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js" type="text/javascript"></script> |
| 14 | + --> |
| 15 | + <link rel="stylesheet" href="../../themes/base/jquery.ui.all.css"> |
| 16 | + <script src="../../jquery-ui/jquery-1.10.2.js"></script> |
| 17 | + <script src="../../jquery-ui/ui/jquery.ui.core.js"></script> |
| 18 | + <script src="../../jquery-ui/ui/jquery.ui.widget.js"></script> |
| 19 | + <script src="../../jquery-ui/ui/jquery.ui.position.js"></script> |
| 20 | + <script src="../../jquery-ui/ui/jquery.ui.menu.js"></script> |
| 21 | + |
| 22 | + <!-- Some custom library to enable 'taphold' events --> |
| 23 | + <script src="jquery-taphold/taphold.js" type="text/javascript"></script> |
| 24 | + |
| 25 | + <!-- Custom library to add a dynamic themeroller switcher --> |
| 26 | + <script type="text/javascript" src="../lib/Super-Theme-Switcher/jquery.themeswitcher.js"></script> |
| 27 | + |
| 28 | + <script src="../jquery.ui-contextmenu.js" type="text/javascript"></script> |
| 29 | + |
| 30 | +<style type="text/css"> |
| 31 | + |
| 32 | +/* Some styling */ |
| 33 | + |
| 34 | +body{ |
| 35 | + font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif"; |
| 36 | + font-size: .8em; |
| 37 | + /* Prevent tablets from selecting text on taphold, etc: |
| 38 | + Note: |
| 39 | + If only the potential menu trigger elements should be protected, simply |
| 40 | + use the 'preventSelect: true' option. |
| 41 | + But we disable it more globally for table pcs, because the whole line |
| 42 | + or paragraph will still be selected otherwise. |
| 43 | + */ |
| 44 | + -webkit-user-select: none; |
| 45 | + -khtml-user-select: none; |
| 46 | + -moz-user-select: none; |
| 47 | + -ms-user-select: none; |
| 48 | + user-select: none; |
| 49 | +} |
| 50 | + |
| 51 | +.hasmenu, .hasmenu2 { |
| 52 | + border: 1px solid #008; |
| 53 | + margin: 3px; |
| 54 | + padding: 5px; |
| 55 | + width: 30px; |
| 56 | +} |
| 57 | + |
| 58 | +.ui-widget{ |
| 59 | + font-size: .8em; |
| 60 | +} |
| 61 | +.ui-menu { |
| 62 | + width: 150px; |
| 63 | +} |
| 64 | + |
| 65 | +/* Define a custom icon */ |
| 66 | + |
| 67 | +.ui-icon.custom-icon-firefox { |
| 68 | + background-image: url(application_firefox.gif); |
| 69 | + background-position: 0 0; |
| 70 | +} |
| 71 | +</style> |
| 72 | + |
| 73 | + |
| 74 | +<script type="text/javascript"> |
| 75 | +var CLIPBOARD = ""; |
| 76 | +$(function(){ |
| 77 | + /* Enable a themeroller theme-switching using a combobox. */ |
| 78 | + $("#switcher").themeswitcher({ |
| 79 | + jqueryuiversion: "1", |
| 80 | + imgpath: "../lib/Super-Theme-Switcher/images/", |
| 81 | + loadTheme: "Smoothness" |
| 82 | + }); |
| 83 | + |
| 84 | + /* Menu 1: init by passing an array of entries. */ |
| 85 | + |
| 86 | + $(document).contextmenu({ |
| 87 | + delegate: ".hasmenu", |
| 88 | + preventSelect: true, |
| 89 | + taphold: true, |
| 90 | + menu: [ |
| 91 | + {title: "Cut", cmd: "cut", uiIcon: "ui-icon-scissors"}, |
| 92 | + {title: "Copy", cmd: "copy", uiIcon: "ui-icon-copy"}, |
| 93 | + {title: "Paste", cmd: "paste", uiIcon: "ui-icon-clipboard", disabled: true }, |
| 94 | + {title: "----"}, |
| 95 | + {title: "Menu 1", children: [ |
| 96 | + {title: "Sub 1", cmd: "sub1"}, |
| 97 | + {title: "Sub 2", cmd: "sub2"}, |
| 98 | + {title: "Sub 3", cmd: "sub3"}, |
| 99 | + {title: "Sub 4", cmd: "sub4"}, |
| 100 | + {title: "Sub 5", cmd: "sub5"} |
| 101 | + ]}, |
| 102 | + {title: "Menu 2", children: [ |
| 103 | + {title: "Sub 1", cmd: "sub1"}, |
| 104 | + {title: "Sub 2", cmd: "sub2"}, |
| 105 | + {title: "Sub 3", cmd: "sub3"}, |
| 106 | + {title: "Sub 4", cmd: "sub4"}, |
| 107 | + {title: "Sub 5", cmd: "sub5"} |
| 108 | + ]}, |
| 109 | + {title: "Menu 3", children: [ |
| 110 | + {title: "Sub 1", cmd: "sub1"}, |
| 111 | + {title: "Sub 2", cmd: "sub2"}, |
| 112 | + {title: "Sub 3", cmd: "sub3"}, |
| 113 | + {title: "Sub 4", cmd: "sub4"}, |
| 114 | + {title: "Sub 5", cmd: "sub5"} |
| 115 | + ]} |
| 116 | + ], |
| 117 | + // Handle menu selection to implement a fake-clipboard |
| 118 | + select: function(event, ui) { |
| 119 | + var $target = ui.target; |
| 120 | + switch(ui.cmd){ |
| 121 | + case "copy": |
| 122 | + CLIPBOARD = $target.text(); |
| 123 | + break |
| 124 | + case "paste": |
| 125 | + CLIPBOARD = ""; |
| 126 | + break |
| 127 | + } |
| 128 | + alert("select " + ui.cmd + " on " + $target.text()); |
| 129 | + // Optionally return false, to prevent closing the menu now |
| 130 | + }, |
| 131 | + // Implement the beforeOpen callback to dynamically change the entries |
| 132 | + beforeOpen: function(event, ui) { |
| 133 | + var $menu = ui.menu, |
| 134 | + $target = ui.target; |
| 135 | + $(document) |
| 136 | +// .contextmenu("replaceMenu", [{title: "aaa"}, {title: "bbb"}]) |
| 137 | +// .contextmenu("replaceMenu", "#options2") |
| 138 | +// .contextmenu("setEntry", "cut", {title: "Cuty", uiIcon: "ui-icon-heart", disabled: true}) |
| 139 | + .contextmenu("setEntry", "copy", "Copy '" + $target.text() + "'") |
| 140 | + .contextmenu("setEntry", "paste", "Paste" + (CLIPBOARD ? " '" + CLIPBOARD + "'" : "")) |
| 141 | + .contextmenu("enableEntry", "paste", (CLIPBOARD !== "")); |
| 142 | + |
| 143 | + // Optionally return false, to prevent opening the menu now |
| 144 | + } |
| 145 | + }); |
| 146 | + |
| 147 | + /* Open and close an existing menu without programatically. */ |
| 148 | + |
| 149 | + $("#triggerPopup").click(function(){ |
| 150 | + // Trigger popup menu on the first target element |
| 151 | + $(document).contextmenu("open", $(".hasmenu:first")); |
| 152 | + setTimeout(function(){ |
| 153 | + // $(document).contextmenu("close"); |
| 154 | + }, 2000); |
| 155 | + }); |
| 156 | +}); |
| 157 | +</script> |
| 158 | +</head> |
| 159 | + |
| 160 | +<body class="example"> |
| 161 | + <h1>jquery.ui-contextmenu.js</h1> |
| 162 | + |
| 163 | + <p><a href="https://github.com/mar10/jquery-ui-contextmenu">View project on GitHub</a></p> |
| 164 | + |
| 165 | + <div> |
| 166 | + <label for="switcher">Theme:</label> <div id="switcher"></div> |
| 167 | + <!-- |
| 168 | + <label for="skinswitcher">Skin:</label> <select id="skinswitcher"></select> |
| 169 | + --> |
| 170 | + </div> |
| 171 | + |
| 172 | + <h3>Sample 1</h3> |
| 173 | + <ul> |
| 174 | + <li>Initialized using a command-array. |
| 175 | + <li>Entry 'More - Sub1' uses the callback syntax. |
| 176 | + <li>The menu is modified in the `beforeOpen` event (disabling an renaming entries). |
| 177 | + <li>`preventSelect: true` prevents accidential selection of the menu |
| 178 | + targets (i.e. 'AAA') when double-clicking or dragging the mouse. |
| 179 | + <li>`taphold: true` enables long-press to open the menu (useful on |
| 180 | + tablet computers). |
| 181 | + <li>Ctrl+Click or two-finger-click on the touchpad also works (MacBook). |
| 182 | + </ul> |
| 183 | + <p>Right-click in an element to open the context menu:</p> |
| 184 | + <div> |
| 185 | + <span class="hasmenu">AAA</span> |
| 186 | + <span class="hasmenu">BBB</span> |
| 187 | + <span class="hasmenu">CCC</span> |
| 188 | + </div> |
| 189 | + |
| 190 | + <h3>Sample 3</h3> |
| 191 | + <p>Open context menu using <code>$("#container").contextmenu("open", $(".hasmenu:first"))</code> and close after 2 sec.:</p> |
| 192 | + <button id="triggerPopup">Trigger popup</button> |
| 193 | +</body> |
| 194 | +</html> |
0 commit comments