~crf-team/crf-irp/crf-irp

« back to all changes in this revision

Viewing changes to WebContent/js/extjs-2/source/util/History.js

  • Committer: Thomas
  • Date: 2010-03-10 23:55:46 UTC
  • Revision ID: thomas@daisybox-port-20100310235546-23635dk6x5asb1ca
Upgrade ExtJs 3.1.1
Upgrade Spring 3.0.1 + dependencies
Change Jawr JS post processor : YUI
Upgrade to last build of dwr 3 trunk 69 revision 3019(after build 116), upgrade jawr-dwr plugin 1.4 unofficiale from jose noheda, Jawr 3.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Ext JS Library 2.3.0
3
 
 * Copyright(c) 2006-2009, Ext JS, LLC.
4
 
 * licensing@extjs.com
5
 
 * 
6
 
 * http://extjs.com/license
7
 
 */
8
 
 
9
 
/**
10
 
 * @class Ext.History
11
 
 * @extends Ext.util.Observable
12
 
 * History management component that allows you to register arbitrary tokens that signify application
13
 
 * history state on navigation actions.  You can then handle the history {@link #change} event in order
14
 
 * to reset your application UI to the appropriate state when the user navigates forward or backward through
15
 
 * the browser history stack.
16
 
 * @singleton
17
 
 */
18
 
