Commit 3c486cf6 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

Fixed navigation in the browser

parent 63e9a5969777
......@@ -152,12 +152,20 @@ chrome.runtime.onMessage.addListener(function(
if (request.requestType == "GetCurrentResource") {
sendResponse(currentBrowser.history[currentBrowser.history.length - 1]);
} else if (request.requestType == "UpdateCurrentCommand") {
currentBrowser.history[currentBrowser.history.length - 1].command =
request.payload;
onNavigatedTo(currentBrowser.history[currentBrowser.history.length - 1]);
let resource = currentBrowser.history[currentBrowser.history.length - 1];
resource.command = request.payload;
onReachedResource(resource);
}
});
/**
* Listens to history state events from the browser
*/
window.onpopstate = function(event) {
let resource = event.state.resource;
onReachedResource(resource);
};
/**
* Initializes the browser
*/
......@@ -194,27 +202,48 @@ function main() {
* @param uri The URI of the resource
*/
function onRequestNavigateTo(uri: string) {
loadObservationsFor(uri)
.then((observation: ResourceObservedData) => {
let resource: ResourceData = {
observations: observation,
command: new ResourceUserCommand()
};
currentBrowser.history.push(resource);
currentBrowser.byResource[uri] = resource;
onNavigatedTo(currentBrowser.history[currentBrowser.history.length - 1]);
})
.catch((reason: any) => {
currentApp.onError(reason.toString());
});
let resource = currentBrowser.byResource[uri];
if (resource != null && resource != undefined) {
// already visited
onNavigatedTo(resource);
} else {
// loads the resource and then navigate to it
loadObservationsFor(uri)
.then((observation: ResourceObservedData) => {
let resource: ResourceData = {
observations: observation,
command: new ResourceUserCommand()
};
// register this resource
currentBrowser.history.push(resource);
currentBrowser.byResource[uri] = resource;
onNavigatedTo(resource);
})
.catch((reason: any) => {
currentApp.onError(reason.toString());
});
}
}
/**
* When the data for a resource are ready
* @param tabData The current data
* Executes the user request of navigating to a new resource
* @param resource The resource
*/
function onNavigatedTo(resource: ResourceData): void {
currentApp.onUpdate();
history.pushState(
{ resource: resource },
resource.observations.primaryTopic,
chrome.extension.getURL("ldbrowser/index.html?target=") +
encodeURIComponent(resource.observations.url)
);
onReachedResource(resource);
}
/**
* When the data for a resource are ready for rendering
* @param resource The resource
*/
function onReachedResource(resource: ResourceData): void {
loadRdfStore(resource)
.then((store: $rdf.Formula) => {
getViewRegistry()
......@@ -223,10 +252,6 @@ function onNavigatedTo(resource: ResourceData): void {
implementation
.newRenderer(registry, getResourceContent)
.then((renderer: application.ViewRenderer) => {
let url =
chrome.extension.getURL("ldbrowser/index.html?target=") +
encodeURIComponent(resource.observations.url);
history.pushState({}, resource.observations.primaryTopic, url);
let context = newRenderingContext(resource, store);
currentApp.onContent(renderer, context);
})
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment