GWT 2.7不支持jquery

时间:2015-09-16 13:55:10

标签: jquery gwt

Jquery最新版本在GWT 2.7中不起作用,因为它创建了调用jquery函数的自定义菜单栏。调用了loadslimmenu()方法并打印了#34; IN loadslimmenu()==="。接下来记录它不打印什么错误没有得到。代码是

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);

    }-*/;

1 个答案:

答案 0 :(得分:2)

Em ......如果您仔细查看http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html - 您会看到所有windowdocument应该写为$wnd$doc 。另外 - jQuery工作正常。您应该使用$wnd.$代替$

此主题也很有用Use jquery inside GWT jsni