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):
self.version = "0.3.6"
self.rev = 908
self.rev = 909
self.argv = argv
self.action = None
self.config_file = "zeronet.conf"

View File

@ -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 += "/"

View File

@ -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 += "/";