Rev909, Inform inner frame on state change, wrapperGetState command to query current history state, Allow to pass null url to wrapperReplaceState and wrapperPushState

This commit is contained in:
HelloZeroNet 2016-02-27 21:39:36 +01:00
parent 58fa5f6e16
commit bbbd42eca3
3 changed files with 36 additions and 6 deletions

View file

@ -8,7 +8,7 @@ class Config(object):
def __init__(self, argv): def __init__(self, argv):
self.version = "0.3.6" self.version = "0.3.6"
self.rev = 908 self.rev = 909
self.argv = argv self.argv = argv
self.action = None self.action = None
self.config_file = "zeronet.conf" self.config_file = "zeronet.conf"

View file

@ -26,12 +26,15 @@ class Wrapper
@opener = null @opener = null
window.onload = @onLoad # On iframe loaded window.onload = @onLoad # On iframe loaded
$(window).on "hashchange", => # On hash change window.onhashchange = (e) => # On hash change
@log "Hashchange", window.location.hash @log "Hashchange", window.location.hash
if window.location.hash if window.location.hash
src = $("#inner-iframe").attr("src").replace(/#.*/, "")+window.location.hash src = $("#inner-iframe").attr("src").replace(/#.*/, "")+window.location.hash
$("#inner-iframe").attr("src", src) $("#inner-iframe").attr("src", src)
window.onpopstate = (e) =>
@sendInner {"cmd": "wrapperPopstate", "result": {"href": document.location.href, "state": e.state}}
$("#inner-iframe").focus() $("#inner-iframe").focus()
@ -111,13 +114,17 @@ class Wrapper
else if cmd == "wrapperReplaceState" else if cmd == "wrapperReplaceState"
query = @toRelativeQuery(message.params[2]) query = @toRelativeQuery(message.params[2])
window.history.replaceState(message.params[0], message.params[1], query) 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 else # Send to websocket
if message.id < 1000000 if message.id < 1000000
@ws.send(message) # Pass message to websocket @ws.send(message) # Pass message to websocket
else else
@log "Invalid inner message id" @log "Invalid inner message id"
toRelativeQuery: (query) -> toRelativeQuery: (query=null) ->
if query == null
query = window.location.search
back = window.location.pathname back = window.location.pathname
if back.slice(-1) != "/" if back.slice(-1) != "/"
back += "/" back += "/"

View file

@ -783,8 +783,8 @@ jQuery.extend( jQuery.easing,
this.address = null; this.address = null;
this.opener = null; this.opener = null;
window.onload = this.onLoad; window.onload = this.onLoad;
$(window).on("hashchange", (function(_this) { window.onhashchange = (function(_this) {
return function() { return function(e) {
var src; var src;
_this.log("Hashchange", window.location.hash); _this.log("Hashchange", window.location.hash);
if (window.location.hash) { if (window.location.hash) {
@ -792,7 +792,18 @@ jQuery.extend( jQuery.easing,
return $("#inner-iframe").attr("src", src); 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(); $("#inner-iframe").focus();
} }
@ -888,6 +899,12 @@ jQuery.extend( jQuery.easing,
} else if (cmd === "wrapperReplaceState") { } else if (cmd === "wrapperReplaceState") {
query = this.toRelativeQuery(message.params[2]); query = this.toRelativeQuery(message.params[2]);
return window.history.replaceState(message.params[0], message.params[1], query); 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 { } else {
if (message.id < 1000000) { if (message.id < 1000000) {
return this.ws.send(message); return this.ws.send(message);
@ -899,6 +916,12 @@ jQuery.extend( jQuery.easing,
Wrapper.prototype.toRelativeQuery = function(query) { Wrapper.prototype.toRelativeQuery = function(query) {
var back; var back;
if (query == null) {
query = null;
}
if (query === null) {
query = window.location.search;
}
back = window.location.pathname; back = window.location.pathname;
if (back.slice(-1) !== "/") { if (back.slice(-1) !== "/") {
back += "/"; back += "/";