0

Jquery latest version is not working in GWT 2.7 as have created custom menubar it calls jquery function .The loadslimmenu() method is called and it prints "IN loadslimmenu() ===". Next log its not printing whats wrong not getting. The code is

public native static void loadslimmenu()
    /*-{
         console.log("IN loadslimmenu() ===");
        (function($, window, document, undefined){
                console.log("Inside function 11====");
                var pluginName = "slimmenu",
                    defaults =
                    {
                        resizeActive: false,
                        resizeWidth: '768',
                        hasCollapser: false,
                        collapserTitle: '',
                        animSpeed: 'medium',
                        easingEffect: null,
                        indentChildren: false,
                        childrenIndenter: '  '
                    };

                function Plugin( element, options )
                {
                    console.log("Inside function 22====");
                    this.element = element;
                    this.$elem = $(this.element);
                    this.options = $.extend( {}, defaults, options );
                    this.init();
                }

                Plugin.prototype = {

                    init: function()
                    {
                        console.log("Inside function 33====");
                        var $options = this.options,
                            $menu = this.$elem,
                            $collapser = '<div class="menu-collapser">'+$options.collapserTitle+'<div class="collapse-button"><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></div></div>',
                            $menu_collapser;

                        $menu.before($collapser);
                        $menu_collapser = $menu.prev('.menu-collapser');

                        $menu.on('click', '.sub-collapser', function(e)
                        {
                            console.log("Inside function 44====");
                            e.preventDefault();
                            e.stopPropagation();
                            console.log("Inside function 55====");
                            var $parent_li = $(this).closest('li');

                            if ($(this).hasClass('expanded'))
                            {
                                console.log("Inside function 66 IN IF====");
                                $(this).removeClass('expanded');
                                $(this).find('i').html('&#9660;');
                                $parent_li.find('>ul').slideUp($options.animSpeed, $options.easingEffect);
                            }
                            else
                            {
                                console.log("Inside function 66 IN ELSE====");
                                $(this).addClass('expanded');
                                $(this).find('i').html('&#9650;');
                                $parent_li.find('>ul').slideDown($options.animSpeed, $options.easingEffect);
                            }
                        });

                        $menu_collapser.on('click', '.collapse-button', function(e)
                        {
                            console.log("Inside function 77 ====");
                            e.preventDefault();
                            $menu.slideToggle($options.animSpeed, $options.easingEffect);
                        });

                        if( ! $options.hasCollapser )
                        {
                            console.log("Inside function 88 ====");
                            $menu_collapser.hide();
                        }

                        this.resizeMenu({ data: { el: this.element, options: this.options } });
                        if( $options.resizeActive )
                        {
                            console.log("Inside function 99 ====");
                            $(window).on('resize', { el: this.element, options: this.options }, this.resizeMenu);
                        }
                    },

                    resizeMenu: function(event)
                    {
                        var $window = $(window),
                            $options = event.data.options,
                            $menu = $(event.data.el),
                            $menu_collapser = $('body').find('.menu-collapser');

                        $menu.find('li').each(function()
                        {
                            if ($(this).has('ul').length)
                            {
                                console.log("Inside Length() ====");
                                if ($(this).has('.sub-collapser').length)
                                {
                                    $(this).children('.sub-collapser i').html('&#9660;');
                                }
                                else
                                {
                                    $(this).append('<span class="sub-collapser"><i>&#9660;</i></span>');
                                }
                            }

                            $(this).children('ul').hide();
                            $(this).find('.sub-collapser').removeClass('expanded').children('i').html('&#9660;');
                        });

                        if ($options.resizeWidth >= $window.width())
                        {
                            if ($options.indentChildren)
                            {
                                $menu.find('ul').each(function()
                                {
                                    var $depth = $(this).parents('ul').length;
                                    if (!$(this).children('li').children('a').has('i').length)
                                    {
                                        $(this).children('li').children('a').prepend(Plugin.prototype.indent($depth, $options));
                                    }
                                });
                            }

                            $menu.find('li').has('ul').off('mouseenter mouseleave');
                            $menu.addClass('collapsed').hide();
                            $menu_collapser.show();
                        }
                        else
                        {
                            $menu.find('li').has('ul').on('mouseenter', function()
                            {
                                $(this).find('>ul').stop().slideDown($options.animSpeed, $options.easingEffect);
                                $(this).addClass('activeNav');
                            })
                            .on('mouseleave', function()
                            {
//                              console.log('mouseleave');
                                console.log("Inside mouseleave 10====");
                                $(this).find('>ul').stop().slideUp($options.animSpeed, $options.easingEffect);
                                $(this).removeClass('activeNav');
                                resetPrevAnchor();
                            });

                            $menu.find('li > a > i').remove();
                            $menu.removeClass('collapsed').show();
                            $menu_collapser.hide();
                        }
                    },

                    indent: function(num, options)
                    {
                        console.log("Inside function 11 ====");
                        var $indent = '';
                        for (var i=0; i < num; i++)
                        {
                            $indent += options.childrenIndenter;
                        }
                        return '<i>'+$indent+'</i>';
                    }
                };

                $.fn[pluginName] = function ( options )
                {
                    return this.each(function ()
                    {
                        if (!$.data(this, "plugin_" + pluginName))
                        {
                            $.data(this, "plugin_" + pluginName,
                            new Plugin( this, options ));
                        }
                    });
                };

            })(jQuery, window, document);

    }-*/;
Yasel
  • 2,920
  • 4
  • 40
  • 48

1 Answers1

2

Em...if you will look closely at http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html - you will see that all window and document should be written as $wnd and $doc. Also - jQuery works fine. You just should use $wnd.$ instead of $.

This topic can be also helpful Use jquery inside GWT jsni

Community
  • 1
  • 1
Mike Voitenko
  • 133
  • 10