KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > client > impl > HistoryImplStandard


1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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   public native boolean init() /*-{
24     $wnd.__gwt_historyToken = '';
25
26     // Get the initial token from the url's hash component.
27     var hash = $wnd.location.hash;
28     if (hash.length > 0)
29       $wnd.__gwt_historyToken = hash.substring(1);
30
31     // Create the timer that checks the browser's url hash every 1/4 s.
32     $wnd.__checkHistory = function() {
33       var token = '', hash = $wnd.location.hash;
34       if (hash.length > 0)
35         token = hash.substring(1);
36
37       if (token != $wnd.__gwt_historyToken) {
38         $wnd.__gwt_historyToken = token;
39         @com.google.gwt.user.client.impl.HistoryImpl::onHistoryChanged(Ljava/lang/String;)(token);
40       }
41
42       $wnd.setTimeout('__checkHistory()', 250);
43     };
44
45     // Kick off the timer.
46     $wnd.__checkHistory();
47
48     return true;
49   }-*/
;
50
51   public native void newItem(String JavaDoc historyToken) /*-{
52     if (historyToken == null) {
53       historyToken = "";
54     }
55     $wnd.location.hash = encodeURIComponent(historyToken);
56   }-*/
;
57 }
58
Popular Tags