Skip to content

Commit b5ba010

Browse files
committed
Add support for newer versions of Font Awesome, it now created an <i> element when font-awesome 5 classes are detected. This also enabled creating a new element as return value for the icon callback for extra flexibility. Relates to issue #593
1 parent d024bee commit b5ba010

17 files changed

+124
-35
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## Changelog ##
22

3+
### Unreleased
4+
5+
#### Added
6+
7+
* Added support for Font Awesome 5 ([Issue #593](https://github.com/swisnl/jQuery-contextMenu/issues/593)), ([Issue #593](https://github.com/swisnl/jQuery-contextMenu/issues/593))
8+
39
### 2.6.4
410

511
#### Fixed

dist/font/context-menu-icons.eot

0 Bytes
Binary file not shown.

dist/font/context-menu-icons.ttf

0 Bytes
Binary file not shown.

dist/font/context-menu-icons.woff

0 Bytes
Binary file not shown.

dist/font/context-menu-icons.woff2

4 Bytes
Binary file not shown.

dist/jquery.contextMenu.css

+20-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Licensed under
1313
* MIT License http://www.opensource.org/licenses/mit-license
1414
*
15-
* Date: 2018-03-16T11:13:46.072Z
15+
* Date: 2018-07-10T10:17:15.670Z
1616
*/
1717
@-webkit-keyframes cm-spin {
1818
0% {
@@ -54,8 +54,8 @@
5454
font-style: normal;
5555
font-weight: normal;
5656

57-
src: url("font/context-menu-icons.eot?1s39y");
58-
src: url("font/context-menu-icons.eot?1s39y#iefix") format("embedded-opentype"), url("font/context-menu-icons.woff2?1s39y") format("woff2"), url("font/context-menu-icons.woff?1s39y") format("woff"), url("font/context-menu-icons.ttf?1s39y") format("truetype");
57+
src: url("font/context-menu-icons.eot?camk");
58+
src: url("font/context-menu-icons.eot?camk#iefix") format("embedded-opentype"), url("font/context-menu-icons.woff2?camk") format("woff2"), url("font/context-menu-icons.woff?camk") format("woff"), url("font/context-menu-icons.ttf?camk") format("truetype");
5959
}
6060

6161
.context-menu-icon-add:before {
@@ -157,6 +157,23 @@
157157
color: #bbb;
158158
}
159159

160+
.context-menu-icon.context-menu-icon--fa5 {
161+
display: list-item;
162+
font-family: inherit;
163+
line-height: inherit;
164+
}
165+
.context-menu-icon.context-menu-icon--fa5 i {
166+
position: absolute;
167+
left: .5em;
168+
color: #2980b9;
169+
}
170+
.context-menu-icon.context-menu-icon--fa5.context-menu-hover i {
171+
color: #fff;
172+
}
173+
.context-menu-icon.context-menu-icon--fa5.context-menu-disabled i {
174+
color: #bbb;
175+
}
176+
160177
.context-menu-list {
161178
position: absolute;
162179
display: inline-block;

dist/jquery.contextMenu.js

+29-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Licensed under
1212
* MIT License http://www.opensource.org/licenses/mit-license
1313
*
14-
* Date: 2018-03-16T11:13:45.992Z
14+
* Date: 2018-07-10T10:17:15.594Z
1515
*/
1616

1717
// jscs:disable
@@ -116,7 +116,7 @@
116116
// flag denoting if a second trigger should simply move (true) or rebuild (false) an open menu
117117
// as long as the trigger happened on one of the trigger-element's child nodes
118118
reposition: true,
119-
// Flag denoting if a second trigger should close the menu, as long as
119+
// Flag denoting if a second trigger should close the menu, as long as
120120
// the trigger happened on one of the trigger-element's child nodes.
121121
// This overrides the reposition option.
122122
hideOnSecondTrigger: false,
@@ -466,12 +466,12 @@
466466
$(target).trigger(e);
467467
root.$layer.show();
468468
}
469-
469+
470470
if (root.hideOnSecondTrigger && triggerAction && root.$menu !== null && typeof root.$menu !== 'undefined') {
471471
root.$menu.trigger('contextmenu:hide');
472472
return;
473473
}
474-
474+
475475
if (root.reposition && triggerAction) {
476476
if (document.elementFromPoint) {
477477
if (root.$trigger.is(target)) {
@@ -1001,7 +1001,7 @@
10011001
// position and show context menu
10021002
opt.$menu.css(css)[opt.animation.show](opt.animation.duration, function () {
10031003
$trigger.trigger('contextmenu:visible');
1004-
1004+
10051005
op.activated(opt);
10061006
opt.events.activated(opt);
10071007
});
@@ -1213,9 +1213,7 @@
12131213
$t.addClass('context-menu-separator ' + root.classNames.notSelectable);
12141214
} else if (item.type === 'html') {
12151215
$t.addClass('context-menu-html ' + root.classNames.notSelectable);
1216-
} else if (item.type === 'sub') {
1217-
// We don't want to execute the next else-if if it is a sub.
1218-
} else if (item.type) {
1216+
} else if (item.type !== 'sub' && item.type) {
12191217
$label = $('<label></label>').appendTo($t);
12201218
createNameNode(item).appendTo($label);
12211219

@@ -1330,14 +1328,27 @@
13301328
if ($.isFunction(item.icon)) {
13311329
item._icon = item.icon.call(this, this, $t, key, item);
13321330
} else {
1333-
if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
1331+
if (typeof(item.icon) === 'string' && (
1332+
item.icon.substring(0, 4) === 'fab '
1333+
|| item.icon.substring(0, 4) === 'fas '
1334+
|| item.icon.substring(0, 4) === 'far '
1335+
|| item.icon.substring(0, 4) === 'fal ')
1336+
) {
13341337
// to enable font awesome
1338+
$t.addClass(root.classNames.icon + ' ' + root.classNames.icon + '--fa5');
1339+
item._icon = $('<i class="' + item.icon + '"></i>');
1340+
} else if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
13351341
item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
13361342
} else {
13371343
item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
13381344
}
13391345
}
1340-
$t.addClass(item._icon);
1346+
1347+
if(typeof(item._icon) === "string"){
1348+
$t.addClass(item._icon);
1349+
} else {
1350+
$t.prepend(item._icon);
1351+
}
13411352
}
13421353
}
13431354

@@ -1433,8 +1444,13 @@
14331444

14341445
if ($.isFunction(item.icon)) {
14351446
$item.removeClass(item._icon);
1436-
item._icon = item.icon.call(this, $trigger, $item, key, item);
1437-
$item.addClass(item._icon);
1447+
var iconResult = item.icon.call(this, $trigger, $item, key, item);
1448+
if(typeof(iconResult) === "string"){
1449+
$item.addClass(iconResult);
1450+
} else {
1451+
$item.prepend(iconResult);
1452+
}
1453+
delete iconResult;
14381454
}
14391455

14401456
if (item.type) {
@@ -1565,7 +1581,7 @@
15651581
$menu.css({
15661582
'top': '0px'
15671583
});
1568-
}
1584+
}
15691585
}
15701586
};
15711587

dist/jquery.contextMenu.min.css

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)