简体   繁体   English

在弹出窗口之外处理点击事件

[英]Handle click event outside popup

How would you handle a click event outside of a "popup", I am actually using LinkedIn Hopscotch wrapper for GWT. 您将如何处理“弹出窗口”之外的点击事件,实际上我正在使用GWT的LinkedIn Hopscotch包装器。 The idea is when user clicks outside of the popup (ie outside .hopscotch-bubble-container ) the popup should hide. 这个想法是当用户在弹出窗口之外单击时(即在.hopscotch-bubble-container外部),弹出窗口应隐藏。 Calling GwtTour.endTour(false); 调用GwtTour.endTour(false); eventually cause the popup to hide. 最终导致弹出窗口隐藏。 This is fine, however, I also need to make when "dashboardLink" menu item is also clicked; 很好,但是,当还单击“ dashboardLink”菜单项时,我还需要进行设置。 this $("html").bind("click",...) should also not be called. 此$(“ html”)。bind(“ click”,...)也不应调用。 Which it is called, not sure why. 叫哪个,不知道为什么。

Code: 码:

private void bindHandlers(){

    // Handle when click event came from here
    $(".hopscotch-bubble-container").bind("click", new com.google.gwt.query.client.Function() {
        @Override
        public boolean f(com.google.gwt.user.client.Event e) {
            e.stopPropagation();
            return false;
        }
    });
    $("#dashboardLink").bind("click", new com.google.gwt.query.client.Function() {
        @Override
        public boolean f(com.google.gwt.user.client.Event e) {
            e.stopPropagation();
            return false;
        }
    });
    // This event handler closes the GWT Tour
    // when user click outside of it
    $("html").bind("click", new com.google.gwt.query.client.Function() {
        @Override
        public boolean f(com.google.gwt.user.client.Event e) {
            GwtTour.endTour(false);
            return true;
        }
    });
}

Check the source of click event if it is triggered form expected source then do whatever is needed. 检查点击事件的来源(如果它是由预期来源触发的),然后执行所需的任何操作。

If Menu item is the source of this click event then do nothing. 如果菜单项是此单击事件的来源,则什么也不做。

Have a look: 看一看:

$("html").bind("click", new com.google.gwt.query.client.Function() {
    @Override
    public boolean f(com.google.gwt.user.client.Event e) {
        // you can check it using instanceof operator, object references or Element ID
        // e.getSource() instanceof MenuItem
        // ((Widget) e.getSource()).getElement().getId()
        if (e.getSource() != dashboardLink) {
            GwtTour.endTour(false);
            return true;
        } else {
            return false;
        }
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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