This is a migrated thread and some comments may be shown as answers.

Selecting all menu controls with jQuery

3 Answers 65 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 09 Sep 2011, 09:35 AM

My site has the need to close a menu if the mouse leaves the window (its very close to the left edge, so its easily left open).

As we have multiple menu's on our page, there is the unlikely possibility that more tha none could be left open, so I really wanted to use a jQuery selector to find all menu controls, and fire its close() method when the mouse leaves the window.

I got to this :

 

$telerik.$(document).mouseleave(

    function () {
        $('.RadMenu').close();
        }
);

 


However, the $('.RadMenu').close(); doesn't work - erroring that close() isn't supported. if I go through the results from $('.RadMenu'), they do seem to be the correct elements being returned (HTMLDiv objects).

Can anyone help?

Thanks,

Andrew

3 Answers, 1 is accepted

Sort by
0
Andrew
Top achievements
Rank 1
answered on 09 Sep 2011, 10:21 AM
It looks like you can't access the object directly, so using another post to get the actual RadMenu object, and iterating through them, this seems to work well...
var closeAll;
 
$telerik.$(document).mouseleave(function () {
    closeAll = setTimeout('closeAllMenus()', 1000);
});
 
function closeAllMenus() {
    var menus = $('.RadMenu').map(function () { return this.control; });
    for (var i = menus.length - 1; i >= 0; i--) {
        menus[i].close();
    }
}

The 1000ms delay is because if the menu is still loading up items (ours is populated by a webservice), then you can't close it. The only caveat is that if you move out and in quickly to the window, the menu will still disappear, but its quite a minor thing.
0
Kate
Telerik team
answered on 14 Sep 2011, 02:30 PM
Hello Andrew,

Thank you for sharing the solution with us. Let us know if you encounter any further difficulties so we could help you. 

Greetings,
Kate
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal
0
Nona
Top achievements
Rank 1
answered on 02 Jul 2012, 06:24 PM
THANK YOU ANDREW!!!!

Please excuse the shoutout, but I've been looking for this for a week!

I knew there was a way! 

the this.control is no where in the documentation. 

Kudos!
Tags
Menu
Asked by
Andrew
Top achievements
Rank 1
Answers by
Andrew
Top achievements
Rank 1
Kate
Telerik team
Nona
Top achievements
Rank 1
Share this question
or