Ext.History = (function () {
19
 
    var iframe, hiddenField;
20
 
    var ready = false;
21
 
    var currentToken;
22
 
 
23
 
    function getHash() {
24
 
        var href = top.location.href, i = href.indexOf("#");
25
 
        return i >= 0 ? href.substr(i + 1) : null;
26
 
    }
27
 
 
28
 
    function doSave() {
29
 
        hiddenField.value = currentToken;
30
 
    }
31
 
 
32
 
    function handleStateChange(token) {
33
 
        currentToken = token;
34
 
        Ext.History.fireEvent('change', token);
35
 
    }
36
 
 
37
 
    function updateIFrame (token) {
38
 
        var html = ['<html><body><div id="state">',token,'</div></body></html>'].join('');
39
 
        try {
40
 
            var doc = iframe.contentWindow.document;
41
 
            doc.open();
42
 
            doc.write(html);
43
 
            doc.close();
44
 
            return true;
45
 
        } catch (e) {
46
 
            return false;
47
 
        }
48
 
    }
49
 
 
50
 
    function checkIFrame() {
51
 
        if (!iframe.contentWindow || !iframe.contentWindow.document) {
52
 
            setTimeout(checkIFrame, 10);
53
 
            return;
54
 
        }
55
 
 
56
 
        var doc = iframe.contentWindow.document;
57
 
        var elem = doc.getElementById("state");
58
 
        var token = elem ? elem.innerText : null;
59
 
 
60
 
        var hash = getHash();
61
 
 
62
 
        setInterval(function () {
63
 
 
64
 
            doc = iframe.contentWindow.document;
65
 
            elem = doc.getElementById("state");
66
 
 
67
 
            var newtoken = elem ? elem.innerText : null;
68
 
 
69
 
            var newHash = getHash();
70
 
 
71
 
            if (newtoken !== token) {
72
 
                token = newtoken;
73
 
                handleStateChange(token);
74
 
                top.location.hash = token;
75
 
                hash = token;
76
 
                doSave();
77
 
            } else if (newHash !== hash) {
78
 
                hash = newHash;
79
 
                updateIFrame(newHash);
80
 
            }
81
 
 
82
 
        }, 50);
83
 
 
84
 
        ready = true;
85
 
 
86
 
        Ext.History.fireEvent('ready', Ext.History);
87
 
    }
88
 
 
89
 
    function startUp() {
90
 
        currentToken = hiddenField.value ? hiddenField.value : getHash();
91
 
        
92
 
        if (Ext.isIE) {
93
 
            checkIFrame();
94
 
        } else {
95
 
            var hash = getHash();
96
 
            setInterval(function () {
97
 
                var newHash = getHash();
98
 
                if (newHash !== hash) {
99
 
                    hash = newHash;
100
 
                    handleStateChange(hash);
101
 
                    doSave();
102
 
                }
103
 
            }, 50);
104
 
            ready = true;
105
 
            Ext.History.fireEvent('ready', Ext.History);
106
 
        }
107
 
    }
108
 
 
109
 
    return {
110
 
        /**
111
 
         * The id of the hidden field required for storing the current history token.
112
 
         * @type String
113
 
         * @property
114
 
         */
115
 
        fieldId: 'x-history-field',
116
 
        /**
117
 
         * The id of the iframe required by IE to manage the history stack.
118
 
         * @type String
119
 
         * @property
120
 
         */
121
 
        iframeId: 'x-history-frame',
122
 
        
123
 
        events:{},
124
 
 
125
 
        /**
126
 
         * Initialize the global History instance.
127
 
         * @param {Boolean} onReady (optional) A callback function that will be called once the history
128
 
         * component is fully initialized.
129
 
         * @param {Object} scope (optional) The callback scope
130
 
         */
131
 
        init: function (onReady, scope) {
132
 
            if(ready) {
133
 
                Ext.callback(onReady, scope, [this]);
134
 
                return;
135
 
            }
136
 
            if(!Ext.isReady){
137
 
                Ext.onReady(function(){
138
 
                    Ext.History.init(onReady, scope);
139
 
                });
140
 
                return;
141
 
            }
142
 
            hiddenField = Ext.getDom(Ext.History.fieldId);
143
 
                        if (Ext.isIE) {
144
 
                iframe = Ext.getDom(Ext.History.iframeId);
145
 
            }
146
 
            this.addEvents('ready', 'change');
147
 
            if(onReady){
148
 
                this.on('ready', onReady, scope, {single:true});
149
 
            }
150
 
            startUp();
151
 
        },
152
 
 
153
 
        /**
154
 
         * Add a new token to the history stack. This can be any arbitrary value, although it would
155
 
         * commonly be the concatenation of a component id and another id marking the specifc history
156
 
         * state of that component.  Example usage:
157
 
         * <pre><code>
158
 
// Handle tab changes on a TabPanel
159
 
tabPanel.on('tabchange', function(tabPanel, tab){
160
 
    Ext.History.add(tabPanel.id + ':' + tab.id);
161
 
});
162
 
</code></pre>
163
 
         * @param {String} token The value that defines a particular application-specific history state
164
 
         * @param {Boolean} preventDuplicates When true, if the passed token matches the current token
165
 
         * it will not save a new history step. Set to false if the same state can be saved more than once
166
 
         * at the same history stack location (defaults to true).
167
 
         */
168
 
        add: function (token, preventDup) {
169
 
            if(preventDup !== false){
170
 
                if(this.getToken() == token){
171
 
                    return true;
172
 
                }
173
 
            }
174
 
            if (Ext.isIE) {
175
 
                return updateIFrame(token);
176
 
            } else {
177
 
                top.location.hash = token;
178
 
                return true;
179
 
            }
180
 
        },
181
 
 
182
 
        /**
183
 
         * Programmatically steps back one step in browser history (equivalent to the user pressing the Back button).
184
 
         */
185
 
        back: function(){
186
 
            history.go(-1);
187
 
        },
188
 
 
189
 
        /**
190
 
         * Programmatically steps forward one step in browser history (equivalent to the user pressing the Forward button).
191
 
         */
192
 
        forward: function(){
193
 
            history.go(1);
194
 
        },
195
 
 
196
 
        /**
197
 
         * Retrieves the currently-active history token.
198
 
         * @return {String} The token
199
 
         */
200
 
        getToken: function() {
201
 
            return ready ? currentToken : getHash();
202
 
        }
203
 
    };
204
 
})();
205
 
Ext.apply(Ext.History, new Ext.util.Observable());
 
 
b'\\ No newline at end of file'