Revision: 9637
Author: jhollenb...@google.com
Date: Thu Jan 27 07:30:25 2011
Log: Change GWT History to work when multiple applications are loaded
within the same page.
Patch by: jhollenbach
Review by: jat, jgw
Review at http://gwt-code-reviews.appspot.com/1322801
http://code.google.com/p/google-web-toolkit/source/detail?r=9637
Modified:
/trunk/user/src/com/google/gwt/user/client/impl/HistoryImpl.java
/trunk/user/src/com/google/gwt/user/client/impl/HistoryImplIE6.java
/trunk/user/src/com/google/gwt/user/client/impl/HistoryImplTimer.java
=======================================
--- /trunk/user/src/com/google/gwt/user/client/impl/HistoryImpl.java Mon
Oct 26 14:02:26 2009
+++ /trunk/user/src/com/google/gwt/user/client/impl/HistoryImpl.java Thu
Jan 27 07:30:25 2011
@@ -35,9 +35,11 @@
*/
public class HistoryImpl implements HasValueChangeHandlers<String>,
HasHandlers {
- public static native String getToken() /*-{
- return $wnd.__gwt_historyToken || "";
- }-*/;
+ private static String token = "";
+
+ public static String getToken() {
+ return (token == null) ? "" : token;
+ }
/**
* Sets whether the IE6 history implementation will update the URL hash
when
@@ -53,9 +55,9 @@
public static void setUpdateHashOnIE6(boolean updateHash) {
}
- protected static native void setToken(String token) /*-{
- $wnd.__gwt_historyToken = token;
- }-*/;
+ protected static void setToken(String token) {
+ HistoryImpl.token = token;
+ }
private HandlerManager handlers = new HandlerManager(null);
@@ -97,6 +99,9 @@
@com.google.gwt.user.client.impl.HistoryImpl::setToken(Ljava/lang/String;)(token);
var historyImpl = this;
+
+ var oldHandler = $wnd.onhashchange;
+
$wnd.onhashchange = $entry(function() {
var token = '', hash = $wnd.location.hash;
if (hash.length > 0) {
@@ -104,6 +109,10 @@
}
historyim...@com.google.gwt.user.client.impl.HistoryImpl::newItemOnEvent(Ljava/lang/String;)(token);
+
+ if (oldHandler) {
+ oldHandler();
+ }
});
return true;
=======================================
--- /trunk/user/src/com/google/gwt/user/client/impl/HistoryImplIE6.java Fri
Oct 16 14:48:33 2009
+++ /trunk/user/src/com/google/gwt/user/client/impl/HistoryImplIE6.java Thu
Jan 27 07:30:25 2011
@@ -179,9 +179,14 @@
private native void injectGlobalHandler() /*-{
var historyImplRef = this;
+ var oldOnLoad = $wnd.__gwt_onHistoryLoad;
$wnd.__gwt_onHistoryLoad = $entry(function(token) {
historyimplr...@com.google.gwt.user.client.impl.HistoryImpl::newItemOnEvent(Ljava/lang/String;)(token);
+
+ if (oldOnLoad) {
+ oldOnLoad(token);
+ }
});
}-*/;
=======================================
--- /trunk/user/src/com/google/gwt/user/client/impl/HistoryImplTimer.java
Wed Oct 28 09:10:53 2009
+++ /trunk/user/src/com/google/gwt/user/client/impl/HistoryImplTimer.java
Thu Jan 27 07:30:25 2011
@@ -35,9 +35,8 @@
// Create the timer that checks the browser's url hash every 1/4 s.
var historyImpl = this;
- $wnd.__checkHistory = $entry(function() {
- $wnd.setTimeout($wnd.__checkHistory, 250);
-
+
+ var checkHistory = $entry(function() {
var token = '', hash = $wnd.location.hash;
if (hash.length > 0) {
token =
historyim...@com.google.gwt.user.client.impl.HistoryImpl::decodeFragment(Ljava/lang/String;)(hash.substring(1));
@@ -46,8 +45,13 @@
historyim...@com.google.gwt.user.client.impl.HistoryImpl::newItemOnEvent(Ljava/lang/String;)(token);
});
+ var checkHistoryCycle = function() {
+ $wnd.setTimeout(checkHistoryCycle, 250);
+ checkHistory();
+ }
+
// Kick off the timer.
- $wnd.__checkHistory();
+ checkHistoryCycle();
return true;
}-*/;
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors