简体   繁体   中英

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?

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!");
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM