1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00

static files:

- re-formatted: default_banner.js, queryWorker.js, search.js, wb_frame.js
This commit is contained in:
John Berlin 2019-09-04 14:59:50 -04:00
parent ae78a955de
commit 69f7f02006
No known key found for this signature in database
GPG Key ID: 6EF5E4B442011B02
4 changed files with 528 additions and 496 deletions

View File

@ -34,7 +34,7 @@ This file is part of pywb, https://github.com/webrecorder/pywb
this.captureInfo = null;
this.last_state = {};
this.state = null;
this.title = "";
this.title = '';
this.loadingId = 'bannerLoading';
this.onMessage = this.onMessage.bind(this);
}
@ -51,7 +51,7 @@ This file is part of pywb, https://github.com/webrecorder/pywb
window.wbinfo.url,
window.wbinfo.timestamp,
window.wbinfo.is_live,
window.wbinfo.is_framed ? "" : document.title
window.wbinfo.is_framed ? '' : document.title
);
} else {
this.createBanner('_wb_frame_top_banner');
@ -75,7 +75,7 @@ This file is part of pywb, https://github.com/webrecorder/pywb
*/
DefaultBanner.prototype.updateCaptureInfo = function(url, ts, is_live) {
if (is_live && !ts) {
ts = new Date().toISOString().replace(/[-T:.Z]/g, '')
ts = new Date().toISOString().replace(/[-T:.Z]/g, '');
}
this.set_banner(url, ts, is_live, null);
};
@ -88,11 +88,11 @@ This file is part of pywb, https://github.com/webrecorder/pywb
DefaultBanner.prototype.onMessage = function(event) {
var type = event.data.wb_type;
if (type === "load" || type === "replace-url") {
if (type === 'load' || type === 'replace-url') {
this.state = event.data;
this.last_state = this.state;
this.title = event.data.title || this.title;
} else if (type === "title") {
} else if (type === 'title') {
this.state = this.last_state;
this.title = event.data.title;
} else {
@ -119,7 +119,12 @@ This file is part of pywb, https://github.com/webrecorder/pywb
}
}
this.set_banner(this.state.url, this.state.ts, this.state.is_live, this.title);
this.set_banner(
this.state.url,
this.state.ts,
this.state.is_live,
this.title
);
};
// Functions internal to the default banner
@ -129,11 +134,12 @@ This file is part of pywb, https://github.com/webrecorder/pywb
* @param {string} bid - The id for the banner
*/
DefaultBanner.prototype.createBanner = function(bid) {
this.banner = document.createElement("wb_div", true);
this.banner.setAttribute("id", bid);
this.banner.setAttribute("lang", "en");
this.banner = document.createElement('wb_div', true);
this.banner.setAttribute('id', bid);
this.banner.setAttribute('lang', 'en');
this.captureInfo = document.createElement('span');
this.captureInfo.innerHTML = '<span id="' + this.loadingId + '">Loading...</span>';
this.captureInfo.innerHTML =
'<span id="' + this.loadingId + '">Loading...</span>';
this.captureInfo.id = '_wb_capture_info';
this.banner.appendChild(this.captureInfo);
document.body.insertBefore(this.banner, document.body.firstChild);
@ -149,19 +155,26 @@ This file is part of pywb, https://github.com/webrecorder/pywb
*/
DefaultBanner.prototype.ts_to_date = function(ts, is_gmt) {
if (!ts) {
return "";
return '';
}
if (ts.length < 14) {
ts += "00000000000000".substr(ts.length);
ts += '00000000000000'.substr(ts.length);
}
var datestr = (ts.substring(0, 4) + "-" +
ts.substring(4, 6) + "-" +
ts.substring(6, 8) + "T" +
ts.substring(8, 10) + ":" +
ts.substring(10, 12) + ":" +
ts.substring(12, 14) + "-00:00");
var datestr =
ts.substring(0, 4) +
'-' +
ts.substring(4, 6) +
'-' +
ts.substring(6, 8) +
'T' +
ts.substring(8, 10) +
':' +
ts.substring(10, 12) +
':' +
ts.substring(12, 14) +
'-00:00';
var date = new Date(datestr);
@ -196,17 +209,17 @@ This file is part of pywb, https://github.com/webrecorder/pywb
}
title_str = capture_str;
capture_str = "<b id='title_or_url'>" + capture_str + "</b>";
capture_str = "<b id='title_or_url'>" + capture_str + '</b>';
if (is_live) {
title_str = " pywb Live: " + title_str;
capture_str += "<i>Live on&nbsp;</i>";
title_str = ' pywb Live: ' + title_str;
capture_str += '<i>Live on&nbsp;</i>';
} else {
title_str += "pywb Archived: " + title_str;
capture_str += "<i>Archived on&nbsp;</i>";
title_str += 'pywb Archived: ' + title_str;
capture_str += '<i>Archived on&nbsp;</i>';
}
title_str += " (" + date_str + ")";
title_str += ' (' + date_str + ')';
capture_str += date_str;
this.captureInfo.innerHTML = capture_str;
window.document.title = title_str;
@ -215,5 +228,3 @@ This file is part of pywb, https://github.com/webrecorder/pywb
// all banners will expose themselves by adding themselves as WBBanner on window
window.WBBanner = new DefaultBanner();
})();

