Commit 9bc145f3 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

Refactoring the extension

parent ef4585c29cce
......@@ -577,14 +577,11 @@ export function observeContent(
observable.content.length > 0
) {
// parse the html to retrieve its header
let doc = document.implementation.createDocument(
"http://www.w3.org/1999/xhtml",
"html",
null
let parser = new DOMParser();
let doc = parser.parseFromString(
observable.content,
observable.contentType
);
let html = doc.createElement("html");
html.innerHTML = observable.content;
while (html.hasChildNodes()) doc.appendChild(html.firstChild);
let otherLinks = findLinksInDocument(doc, observable.url, primary);
links = links.concat(otherLinks);
if (primary == null || primary == undefined || primary == "")
......
......@@ -32,7 +32,8 @@ import {
RawContent,
selectPrimaryTopic,
ObservableContent,
observeContent
observeContent,
ResourceUserCommand
} from "../common/data";
import {
getResourceContent,
......@@ -142,6 +143,10 @@ let browserLanguage = getBrowserLanguage();
* Initializes the browser
*/
function main() {
// display loading
currentApp = new MainViewer();
currentApp.onUpdate();
let target = getParameterByName("target");
let promise =
target == null || target == undefined || target == ""
......@@ -150,12 +155,9 @@ function main() {
promise
.then((observation: ResourceObservedData) => {
currentBrowser = new LDBrowserData(observation);
currentApp = new MainViewer();
currentApp.onUpdate();
onNavigatedTo(currentBrowser.history[0]);
})
.catch((reason: any) => {
currentApp = new MainViewer();
currentApp.onError(reason.toString());
});
}
......@@ -164,7 +166,21 @@ function main() {
* Executes the user request of navigating to a new resource
* @param uri The URI of the resource
*/
function onRequestNavigateTo(uri: string) {}
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());
});
}
/**
* When the data for a resource are ready
......@@ -180,6 +196,10 @@ 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);
})
......
Markdown is supported
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