views:

298

answers:

1

I need to put a custom hover menu from http://www.addthis.com/help/toolbox, but Rails uses Prototype whereas the code given is in JQuery. I do not have much experience with either JavaScript library, if someone can help it'd be much appreciated!

$(function()
{
    $('.custom_button, .hover_menu').mouseenter(function()
    {
        $('.hover_menu').fadeIn('fast');
        $('.custom_button').addClass('active');
        $(this).data('in', true);
        $('.hover_menu').data('hidden', false);
    }).mouseleave(function()
    {
        $(this).data('in', false);
        setTimeout(hideMenu, delay);
    });

    var delay = 400;
    function hideMenu()
    {
        if (!$('.custom_button').data('in') && !$('.hover_menu').data('in') && !$('.hover_menu').data('hidden'))
        {
            $('.hover_menu').fadeOut('fast');
            $('.custom_button').removeClass('active');
            $('.hover_menu').data('hidden', true);
        }
    }
});
+2  A: 

So if you're not tied down to using Prototype and want to use jQuery instead, there's a plugin called jRails which serves as a drop-in replacement for Prototype.

Not that there's anything wrong with Prototype, but getting jQuery installed may end up being easier than trying to port it to Prototype. Hope that helps (sorry if it isn't exactly what you were looking for).

EDIT: This page has some good information about jQuery and Rails. Hope that helps.

thebrokencube
That's not a bad idea, the problem is the developers don't want to include more libraries than needed (Prototype/Scriptaculous are packaged in, and we're also using YUI)
echoblaze
Ah, okay. that makes sense, sorry that wasn't much help =/.
thebrokencube
Well if youve already got proto and yui why not go for the full quota and include jQuery and extjs:)
redsquare