Skip to content

Commit 4eb55f7

Browse files
committed
Load icon and check if menu is visible when resolving promise.
1 parent 9780b66 commit 4eb55f7

16 files changed

+162
-46
lines changed

dist/font/context-menu-icons.eot

132 Bytes
Binary file not shown.

dist/font/context-menu-icons.ttf

132 Bytes
Binary file not shown.

dist/font/context-menu-icons.woff

104 Bytes
Binary file not shown.

dist/font/context-menu-icons.woff2

92 Bytes
Binary file not shown.

dist/jquery.contextMenu.css

+47-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*!
33
* jQuery contextMenu - Plugin for simple contextMenu handling
44
*
5-
* Version: v2.2.5-dev
5+
* Version: v2.2.4
66
*
77
* Authors: Björn Brala (SWIS.nl), Rodney Rehm, Addy Osmani (patches for FF)
88
* Web: http://swisnl.github.io/jQuery-contextMenu/
@@ -12,15 +12,15 @@
1212
* Licensed under
1313
* MIT License http://www.opensource.org/licenses/mit-license
1414
*
15-
* Date: 2016-10-11T14:21:45.355Z
15+
* Date: 2016-10-24T14:22:19.667Z
1616
*/
1717
@font-face {
1818
font-family: "context-menu-icons";
1919
font-style: normal;
2020
font-weight: normal;
2121

22-
src: url("font/context-menu-icons.eot?4pl8q");
23-
src: url("font/context-menu-icons.eot?4pl8q#iefix") format("embedded-opentype"), url("font/context-menu-icons.woff2?4pl8q") format("woff2"), url("font/context-menu-icons.woff?4pl8q") format("woff"), url("font/context-menu-icons.ttf?4pl8q") format("truetype");
22+
src: url("font/context-menu-icons.eot?386c8");
23+
src: url("font/context-menu-icons.eot?386c8#iefix") format("embedded-opentype"), url("font/context-menu-icons.woff2?386c8") format("woff2"), url("font/context-menu-icons.woff?386c8") format("woff"), url("font/context-menu-icons.ttf?386c8") format("truetype");
2424
}
2525

2626
.context-menu-icon-add:before {
@@ -43,14 +43,49 @@
4343
content: "\EA05";
4444
}
4545

