bin.shen
2016-12-05 a4c9331bbfe3e8765ccdc1c54cc6931bac49cc82
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
 * jQuery ajax history plugins
 * @author ZhangHuihua@msn.com
 */
 
 
(function($){
 
    $.extend({
        
        History: {
            _hash: new Array(),
            _cont: undefined,
            _currentHash: "",
            _callback: undefined,
            init: function(cont, callback){
                $.History._cont = cont;
                $.History._callback = callback;
                var current_hash = location.hash.replace(/\?.*$/, '');
                $.History._currentHash = current_hash;
                if ($.browser.msie) {
                    if ($.History._currentHash == '') {
                        $.History._currentHash = '#';
                    }
                    $("body").append('<iframe id="jQuery_history" style="display: none;" src="about:blank"></iframe>');
                    var ihistory = $("#jQuery_history")[0];
                    var iframe = ihistory.contentDocument || ihistory.contentWindow.document;
                    iframe.open();
                    iframe.close();
                    iframe.location.hash = current_hash;
                }
                if ($.isFunction(this._callback)) 
                    $.History._callback(current_hash.skipChar("#"));
                setInterval($.History._historyCheck, 100);
            },
            _historyCheck: function(){
                var current_hash = "";
                if ($.browser.msie) {
                    var ihistory = $("#jQuery_history")[0];
                    var iframe = ihistory.contentWindow;
                    current_hash = iframe.location.hash.skipChar("#").replace(/\?.*$/, '');
                } else {
                    current_hash = location.hash.skipChar('#').replace(/\?.*$/, '');
                }
//                if (!current_hash) {
//                    if (current_hash != $.History._currentHash) {
//                        $.History._currentHash = current_hash;
//                        //TODO
//                    }
//                } else {
                    if (current_hash != $.History._currentHash) {
                        $.History._currentHash = current_hash;
                        $.History.loadHistory(current_hash);
                    }
//                }
                
            },
            addHistory: function(hash, fun, args){
                $.History._currentHash = hash;
                var history = [hash, fun, args];
                $.History._hash.push(history);
                if ($.browser.msie) {
                    var ihistory = $("#jQuery_history")[0];
                    var iframe = ihistory.contentDocument || ihistory.contentWindow.document;
                    iframe.open();
                    iframe.close();
                    iframe.location.hash = hash.replace(/\?.*$/, '');
                    location.hash = hash.replace(/\?.*$/, '');
                } else {
                    location.hash = hash.replace(/\?.*$/, '');
                }
            },
            loadHistory: function(hash){
                if ($.browser.msie) {
                    location.hash = hash;
                }
                for (var i = 0; i < $.History._hash.length; i += 1) {
                    if ($.History._hash[i][0] == hash) {
                        $.History._hash[i][1]($.History._hash[i][2]);
                        return;
                    }
                }
            }
        }
    });
})(jQuery);