javagwtgesturegwtquerygquery

How to enable text highlighting on a page using gquery gestures plugin?


I have a complex GWT application that is designed for mobile and has this gwtquery-gestures-plugin code in its (root) ApplicationPresenter:

$(RootPanel.get())
            .as(Gesture.Gesture)
            .on("tap", new Function()
            {
                @Override
                public boolean f(Event e)
                {
                    Log.info("tap:" + e.getType() + ", x:" + e.getClientX() + ", y:" + e.getClientY());

                    // handle tap events here

                    return true;
                }
            })
            .on("swipeone", new Function()
            {
                @Override
                public boolean f(Event e)
                {
                    GestureObjects.Options o = arguments(0);
                    int delta = (int) o.delta().get(0).moved();

                    Log.info(o.description() + ":" + o.directionName() + ", x:" + e.getClientX() + ", y:" + e.getClientY() + ", delta:" + delta);

                    // handle swipe events here

                    return true;
                }

            });

Unfortunately this plugin seems to totally hijack the native selection of text, so the user can't copy and paste anything. Is there a way to enable this, or a workaround of some kind?


Solution

  • On closer inspection of the documentation, I found this static boolean hasGestures that can be used to check if we are loading on a mobile decive or not.

    So the snippet now becomes:

    if(Gesture.hasGestures) // only load for mobile devices
        {
            $(RootPanel.get())
                    .as(Gesture.Gesture)
                    .on("tap", new Function() 
                    {
                        @Override
                        public boolean f(Event e)
                        {
                            Log.info("tap:" + e.getType() + ", x:" + e.getClientX() + ", y:" + e.getClientY());
    
                            return true;
                        }
                    })
                    .on("swipeone", new Function()
                    {
                        @Override
                        public boolean f(Event e)
                        {
                            GestureObjects.Options o = arguments(0);
                            int delta = (int) o.delta().get(0).moved();
    
                            Log.info(o.description() + ":" + o.directionName() + ", x:" + e.getClientX() + ", y:" + e.getClientY() + ", delta:" + delta);
    
                            return true;
                        }
    
                    });
        }
        else
        {
            Log.info("Not adding gesture handlers as this is not a mobile device!");
        }