Permalink
Browse files

Merge branch 'html5'

  • Loading branch information...
2 parents 318cdf4 + ab60e49 commit 7ad0e523195b776d665ca1a7f3816d8da22c42b5 Takayuki Miwa committed Sep 12, 2010
Showing with 57 additions and 27 deletions.
  1. +54 −27 jquery.history.js
  2. +2 −0 samples/debugger/debugger.js
  3. +1 −0 samples/debugger/index.php
View
@@ -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);
@@ -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);
@@ -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);
@@ -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>

0 comments on commit 7ad0e52

Please sign in to comment.