2014-03-05 40 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; 
     } 
    } 
});