From 592b3eaef75cc849c41590451c7347a3b6880428 Mon Sep 17 00:00:00 2001 From: shayanelhami Date: Wed, 17 Jul 2013 10:07:16 +0100 Subject: [PATCH 1/3] Add feature: dynamic icons --- src/jquery.contextMenu.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/jquery.contextMenu.js b/src/jquery.contextMenu.js index 103a5858..c8c8c472 100755 --- a/src/jquery.contextMenu.js +++ b/src/jquery.contextMenu.js @@ -1076,7 +1076,8 @@ var // currently active contextMenu trigger // add icons if (item.icon) { - $t.addClass("icon icon-" + item.icon); + var icon = ($.isFunction(item.icon)) ? item.icon.call(this, $t, key, item) : item.icon; + $t.addClass("icon icon-" + icon); } } From 4cce9ea4f06f41c270b22391ea22101f33e955d2 Mon Sep 17 00:00:00 2001 From: shayanelhami Date: Wed, 17 Jul 2013 10:20:37 +0100 Subject: [PATCH 2/3] Add feature: dynamic icons --- src/jquery.contextMenu.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/jquery.contextMenu.js b/src/jquery.contextMenu.js index c8c8c472..10d1bbad 100755 --- a/src/jquery.contextMenu.js +++ b/src/jquery.contextMenu.js @@ -1076,8 +1076,8 @@ var // currently active contextMenu trigger // add icons if (item.icon) { - var icon = ($.isFunction(item.icon)) ? item.icon.call(this, $t, key, item) : item.icon; - $t.addClass("icon icon-" + icon); + item._icon = ($.isFunction(item.icon)) ? item.icon.call(this, $t, key, item) : item.icon; + $t.addClass("icon icon-" + item._icon); } } @@ -1150,6 +1150,11 @@ var // currently active contextMenu trigger // dis- / enable item $item[disabled ? 'addClass' : 'removeClass']('disabled'); + + if ($.isFunction(item.icon)) { + $item.removeClass("icon-" + item._icon); + $item.addClass("icon-" + item.icon.call(this, $trigger, key, item)); + } if (item.type) { // dis- / enable input elements From 8b685ce0588efc3957ae99b321bf56d2f1aa520f Mon Sep 17 00:00:00 2001 From: shayanelhami Date: Wed, 17 Jul 2013 11:26:14 +0100 Subject: [PATCH 3/3] Fix: remember _icon on every update --- src/jquery.contextMenu.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/jquery.contextMenu.js b/src/jquery.contextMenu.js index 10d1bbad..1d2a99e8 100755 --- a/src/jquery.contextMenu.js +++ b/src/jquery.contextMenu.js @@ -1153,7 +1153,8 @@ var // currently active contextMenu trigger if ($.isFunction(item.icon)) { $item.removeClass("icon-" + item._icon); - $item.addClass("icon-" + item.icon.call(this, $trigger, key, item)); + item._icon = item.icon.call(this, $trigger, key, item); + $item.addClass("icon-" + item._icon); } if (item.type) {