Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improved history proxuing by adding screenjshistorychange event

  • Loading branch information...
commit 42b9b37ef78059dfe425717eef64871bcc733551 1 parent c5dbdc2
Amit Ambardekar authored
Showing with 52 additions and 36 deletions.
  1. +52 −36 public/screenjs-proxy.js
88 public/screenjs-proxy.js
View
@@ -212,51 +212,67 @@ window.open = function (open) {
};
})();
-// Handle pushState, replaceState navigation
-// TODO: In desperate need of re-factoring two functions below
-(function(history){
- var pushState = history.pushState;
- history.pushState = function(state) {
-
- if (typeof history.onpushstate == "function") {
- history.onpushstate({state: state});
+(function(){
+
+ function dispatchScreenjsHistorychangeEvent(){
+ var evt = document.createEvent("CustomEvent");
+ evt.initEvent("screenjshistorychange", true, true);
+ window.dispatchEvent(evt);
+ }
+
+ // Handle pushState, replaceState navigation
+ // TODO: In desperate need of re-factoring two functions below
+ (function(history){
+ var pushState = history.pushState;
+ history.pushState = function(state) {
+
+ if (typeof history.onpushstate == "function") {
+ history.onpushstate({state: state});
+ }
+
+ var screenjsBaseTag = document.head.getElementsByTagName("base")[0];
+ var originalBaseHref = screenjsBaseTag.href;
+ screenjsBaseTag.href = window.location.href;
+
+ var url = arguments[2];
+ arguments[2] = translateTargetUrlToRequestUrl(url);
+
+ var retVal = pushState.apply(history, arguments);
+ screenjsBaseTag.href = originalBaseHref;
+
+ dispatchScreenjsHistorychangeEvent();
+
+ return retVal;
}
+ })(window.history);
- var screenjsBaseTag = document.head.getElementsByTagName("base")[0];
- var originalBaseHref = screenjsBaseTag.href;
- screenjsBaseTag.href = window.location.href;
+ (function(history){
+ var replaceState = history.replaceState;
+ history.replaceState = function(state) {
- var url = arguments[2];
- arguments[2] = translateTargetUrlToRequestUrl(url);
+ // TODO: Find out if need to fire onpushstate
+ // event here
+ // if (typeof history.onpushstate == "function") {
+ // history.onpushstate({state: state});
+ // }
- var retVal = pushState.apply(history, arguments);
- screenjsBaseTag.href = originalBaseHref;
- return retVal;
- }
-})(window.history);
+ var screenjsBaseTag = document.head.getElementsByTagName("base")[0];
+ var originalBaseHref = screenjsBaseTag.href;
+ screenjsBaseTag.href = window.location.href;
-(function(history){
- var replaceState = history.replaceState;
- history.replaceState = function(state) {
+ var url = arguments[2];
+ arguments[2] = translateTargetUrlToRequestUrl(url);
- // TODO: Find out if need to fire onpushstate
- // event here
- // if (typeof history.onpushstate == "function") {
- // history.onpushstate({state: state});
- // }
+ var retVal = replaceState.apply(history, arguments);
+ screenjsBaseTag.href = originalBaseHref;
- var screenjsBaseTag = document.head.getElementsByTagName("base")[0];
- var originalBaseHref = screenjsBaseTag.href;
- screenjsBaseTag.href = window.location.href;
+ dispatchScreenjsHistorychangeEvent
- var url = arguments[2];
- arguments[2] = translateTargetUrlToRequestUrl(url);
+ return retVal;
+ }
+ })(window.history);
- var retVal = replaceState.apply(history, arguments);
- screenjsBaseTag.href = originalBaseHref;
- return retVal;
- }
-})(window.history);
+})();
var documentDomain = window.document;
Please sign in to comment.
Something went wrong with that request. Please try again.