Skip to content

Commit da7b150

Browse files
committed
Added API for external activation
1 parent da3cb65 commit da7b150

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

jquery.menu-aim.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,26 @@
6767
* submenuDirection: "right"
6868
* });
6969
*
70+
* Activation can be triggered from your own code via the API:
71+
*
72+
* $('#menu').menuAim('activate', elem);
73+
* $('#menu').menuAim('deactivateMenu');
74+
*
7075
* https://github.com/kamens/jQuery-menu-aim
7176
*/
7277
(function($) {
7378

7479
$.fn.menuAim = function(opts) {
80+
var apiAction, apiArgs;
81+
if (typeof arguments[0] === 'string') {
82+
apiAction = arguments[0];
83+
apiArgs = Array.prototype.slice.apply(arguments, [1]);
84+
this.each(function(){
85+
$(this).data('menuAim')[apiAction].apply(null, apiArgs);
86+
});
87+
return this;
88+
}
89+
7590
// Initialize menu-aim for all elements in jQuery collection
7691
this.each(function() {
7792
init.call(this, opts);
@@ -318,6 +333,23 @@
318333

319334
$(document).mousemove(mousemoveDocument);
320335

336+
337+
// API for external activation triggers
338+
$menu.data('menuAim', {
339+
activate: function(elem) {
340+
if (!$menu.find(options.rowSelector).filter(elem).length) return;
341+
activate(elem);
342+
},
343+
deactivateMenu: function() {
344+
if (timeoutId) {
345+
clearTimeout(timeoutId);
346+
}
347+
if (activeRow) {
348+
options.deactivate(activeRow);
349+
}
350+
activeRow = null;
351+
}
352+
});
321353
};
322354
})(jQuery);
323355

0 commit comments

Comments
 (0)