Skip to content

Commit d685eea

Browse files
Luke Brassardbbrala
Luke Brassard
authored andcommitted
adding option for menu item name to use html() instead of text() (#388)
* adding option for menu item name to use html() instead of text() * adding documentation and error-handling for isHtmlName option
1 parent 17133c1 commit d685eea

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

documentation/docs/items.md

+22
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,28 @@ var items = {
5959
```
6060

6161

62+
### isHtmlName
63+
64+
When truthy, the defined `name` value is HTML.
65+
66+
The value will be rendered using `$.html()` instead of `$.text()`.
67+
68+
__Note: Cannot be used with the [accesskey](#accesskey) option in the same item.__
69+
70+
`isHtmlName`: `boolean`
71+
72+
#### Example
73+
74+
```javascript
75+
var items = {
76+
firstCommand: {
77+
name: "Copy <span style='font-weight: bold'>Text</span>︎",
78+
isHtmlName: true
79+
}
80+
}
81+
```
82+
83+
6284
### callback
6385

6486
Specifies the callback to execute if clicked on

src/jquery.contextMenu.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,15 @@
10871087
$name.append(document.createTextNode(item._afterAccesskey));
10881088
}
10891089
} else {
1090-
$name.text(item.name);
1090+
if (item.isHtmlName) {
1091+
// restrict use with access keys
1092+
if (typeof item.accesskey !== 'undefined') {
1093+
throw new Error('accesskeys are not compatible with HTML names and cannot be used together in the same item');
1094+
}
1095+
$name.html(item.name);
1096+
} else {
1097+
$name.text(item.name);
1098+
}
10911099
}
10921100
return $name;
10931101
}

0 commit comments

Comments
 (0)