2014-03-05 41 views
0

如何处理“弹出式窗口”之外的点击事件,实际上是使用LinkedIn Hopscotch包装器进行GWT。这个想法是当用户点击弹出窗口之外(即在.hopscotch-bubble-container之外)弹出窗口应该隐藏。调用GwtTour.endTour(false);最终会导致弹出窗口隐藏。这很好,但是,当“dashboardLink”菜单项也被点击时我也需要制作;这个$(​​“html”)。bind(“click”,...)也不应该被调用。它被称为,不知道为什么。处理弹出式窗口外的单击事件

代码:

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; 
     } 
    }); 
} 
+0

你能不能只使用GWT从该对话框类“新的对话框(真)”为自动隐藏选项? – Akkusativobjekt

回答

1

检查它是否触发形式有望源,然后做相应处理即可点击事件的来源。

如果菜单项是此单击事件的源,则不执行任何操作。

看一看:

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