Skip to content

Commit

Permalink
Merge branch 'html5'
Browse files Browse the repository at this point in the history
  • Loading branch information
Takayuki Miwa committed Sep 12, 2010
2 parents 318cdf4 + ab60e49 commit 7ad0e52
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 27 deletions.
81 changes: 54 additions & 27 deletions jquery.history.js
Expand Up @@ -88,47 +88,54 @@
}
}

// public base interface
var _ = {
appState: undefined,
var implementations = {};

implementations.base = {
callback: undefined,
init: function(callback, options) {},
check: function() {},
load: function(hash) {}
};
$.history = _;
type: undefined,

var SimpleImpl = {
init: function(callback, options) {
check: function() {},
load: function(hash) {},
init: function(callback, options) {
initObjects(options);
_.callback = callback;
_._options = options;
_._init();
},

_init: function() {},
_options: {}
};

implementations.timer = {
_appState: undefined,
_init: function() {
var current_hash = locationWrapper.get();
_.appState = current_hash;
_._appState = current_hash;
_.callback(current_hash);
setInterval(_.check, 100);
},
check: function() {
var current_hash = locationWrapper.get();
if(current_hash != _.appState) {
_.appState = current_hash;
if(current_hash != _._appState) {
_._appState = current_hash;
_.callback(current_hash);
}
},
load: function(hash) {
if(hash != _.appState) {
if(hash != _._appState) {
locationWrapper.put(hash);
_.appState = hash;
_._appState = hash;
_.callback(hash);
}
}
};

var IframeImpl = {
init: function(callback, options) {
initObjects(options);
_.callback = callback;
implementations.iframeTimer = {
_appState: undefined,
_init: function() {
var current_hash = locationWrapper.get();
_.appState = current_hash;
_._appState = current_hash;
iframeWrapper.init().put(current_hash);
_.callback(current_hash);
setInterval(_.check, 100);
Expand All @@ -138,30 +145,50 @@
location_hash = locationWrapper.get();

if (location_hash != iframe_hash) {
if (location_hash == _.appState) { // user used Back or Forward button
_.appState = iframe_hash;
if (location_hash == _._appState) { // user used Back or Forward button
_._appState = iframe_hash;
locationWrapper.put(iframe_hash);
_.callback(iframe_hash);
} else { // user loaded new bookmark
_.appState = location_hash;
_._appState = location_hash;
iframeWrapper.put(location_hash);
_.callback(location_hash);
}
}
},
load: function(hash) {
if(hash != _.appState) {
if(hash != _._appState) {
locationWrapper.put(hash);
iframeWrapper.put(hash);
_.appState = hash;
_._appState = hash;
_.callback(hash);
}
}
};

implementations.hashchangeEvent = {
_init: function() {
_.callback(locationWrapper.get());
$(window).bind('hashchange', _.check);
},
check: function() {
_.callback(locationWrapper.get());
},
load: function(hash) {
locationWrapper.put(hash);
}
};

var _ = $.extend({}, implementations.base);

if($.browser.msie && ($.browser.version < 8 || document.documentMode < 8)) {
$.extend(_, IframeImpl);
_.type = 'iframeTimer';
} else if("onhashchange" in window) {
_.type = 'hashchangeEvent';
} else {
$.extend(_, SimpleImpl);
_.type = 'timer';
}

$.extend(_, implementations[_.type]);
$.history = _;
})(jQuery);
2 changes: 2 additions & 0 deletions samples/debugger/debugger.js
Expand Up @@ -13,6 +13,8 @@ $(document).ready(function() {
if($.browser.msie && $.browser.version == 8) {
$('#ie-info').text('You are using IE8 in version '+ document.documentMode +' compatible mode.');
}
$('#type-info').text('The plugin is running in '+ $.history.type +' mode.');


$.history.init(function (hash) {
Logger.append("[callback called] hash="+ hash);
Expand Down
1 change: 1 addition & 0 deletions samples/debugger/index.php
Expand Up @@ -81,6 +81,7 @@ function IEModeSelector() {
<h1>jQuery History Plugin Debugger Sample</h1>

<div id="ie-info"></div>
<div id="type-info"></div>
<ul class="history-links">
<li><a href="#1">load 1</a></li>
<li><a href="#2">load 2</a></li>
Expand Down

0 comments on commit 7ad0e52

Please sign in to comment.