Skip to content
This repository was archived by the owner on Aug 14, 2021. It is now read-only.

Commit da26cea

Browse files
committed
setEntry() supports creating nested menus
Close #80
1 parent 88b4afd commit da26cea

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# 1.7.1-0 / Unreleased
2+
* [FEATURE] #80 setEntry() supports creating nested menus
3+
* [BUGFIX] entry data attached to parentLi instead of `<a>`
24
* Use jscs
35

46
# 1.7.0 / 2014-09-09

MIT-LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2014 Martin Wendt and others (see commiter list on GitHub)
1+
Copyright 2013-2014 Martin Wendt and others (see commiter list on GitHub)
22
https://github.com/mar10/jquery-ui-contextmenu
33

44
Permission is hereby granted, free of charge, to any person obtaining

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ See also the [Change Log](https://github.com/mar10/jquery-ui-contextmenu/blob/ma
2828

2929
First, include dependencies, i.e.
3030

31-
* jQuery 1.7+ (1.10 recommended)
32-
* jQuery UI 1.9+ (at least core, widhet, menu), 1.11 recommended
31+
* jQuery 1.7+ (1.10 or later recommended)
32+
* jQuery UI 1.9+ (at least core, widget, menu), 1.11 recommended
3333
* One of the ThemeRoller CSS themes or a custom one
3434
* jquery.ui-contextmenu.js (also [available as CDN](http://www.jsdelivr.com/#!jquery.ui-contextmenu))
3535

3636
```html
3737
<head>
38-
<link href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" type="text/css" rel="stylesheet" />
38+
<link href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" type="text/css" rel="stylesheet" />
3939
<script src="//code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
40-
<script src="//code.jquery.com/ui/1.11.1/jquery-ui.min.js" type="text/javascript"></script>
40+
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.min.js" type="text/javascript"></script>
4141
<script src="assets/jquery.ui-contextmenu.min.js"></script>
4242
```
4343

demo/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
55
<title>jquery.ui-contextmenu.js - Demo</title>
66

7-
<link href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" type="text/css" rel="stylesheet" />
7+
<link href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" type="text/css" rel="stylesheet" />
88
<script src="//code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
9-
<script src="//code.jquery.com/ui/1.11.1/jquery-ui.min.js" type="text/javascript"></script>
9+
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.min.js" type="text/javascript"></script>
1010

1111
<!-- Optional custom library to enable 'taphold' events -->
1212
<script src="jquery-taphold/taphold.js" type="text/javascript"></script>
@@ -67,7 +67,7 @@
6767
$(function(){
6868
/* Enable a themeroller theme-switching using a combobox. */
6969
$("#switcher").themeswitcher({
70-
jqueryuiversion: "1.11.1",
70+
jqueryuiversion: "1.11.2",
7171
themepath: "//code.jquery.com/ui/",
7272
imgpath: "../lib/Super-Theme-Switcher/images/",
7373
loadTheme: "Smoothness"

jquery.ui-contextmenu.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* @see https://github.com/mar10/jquery-ui-contextmenu
77
*
8-
* Copyright (c) 2014, Martin Wendt (http://wwWendt.de). Licensed MIT.
8+
* Copyright (c) 2013-2014, Martin Wendt (http://wwWendt.de). Licensed MIT.
99
*/
1010

1111
(function( factory ) {
@@ -301,15 +301,21 @@ $.widget("moogle.contextmenu", {
301301
this._createUiMenu(data);
302302
},
303303
/** Redefine menu entry (title or all of it). */
304-
setEntry: function(cmd, titleOrData) {
305-
var $entry = this._getMenuEntry(cmd);
304+
setEntry: function(cmd, entry) {
305+
var $ul,
306+
$entryLi = this._getMenuEntry(cmd);
306307

307-
if (typeof titleOrData === "string") {
308-
$.moogle.contextmenu.updateTitle($entry, titleOrData);
308+
if (typeof entry === "string") {
309+
$.moogle.contextmenu.updateTitle($entryLi, entry);
309310
} else {
310-
$entry.empty();
311-
titleOrData.cmd = titleOrData.cmd || cmd;
312-
$.moogle.contextmenu.createEntryMarkup(titleOrData, $entry);
311+
$entryLi.empty();
312+
entry.cmd = entry.cmd || cmd;
313+
$.moogle.contextmenu.createEntryMarkup(entry, $entryLi);
314+
if ($.isArray(entry.children)) {
315+
$ul = $("<ul/>").appendTo($entryLi);
316+
$.moogle.contextmenu.createMenuMarkup(entry.children, $ul);
317+
}
318+
this.getMenu().menu("refresh");
313319
}
314320
},
315321
/** Show or hide the menu command. */
@@ -341,7 +347,7 @@ $.extend($.moogle.contextmenu, {
341347
}
342348
return $parentUl;
343349
},
344-
/** Replaces the value of elem's first text node child*/
350+
/** Replaces the value of elem's first text node child */
345351
replaceFirstTextNodeChild: function(elem, text) {
346352
elem
347353
.contents()

0 commit comments

Comments
 (0)