View File

@ -42,7 +42,8 @@ function defaultErrorCatcher(error) {
*/
function consumeResponseBodyAsStream(response) {
var reader = response.body.getReader();
reader.read()
reader
.read()
.then(function consumeStream(result) {
if (result.done) {
if (bufferedPreviousChunk) {
@ -58,7 +59,10 @@ function consumeResponseBodyAsStream(response) {
return;
}
transformChunk(result.value);
reader.read().then(consumeStream).catch(defaultErrorCatcher);
reader
.read()
.then(consumeStream)
.catch(defaultErrorCatcher);
})
.catch(defaultErrorCatcher);
}
@ -154,8 +158,11 @@ function handleCDXRecord(binaryCDXRecord) {
year: ts.substring(0, 4),
month: ts.substring(4, 6),
day: day.charAt(0) === '0' ? day.charAt(1) : day,
time: ts.substring(8, 10) + colon +
ts.substring(10, 12) + colon +
time:
ts.substring(8, 10) +
colon +
ts.substring(10, 12) +
colon +
ts.substring(12, 14)
},
wasError: false,
@ -163,9 +170,3 @@ function handleCDXRecord(binaryCDXRecord) {
recordCountFormatted: recordCount.toLocaleString()
});
}

View File

@ -32,11 +32,13 @@
resultsNewWindow: 'open-results-new-window'
};
function makeCheckDateRangeChecker(dtInputId, dtBadNotice) {
var dtInput = document.getElementById(dtInputId);
dtInput.onblur = function() {
if (dtInput.validity.valid && dtBadNotice.classList.contains(showBadDateTimeClass)) {
if (
dtInput.validity.valid &&
dtBadNotice.classList.contains(showBadDateTimeClass)
) {
return dtBadNotice.classList.remove(showBadDateTimeClass);
}
if (dtInput.validity.valueMissing) {
@ -80,7 +82,14 @@
filterList.removeChild(filterNothing);
}
var li = document.createElement('li');
li.innerText = 'By ' + by[0].toUpperCase() + by.substr(1) + ' ' + filterMods[modifier] + ' ' + expr;
li.innerText =
'By ' +
by[0].toUpperCase() +
by.substr(1) +
' ' +
filterMods[modifier] +
' ' +
expr;
li.dataset.filter = filterExpr;
var nukeButton = document.createElement('button');
nukeButton.type = 'button';
@ -114,7 +123,8 @@
function performQuery(url) {
var query = [window.wb_prefix + '*?url=' + url];
var filterExpressions = document.getElementById(elemIds.filtering.list).children;
var filterExpressions = document.getElementById(elemIds.filtering.list)
.children;
if (filterExpressions.length) {
for (var i = 0; i < filterExpressions.length; ++i) {
var fexpr = filterExpressions[i];
@ -153,8 +163,14 @@
container: 'body',
delay: { show: 1000 }
});
makeCheckDateRangeChecker(elemIds.dateTime.from, document.getElementById(elemIds.dateTime.fromBad));
makeCheckDateRangeChecker(elemIds.dateTime.to, document.getElementById(elemIds.dateTime.toBad));
makeCheckDateRangeChecker(
elemIds.dateTime.from,
document.getElementById(elemIds.dateTime.fromBad)
);
makeCheckDateRangeChecker(
elemIds.dateTime.to,
document.getElementById(elemIds.dateTime.toBad)
);
document.getElementById(elemIds.filtering.add).onclick = addFilter;
document.getElementById(elemIds.filtering.clear).onclick = clearFilters;
var searchURLInput = document.getElementById(elemIds.url);

View File

@ -17,7 +17,6 @@ This file is part of pywb, https://github.com/webrecorder/pywb
along with pywb. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @param {Object} content_info - Information about the contents to be replayed
*/
@ -39,7 +38,9 @@ function ContentFrame(content_info) {
if (document.readyState === 'complete') {
this.init_iframe();
} else {
document.addEventListener('DOMContentLoaded', this.init_iframe.bind(this), {once: true});
document.addEventListener('DOMContentLoaded', this.init_iframe.bind(this), {
once: true
});
}
window.__WB_pmw = function(win) {
@ -53,7 +54,7 @@ function ContentFrame(content_info) {
* then the init function of the banner is called.
*/
ContentFrame.prototype.init_iframe = function() {
if (typeof (this.content_info.iframe) === 'string') {
if (typeof this.content_info.iframe === 'string') {
this.iframe = document.querySelector(this.content_info.iframe);
} else {
this.iframe = this.content_info.iframe;
@ -77,7 +78,8 @@ ContentFrame.prototype.init_iframe = function () {
*/
ContentFrame.prototype.extract_prefix = function() {
this.app_prefix = this.content_info.app_prefix || this.content_info.prefix;
this.content_prefix = this.content_info.content_prefix || this.content_info.prefix;
this.content_prefix =
this.content_info.content_prefix || this.content_info.prefix;
if (this.app_prefix && this.content_prefix) {
return;
@ -142,7 +144,7 @@ ContentFrame.prototype.handle_event = function (event) {
frame_win.postMessage(event.data, '*');
} else if (event.source === frame_win) {
// Check if iframe url change message
if (typeof (event.data) === 'object' && event.data['wb_type']) {
if (typeof event.data === 'object' && event.data['wb_type']) {
this.handle_message(event);
} else {
// Pass to parent
@ -175,7 +177,10 @@ ContentFrame.prototype.handle_message = function (event) {
* @param {Object} state - The contents of a message rreceived from the replay iframe
*/
ContentFrame.prototype.set_url = function(state) {
if (state.url && (state.url !== this.last_url || state.request_ts !== this.last_ts)) {
if (
state.url &&
(state.url !== this.last_url || state.request_ts !== this.last_ts)
) {
var new_url = this.make_url(state.url, state.request_ts, false);
window.history.replaceState(state, '', new_url);
@ -216,7 +221,6 @@ ContentFrame.prototype.initBannerUpdateCheck = function (newUrl, newTs) {
this.iframe.addEventListener('load', replayIframeLoaded);
};
/**
* @desc Navigates the replay iframe to a newURL and if a banner is exposed
* the initBannerUpdateCheck function is called.
@ -252,7 +256,7 @@ ContentFrame.prototype.outer_hash_changed = function (event) {
}
if (this.iframe) {
var message = {'wb_type': 'outer_hashchange', 'hash': window.location.hash};
var message = { wb_type: 'outer_hashchange', hash: window.location.hash };
this.iframe.contentWindow.postMessage(message, '*', undefined, true);
}