46-
.context-menu-icon-paste:before {
46+
.context-menu-icon-loading:before {
4747
content: "\EA06";
4848
}
4949

50-
.context-menu-icon-quit:before {
50+
.context-menu-icon-paste:before {
5151
content: "\EA07";
5252
}
5353

54+
.context-menu-icon-quit:before {
55+
content: "\EA08";
56+
}
57+
58+
@-webkit-keyframes cm-spin {
59+
0% {
60+
-webkit-transform: translateY(-50%) rotate(0deg);
61+
}
62+
100% {
63+
-webkit-transform: translateY(-50%) rotate(359deg);
64+
}
65+
}
66+
67+
@-o-keyframes cm-spin {
68+
0% {
69+
-o-transform: translateY(-50%) rotate(0deg);
70+
}
71+
100% {
72+
-o-transform: translateY(-50%) rotate(359deg);
73+
}
74+
}
75+
76+
@keyframes cm-spin {
77+
0% {
78+
-webkit-transform: translateY(-50%) rotate(0deg);
79+
-o-transform: translateY(-50%) rotate(0deg);
80+
transform: translateY(-50%) rotate(0deg);
81+
}
82+
100% {
83+
-webkit-transform: translateY(-50%) rotate(359deg);
84+
-o-transform: translateY(-50%) rotate(359deg);
85+
transform: translateY(-50%) rotate(359deg);
86+
}
87+
}
88+
5489
.context-menu-icon::before {
5590
position: absolute;
5691
top: 50%;
@@ -80,6 +115,12 @@
80115
color: #bbb;
81116
}
82117

118+
.context-menu-icon.context-menu-icon-loading:before {
119+
-webkit-animation: cm-spin 2s infinite;
120+
-o-animation: cm-spin 2s infinite;
121+
animation: cm-spin 2s infinite;
122+
}
123+
83124
.context-menu-icon.context-menu-icon--fa {
84125
display: list-item;
85126
}

dist/jquery.contextMenu.js

+40-24
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
2-
* jQuery contextMenu v2.2.5-dev - Plugin for simple contextMenu handling
2+
* jQuery contextMenu v2.2.4 - Plugin for simple contextMenu handling
33
*
4-
* Version: v2.2.5-dev
4+
* Version: v2.2.4
55
*
66
* Authors: Björn Brala (SWIS.nl), Rodney Rehm, Addy Osmani (patches for FF)
77
* Web: http://swisnl.github.io/jQuery-contextMenu/
@@ -12,7 +12,7 @@
1212
* MIT License http://www.opensource.org/licenses/mit-license
1313
* GPL v3 http://opensource.org/licenses/GPL-3.0
1414
*
15-
* Date: 2016-10-11T14:22:42.163Z
15+
* Date: 2016-10-24T14:31:11.197Z
1616
*/
1717

1818
(function (factory) {
@@ -1236,15 +1236,20 @@
12361236
item.appendTo = item.$node;
12371237
$t.data('contextMenu', item).addClass('context-menu-submenu');
12381238
item.callback = null;
1239-
//if item contains items, and this is a promise, we should create it later
1240-
//check if subitems is of type promise. If it is a promise we need to create it later, after promise has been resolved
1241-
if ('function' === typeof item.items.then) {
1242-
// probably a promise, process it, when completed it will create the sub menu's.
1243-
op.processPromises(item, root, item.items);
1244-
} else {
1245-
// normal submenu.
1246-
op.create(item, root);
1247-
}
1239+
1240+
// If item contains items, and this is a promise, we should create it later
1241+
// check if subitems is of type promise. If it is a promise we need to create
1242+
// it later, after promise has been resolved.
1243+
if ('function' === typeof item.items.then) {
1244+
// probably a promise, process it, when completed it will create the sub menu's.
1245+
// @todo Add a loading class to the item so you know it is loading.
1246+
1247+
1248+
op.processPromises(item, root, item.items);
1249+
} else {
1250+
// normal submenu.
1251+
op.create(item, root);
1252+
}
12481253
break;
12491254

12501255
case 'html':
@@ -1428,34 +1433,45 @@
14281433
return $layer;
14291434
},
14301435
processPromises: function (opt, root, promise) {
1436+
// Start
1437+
opt.$node.addClass('context-menu-icon-loading');
1438+
1439+
14311440
function completedPromise(opt,root,items) {
1432-
//completed promise (dev called promise.resolve)
1433-
//we now have a list of items which can be used to create the rest of the context menu.
1441+
// Completed promise (dev called promise.resolve). We now have a list of items which can
1442+
// be used to create the rest of the context menu.
14341443
if (items === undefined) {
1435-
//meh, null result, dev should have checked
1444+
// Null result, dev should have checked
14361445
errorPromise(undefined);//own error object
14371446
}
14381447
finishPromiseProcess(opt,root, items);
14391448
};
14401449
function errorPromise(opt,root,errorItem) {
1441-
//user called promise.reject() with an error item, if not, provide own error item.
1450+
console.log('error')
1451+
// User called promise.reject() with an error item, if not, provide own error item.
14421452
if (errorItem === undefined) {
14431453
errorItem = { "error": { name: "No items and no error item", icon: "context-menu-icon context-menu-icon-quit" } };
14441454
if (window.console) {
14451455
(console.error || console.log).call(console, 'When you reject a promise, provide an "items" object, equal to normal sub-menu items');
14461456
}
1447-
}else if(typeof errorItem === 'string'){
1448-
errorItem = { "error": { name: errorItem } };
1449-
}
1457+
} else if(typeof errorItem === 'string'){
1458+
errorItem = { "error": { name: errorItem } };
1459+
}
14501460
finishPromiseProcess(opt,root,errorItem);
14511461
};
14521462
function finishPromiseProcess(opt,root,items) {
1453-
opt.items = items;//override promise to items.
1454-
op.create(opt, root, true);//create submenu
1455-
op.update(opt, root);//correctly update position if user is already hovered over menu item
1456-
root.positionSubmenu.call(opt.$node, opt.$menu); //positionSubmenu, will only do anything if user already hovered over menu item that just got new subitems.
1463+
if(root.$menu === undefined || !root.$menu.is(':visible')){
1464+
return;
1465+
}
1466+
opt.$node.removeClass('context-menu-icon-loading');
1467+
opt.items = items; // Override promise to items.
1468+
op.create(opt, root, true); // Create submenu
1469+
op.update(opt, root); // Correctly update position if user is already hovered over menu item
1470+
root.positionSubmenu.call(opt.$node, opt.$menu); // positionSubmenu, will only do anything if user already hovered over menu item that just got new subitems.
14571471
};
1458-
//wait for promise completion. .then(success, error, notify) (we don't track notify). Bind the opt and root to avoid scope problems
1472+
1473+
// Wait for promise completion. .then(success, error, notify) (we don't track notify). Bind the opt
1474+
// and root to avoid scope problems
14591475
promise.then(completedPromise.bind(this, opt, root), errorPromise.bind(this, opt, root));
14601476
}
14611477
};

dist/jquery.contextMenu.min.css

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

0 commit comments

Comments
 (0)