From bbbd42eca3af7d7acf73b6dc8400992e3116d292 Mon Sep 17 00:00:00 2001 From: HelloZeroNet Date: Sat, 27 Feb 2016 21:39:36 +0100 Subject: [PATCH] Rev909, Inform inner frame on state change, wrapperGetState command to query current history state, Allow to pass null url to wrapperReplaceState and wrapperPushState --- src/Config.py | 2 +- src/Ui/media/Wrapper.coffee | 11 +++++++++-- src/Ui/media/all.js | 29 ++++++++++++++++++++++++++--- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/Config.py b/src/Config.py index 7c81870c..e372a4a2 100644 --- a/src/Config.py +++ b/src/Config.py @@ -8,7 +8,7 @@ class Config(object): def __init__(self, argv): self.version = "0.3.6" - self.rev = 908 + self.rev = 909 self.argv = argv self.action = None self.config_file = "zeronet.conf" diff --git a/src/Ui/media/Wrapper.coffee b/src/Ui/media/Wrapper.coffee index 746d934e..8889372c 100644 --- a/src/Ui/media/Wrapper.coffee +++ b/src/Ui/media/Wrapper.coffee @@ -26,12 +26,15 @@ class Wrapper @opener = null window.onload = @onLoad # On iframe loaded - $(window).on "hashchange", => # On hash change + window.onhashchange = (e) => # On hash change @log "Hashchange", window.location.hash if window.location.hash src = $("#inner-iframe").attr("src").replace(/#.*/, "")+window.location.hash $("#inner-iframe").attr("src", src) + window.onpopstate = (e) => + @sendInner {"cmd": "wrapperPopstate", "result": {"href": document.location.href, "state": e.state}} + $("#inner-iframe").focus() @@ -111,13 +114,17 @@ class Wrapper else if cmd == "wrapperReplaceState" query = @toRelativeQuery(message.params[2]) window.history.replaceState(message.params[0], message.params[1], query) + else if cmd == "wrapperGetState" + @sendInner {"cmd": "response", "to": message.id, "result": window.history.state} else # Send to websocket if message.id < 1000000 @ws.send(message) # Pass message to websocket else @log "Invalid inner message id" - toRelativeQuery: (query) -> + toRelativeQuery: (query=null) -> + if query == null + query = window.location.search back = window.location.pathname if back.slice(-1) != "/" back += "/" diff --git a/src/Ui/media/all.js b/src/Ui/media/all.js index f0435bf5..617f493e 100644 --- a/src/Ui/media/all.js +++ b/src/Ui/media/all.js @@ -783,8 +783,8 @@ jQuery.extend( jQuery.easing, this.address = null; this.opener = null; window.onload = this.onLoad; - $(window).on("hashchange", (function(_this) { - return function() { + window.onhashchange = (function(_this) { + return function(e) { var src; _this.log("Hashchange", window.location.hash); if (window.location.hash) { @@ -792,7 +792,18 @@ jQuery.extend( jQuery.easing, return $("#inner-iframe").attr("src", src); } }; - })(this)); + })(this); + window.onpopstate = (function(_this) { + return function(e) { + return _this.sendInner({ + "cmd": "wrapperPopstate", + "result": { + "href": document.location.href, + "state": e.state + } + }); + }; + })(this); $("#inner-iframe").focus(); } @@ -888,6 +899,12 @@ jQuery.extend( jQuery.easing, } else if (cmd === "wrapperReplaceState") { query = this.toRelativeQuery(message.params[2]); return window.history.replaceState(message.params[0], message.params[1], query); + } else if (cmd === "wrapperGetState") { + return this.sendInner({ + "cmd": "response", + "to": message.id, + "result": window.history.state + }); } else { if (message.id < 1000000) { return this.ws.send(message); @@ -899,6 +916,12 @@ jQuery.extend( jQuery.easing, Wrapper.prototype.toRelativeQuery = function(query) { var back; + if (query == null) { + query = null; + } + if (query === null) { + query = window.location.search; + } back = window.location.pathname; if (back.slice(-1) !== "/") { back += "/";