|
1 | 1 | /*!
|
2 |
| - * jQuery contextMenu v2.2.5-dev - Plugin for simple contextMenu handling |
| 2 | + * jQuery contextMenu v2.2.4 - Plugin for simple contextMenu handling |
3 | 3 | *
|
4 |
| - * Version: v2.2.5-dev |
| 4 | + * Version: v2.2.4 |
5 | 5 | *
|
6 | 6 | * Authors: Björn Brala (SWIS.nl), Rodney Rehm, Addy Osmani (patches for FF)
|
7 | 7 | * Web: http://swisnl.github.io/jQuery-contextMenu/
|
|
12 | 12 | * MIT License http://www.opensource.org/licenses/mit-license
|
13 | 13 | * GPL v3 http://opensource.org/licenses/GPL-3.0
|
14 | 14 | *
|
15 |
| - * Date: 2016-10-11T14:22:42.163Z |
| 15 | + * Date: 2016-10-24T14:31:11.197Z |
16 | 16 | */
|
17 | 17 |
|
18 | 18 | (function (factory) {
|
|
1236 | 1236 | item.appendTo = item.$node;
|
1237 | 1237 | $t.data('contextMenu', item).addClass('context-menu-submenu');
|
1238 | 1238 | 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 | + } |
1248 | 1253 | break;
|
1249 | 1254 |
|
1250 | 1255 | case 'html':
|
|
1428 | 1433 | return $layer;
|
1429 | 1434 | },
|
1430 | 1435 | processPromises: function (opt, root, promise) {
|
| 1436 | + // Start |
| 1437 | + opt.$node.addClass('context-menu-icon-loading'); |
| 1438 | + |
| 1439 | + |
1431 | 1440 | 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. |
1434 | 1443 | if (items === undefined) {
|
1435 |
| - //meh, null result, dev should have checked |
| 1444 | + // Null result, dev should have checked |
1436 | 1445 | errorPromise(undefined);//own error object
|
1437 | 1446 | }
|
1438 | 1447 | finishPromiseProcess(opt,root, items);
|
1439 | 1448 | };
|
1440 | 1449 | 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. |
1442 | 1452 | if (errorItem === undefined) {
|
1443 | 1453 | errorItem = { "error": { name: "No items and no error item", icon: "context-menu-icon context-menu-icon-quit" } };
|
1444 | 1454 | if (window.console) {
|
1445 | 1455 | (console.error || console.log).call(console, 'When you reject a promise, provide an "items" object, equal to normal sub-menu items');
|
1446 | 1456 | }
|
1447 |
| - }else if(typeof errorItem === 'string'){ |
1448 |
| - errorItem = { "error": { name: errorItem } }; |
1449 |
| - } |
| 1457 | + } else if(typeof errorItem === 'string'){ |
| 1458 | + errorItem = { "error": { name: errorItem } }; |
| 1459 | + } |
1450 | 1460 | finishPromiseProcess(opt,root,errorItem);
|
1451 | 1461 | };
|
1452 | 1462 | 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. |
1457 | 1471 | };
|
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 |
1459 | 1475 | promise.then(completedPromise.bind(this, opt, root), errorPromise.bind(this, opt, root));
|
1460 | 1476 | }
|
1461 | 1477 | };
|
|
0 commit comments