mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 06:59:52 +01:00
banner dynamic update:
- ensure banner updated in response to inner frame events
This commit is contained in:
parent
f8a73c0b03
commit
11b6794616
@ -5,6 +5,7 @@ class CDXLoader {
|
|||||||
constructor(staticPrefix, url, prefix, timestamp) {
|
constructor(staticPrefix, url, prefix, timestamp) {
|
||||||
this.opts = {};
|
this.opts = {};
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
|
this.staticPrefix = staticPrefix;
|
||||||
|
|
||||||
this.isReplay = (timestamp !== undefined);
|
this.isReplay = (timestamp !== undefined);
|
||||||
|
|
||||||
@ -12,19 +13,19 @@ class CDXLoader {
|
|||||||
window.WBBanner = new VueBannerWrapper(this);
|
window.WBBanner = new VueBannerWrapper(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.queryWorker = new Worker(staticPrefix + '/queryWorker.js');
|
let queryURL;
|
||||||
|
|
||||||
// query form *?=url...
|
// query form *?=url...
|
||||||
if (window.location.href.indexOf("*?") > 0) {
|
if (window.location.href.indexOf("*?") > 0) {
|
||||||
this.queryURL = window.location.href.replace("*?", "cdx?") + "&output=json";
|
queryURL = window.location.href.replace("*?", "cdx?") + "&output=json";
|
||||||
url = new URL(this.queryURL).searchParams.get("url");
|
url = new URL(queryURL).searchParams.get("url");
|
||||||
|
|
||||||
// otherwise, traditional calendar form /*/<url>
|
// otherwise, traditional calendar form /*/<url>
|
||||||
} else if (url) {
|
} else if (url) {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
params.set("url", url);
|
params.set("url", url);
|
||||||
params.set("output", "json");
|
params.set("output", "json");
|
||||||
this.queryURL = prefix + "cdx?" + params.toString();
|
queryURL = prefix + "cdx?" + params.toString();
|
||||||
|
|
||||||
// otherwise, an error since no URL
|
// otherwise, an error since no URL
|
||||||
} else {
|
} else {
|
||||||
@ -36,32 +37,60 @@ class CDXLoader {
|
|||||||
// TODO: make configurable
|
// TODO: make configurable
|
||||||
this.opts.logoImg = staticPrefix + "/pywb-logo-sm.png";
|
this.opts.logoImg = staticPrefix + "/pywb-logo-sm.png";
|
||||||
|
|
||||||
const cdxList = [];
|
this.loadCDX(queryURL).then((cdxList) => {
|
||||||
|
PywbVue.init(cdxList, this.opts, (snapshot) => this.loadSnapshot(snapshot));
|
||||||
this.queryWorker.addEventListener("message", (event) => {
|
|
||||||
const data = event.data;
|
|
||||||
switch (data.type) {
|
|
||||||
case "cdxRecord":
|
|
||||||
cdxList.push(data.record);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "finished":
|
|
||||||
PywbVue.init(cdxList, this.opts, (snapshot) => this.loadSnapshot(snapshot));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
async updateSnapshot(url, timestamp) {
|
||||||
this.queryWorker.postMessage({
|
const params = new URLSearchParams();
|
||||||
type: 'query',
|
params.set("url", url);
|
||||||
queryURL: this.queryURL
|
params.set("output", "json");
|
||||||
|
const queryURL = this.prefix + "cdx?" + params.toString();
|
||||||
|
|
||||||
|
const cdxList = await this.loadCDX(queryURL);
|
||||||
|
|
||||||
|
PywbVue.update(cdxList, {url, timestamp});
|
||||||
|
}
|
||||||
|
|
||||||
|
async loadCDX(queryURL) {
|
||||||
|
const queryWorker = new Worker(this.staticPrefix + '/queryWorker.js');
|
||||||
|
|
||||||
|
const p = new Promise((resolve) => {
|
||||||
|
const cdxList = [];
|
||||||
|
|
||||||
|
queryWorker.addEventListener("message", (event) => {
|
||||||
|
const data = event.data;
|
||||||
|
switch (data.type) {
|
||||||
|
case "cdxRecord":
|
||||||
|
cdxList.push(data.record);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "finished":
|
||||||
|
resolve(cdxList);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
queryWorker.postMessage({
|
||||||
|
type: 'query',
|
||||||
|
queryURL
|
||||||
|
});
|
||||||
|
|
||||||
|
const results = await p;
|
||||||
|
|
||||||
|
queryWorker.terminate();
|
||||||
|
//delete queryWorker;
|
||||||
|
|
||||||
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadSnapshot(snapshot) {
|
loadSnapshot(snapshot) {
|
||||||
if (!isReplay) {
|
if (!this.isReplay) {
|
||||||
window.location.href = this.prefix + snapshot.id + "/" + snapshot.url;
|
window.location.href = this.prefix + snapshot.id + "/" + snapshot.url;
|
||||||
|
} else if (cframe) {
|
||||||
|
cframe.load_url(snapshot.url, snapshot.id + "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -70,9 +99,10 @@ class CDXLoader {
|
|||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
class VueBannerWrapper
|
class VueBannerWrapper
|
||||||
{
|
{
|
||||||
constructor() {
|
constructor(loader) {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.lastUrl = null;
|
this.lastUrl = null;
|
||||||
|
this.loader = loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {}
|
init() {}
|
||||||
@ -86,6 +116,13 @@ class VueBannerWrapper
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMessage(event) {
|
onMessage(event) {
|
||||||
console.log(event);
|
const type = event.data.wb_type;
|
||||||
|
|
||||||
|
if (type === 'load' || type === 'replace-url') {
|
||||||
|
if (event.data.url !== this.lastUrl) {
|
||||||
|
this.loader.updateSnapshot(event.data.url, event.data.ts);
|
||||||
|
this.lastUrl = event.data.url;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
@ -33,7 +33,6 @@ window.banner_info = {
|
|||||||
<script src="{{ static_prefix }}/js/cdxquery.js"></script>
|
<script src="{{ static_prefix }}/js/cdxquery.js"></script>
|
||||||
<script>
|
<script>
|
||||||
var loader = new CDXLoader("{{ static_prefix }}", "{{ url }}", "{{ wb_prefix }}", "{{ timestamp }}");
|
var loader = new CDXLoader("{{ static_prefix }}", "{{ url }}", "{{ wb_prefix }}", "{{ timestamp }}");
|
||||||
loader.init();
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{% if not old_banner %}
|
{% if not old_banner %}
|
||||||
|
@ -54,7 +54,6 @@
|
|||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
var loader = new CDXLoader("{{ static_prefix }}", "{{ url }}", "{{ prefix }}");
|
var loader = new CDXLoader("{{ static_prefix }}", "{{ url }}", "{{ prefix }}");
|
||||||
loader.init();
|
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
@ -87,15 +87,18 @@ export default {
|
|||||||
if (!this.config.title) {
|
if (!this.config.title) {
|
||||||
this.config.title = this.config.initialView.url;
|
this.config.title = this.config.initialView.url;
|
||||||
}
|
}
|
||||||
if (this.config.initialView.timestamp === "undefined") {
|
if (this.config.initialView.timestamp === undefined) {
|
||||||
this.showFullView = true;
|
this.showFullView = true;
|
||||||
} else {
|
} else {
|
||||||
this.showFullView = false;
|
this.showFullView = false;
|
||||||
|
this.setSnapshot(this.config.initialView);
|
||||||
// convert to snapshot objec to support proper rendering of time/date
|
|
||||||
const snapshot = new PywbSnapshot(this.config.initialView, 0);
|
|
||||||
this.gotoSnapshot(snapshot);
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
setSnapshot(view) {
|
||||||
|
// convert to snapshot objec to support proper rendering of time/date
|
||||||
|
const snapshot = new PywbSnapshot(view, 0);
|
||||||
|
this.config.title = view.url;
|
||||||
|
this.gotoSnapshot(snapshot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -4,15 +4,16 @@ import { PywbData } from "./model.js";
|
|||||||
|
|
||||||
import Vue from "vue/dist/vue.esm.browser";
|
import Vue from "vue/dist/vue.esm.browser";
|
||||||
|
|
||||||
|
var app = null;
|
||||||
|
|
||||||
export function init(data, config = {}, loadCallback = null) {
|
export function init(data, config = {}, loadCallback = null) {
|
||||||
const app = new Vue(appData);
|
app = new Vue(appData);
|
||||||
|
|
||||||
const pywbData = new PywbData(data);
|
const pywbData = new PywbData(data);
|
||||||
|
|
||||||
app.$set(app, "snapshots", pywbData.snapshots);
|
app.$set(app, "snapshots", pywbData.snapshots);
|
||||||
app.$set(app, "currentPeriod", pywbData.timeline);
|
app.$set(app, "currentPeriod", pywbData.timeline);
|
||||||
|
|
||||||
//console.log({...app.config, ...config}.logoImg);
|
|
||||||
app.$set(app, "config", {...app.config, ...config});
|
app.$set(app, "config", {...app.config, ...config});
|
||||||
|
|
||||||
app.$mount("#app");
|
app.$mount("#app");
|
||||||
@ -21,3 +22,12 @@ export function init(data, config = {}, loadCallback = null) {
|
|||||||
app.$on("show-snapshot", loadCallback);
|
app.$on("show-snapshot", loadCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function update(data, snapshotData) {
|
||||||
|
const pywbData = new PywbData(data);
|
||||||
|
|
||||||
|
app.$set(app, "snapshots", pywbData.snapshots);
|
||||||
|
app.$set(app, "currentPeriod", pywbData.timeline);
|
||||||
|
|
||||||
|
app.setSnapshot(snapshotData);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user