01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.user.client.impl;
17:
18: /**
19: * Standard history implementation, currently used only on Opera browsers.
20: */
21: class HistoryImplStandard extends HistoryImpl {
22:
23: @Override
24: public native boolean init() /*-{
25: $wnd.__gwt_historyToken = '';
26:
27: // Get the initial token from the url's hash component.
28: var hash = $wnd.location.hash;
29: if (hash.length > 0)
30: $wnd.__gwt_historyToken = hash.substring(1);
31:
32: // Create the timer that checks the browser's url hash every 1/4 s.
33: $wnd.__checkHistory = function() {
34: var token = '', hash = $wnd.location.hash;
35: if (hash.length > 0)
36: token = hash.substring(1);
37:
38: if (token != $wnd.__gwt_historyToken) {
39: $wnd.__gwt_historyToken = token;
40: @com.google.gwt.user.client.impl.HistoryImpl::onHistoryChanged(Ljava/lang/String;)(token);
41: }
42:
43: $wnd.setTimeout('__checkHistory()', 250);
44: };
45:
46: // Kick off the timer.
47: $wnd.__checkHistory();
48:
49: return true;
50: }-*/;
51:
52: @Override
53: public native void newItem(String historyToken) /*-{
54: if (historyToken == null) {
55: historyToken = "";
56: }
57: $wnd.location.hash = encodeURIComponent(historyToken);
58: }-*/;
59: }
|