mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 23:19:52 +01:00
static files:
- re-formatted: default_banner.js, queryWorker.js, search.js, wb_frame.js
This commit is contained in:
parent
ae78a955de
commit
69f7f02006
@ -20,7 +20,7 @@ This file is part of pywb, https://github.com/webrecorder/pywb
|
|||||||
|
|
||||||
// Creates the default pywb banner.
|
// Creates the default pywb banner.
|
||||||
|
|
||||||
(function () {
|
(function() {
|
||||||
if (window.top !== window) {
|
if (window.top !== window) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ This file is part of pywb, https://github.com/webrecorder/pywb
|
|||||||
this.captureInfo = null;
|
this.captureInfo = null;
|
||||||
this.last_state = {};
|
this.last_state = {};
|
||||||
this.state = null;
|
this.state = null;
|
||||||
this.title = "";
|
this.title = '';
|
||||||
this.loadingId = 'bannerLoading';
|
this.loadingId = 'bannerLoading';
|
||||||
this.onMessage = this.onMessage.bind(this);
|
this.onMessage = this.onMessage.bind(this);
|
||||||
}
|
}
|
||||||
@ -44,14 +44,14 @@ This file is part of pywb, https://github.com/webrecorder/pywb
|
|||||||
/**
|
/**
|
||||||
* @desc Initialize (display) the banner
|
* @desc Initialize (display) the banner
|
||||||
*/
|
*/
|
||||||
DefaultBanner.prototype.init = function () {
|
DefaultBanner.prototype.init = function() {
|
||||||
if (window.wbinfo) {
|
if (window.wbinfo) {
|
||||||
this.createBanner('_wb_plain_banner');
|
this.createBanner('_wb_plain_banner');
|
||||||
this.set_banner(
|
this.set_banner(
|
||||||
window.wbinfo.url,
|
window.wbinfo.url,
|
||||||
window.wbinfo.timestamp,
|
window.wbinfo.timestamp,
|
||||||
window.wbinfo.is_live,
|
window.wbinfo.is_live,
|
||||||
window.wbinfo.is_framed ? "" : document.title
|
window.wbinfo.is_framed ? '' : document.title
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.createBanner('_wb_frame_top_banner');
|
this.createBanner('_wb_frame_top_banner');
|
||||||
@ -63,7 +63,7 @@ This file is part of pywb, https://github.com/webrecorder/pywb
|
|||||||
* that the page is loading
|
* that the page is loading
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
DefaultBanner.prototype.stillIndicatesLoading = function () {
|
DefaultBanner.prototype.stillIndicatesLoading = function() {
|
||||||
return document.getElementById(this.loadingId) != null;
|
return document.getElementById(this.loadingId) != null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -73,9 +73,9 @@ This file is part of pywb, https://github.com/webrecorder/pywb
|
|||||||
* If we are in live mode this is undefined/empty string
|
* If we are in live mode this is undefined/empty string
|
||||||
* @param {boolean} is_live - A bool indicating if we are operating in live mode
|
* @param {boolean} is_live - A bool indicating if we are operating in live mode
|
||||||
*/
|
*/
|
||||||
DefaultBanner.prototype.updateCaptureInfo = function (url, ts, is_live) {
|
DefaultBanner.prototype.updateCaptureInfo = function(url, ts, is_live) {
|
||||||
if (is_live && !ts) {
|
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);
|
this.set_banner(url, ts, is_live, null);
|
||||||
};
|
};
|
||||||
@ -85,14 +85,14 @@ This file is part of pywb, https://github.com/webrecorder/pywb
|
|||||||
* @param {MessageEvent} event - The message event containing the message received
|
* @param {MessageEvent} event - The message event containing the message received
|
||||||
* from the replayed page
|
* from the replayed page
|
||||||
*/
|
*/
|
||||||
DefaultBanner.prototype.onMessage = function (event) {
|
DefaultBanner.prototype.onMessage = function(event) {
|
||||||
var type = event.data.wb_type;
|
var type = event.data.wb_type;
|
||||||
|
|
||||||
if (type === "load" || type === "replace-url") {
|
if (type === 'load' || type === 'replace-url') {
|
||||||
this.state = event.data;
|
this.state = event.data;
|
||||||
this.last_state = this.state;
|
this.last_state = this.state;
|
||||||
this.title = event.data.title || this.title;
|
this.title = event.data.title || this.title;
|
||||||
} else if (type === "title") {
|
} else if (type === 'title') {
|
||||||
this.state = this.last_state;
|
this.state = this.last_state;
|
||||||
this.title = event.data.title;
|
this.title = event.data.title;
|
||||||
} else {
|
} 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
|
// Functions internal to the default banner
|
||||||
@ -128,12 +133,13 @@ This file is part of pywb, https://github.com/webrecorder/pywb
|
|||||||
* @desc Creates the underlying HTML elements comprising the banner
|
* @desc Creates the underlying HTML elements comprising the banner
|
||||||
* @param {string} bid - The id for the banner
|
* @param {string} bid - The id for the banner
|
||||||
*/
|
*/
|
||||||
DefaultBanner.prototype.createBanner = function (bid) {
|
DefaultBanner.prototype.createBanner = function(bid) {
|
||||||
this.banner = document.createElement("wb_div", true);
|
this.banner = document.createElement('wb_div', true);
|
||||||
this.banner.setAttribute("id", bid);
|
this.banner.setAttribute('id', bid);
|
||||||
this.banner.setAttribute("lang", "en");
|
this.banner.setAttribute('lang', 'en');
|
||||||
this.captureInfo = document.createElement('span');
|
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.captureInfo.id = '_wb_capture_info';
|
||||||
this.banner.appendChild(this.captureInfo);
|
this.banner.appendChild(this.captureInfo);
|
||||||
document.body.insertBefore(this.banner, document.body.firstChild);
|
document.body.insertBefore(this.banner, document.body.firstChild);
|
||||||
@ -147,21 +153,28 @@ This file is part of pywb, https://github.com/webrecorder/pywb
|
|||||||
* @param {boolean} is_gmt - Is the returned date string to be in GMT time
|
* @param {boolean} is_gmt - Is the returned date string to be in GMT time
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
DefaultBanner.prototype.ts_to_date = function (ts, is_gmt) {
|
DefaultBanner.prototype.ts_to_date = function(ts, is_gmt) {
|
||||||
if (!ts) {
|
if (!ts) {
|
||||||
return "";
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ts.length < 14) {
|
if (ts.length < 14) {
|
||||||
ts += "00000000000000".substr(ts.length);
|
ts += '00000000000000'.substr(ts.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
var datestr = (ts.substring(0, 4) + "-" +
|
var datestr =
|
||||||
ts.substring(4, 6) + "-" +
|
ts.substring(0, 4) +
|
||||||
ts.substring(6, 8) + "T" +
|
'-' +
|
||||||
ts.substring(8, 10) + ":" +
|
ts.substring(4, 6) +
|
||||||
ts.substring(10, 12) + ":" +
|
'-' +
|
||||||
ts.substring(12, 14) + "-00:00");
|
ts.substring(6, 8) +
|
||||||
|
'T' +
|
||||||
|
ts.substring(8, 10) +
|
||||||
|
':' +
|
||||||
|
ts.substring(10, 12) +
|
||||||
|
':' +
|
||||||
|
ts.substring(12, 14) +
|
||||||
|
'-00:00';
|
||||||
|
|
||||||
var date = new Date(datestr);
|
var date = new Date(datestr);
|
||||||
|
|
||||||
@ -179,7 +192,7 @@ This file is part of pywb, https://github.com/webrecorder/pywb
|
|||||||
* @param {boolean} is_live - Are we in live mode
|
* @param {boolean} is_live - Are we in live mode
|
||||||
* @param {?string} title - The title of the replayed page to be displayed in the banner
|
* @param {?string} title - The title of the replayed page to be displayed in the banner
|
||||||
*/
|
*/
|
||||||
DefaultBanner.prototype.set_banner = function (url, ts, is_live, title) {
|
DefaultBanner.prototype.set_banner = function(url, ts, is_live, title) {
|
||||||
var capture_str;
|
var capture_str;
|
||||||
var title_str;
|
var title_str;
|
||||||
|
|
||||||
@ -196,17 +209,17 @@ This file is part of pywb, https://github.com/webrecorder/pywb
|
|||||||
}
|
}
|
||||||
|
|
||||||
title_str = capture_str;
|
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) {
|
if (is_live) {
|
||||||
title_str = " pywb Live: " + title_str;
|
title_str = ' pywb Live: ' + title_str;
|
||||||
capture_str += "<i>Live on </i>";
|
capture_str += '<i>Live on </i>';
|
||||||
} else {
|
} else {
|
||||||
title_str += "pywb Archived: " + title_str;
|
title_str += 'pywb Archived: ' + title_str;
|
||||||
capture_str += "<i>Archived on </i>";
|
capture_str += '<i>Archived on </i>';
|
||||||
}
|
}
|
||||||
|
|
||||||
title_str += " (" + date_str + ")";
|
title_str += ' (' + date_str + ')';
|
||||||
capture_str += date_str;
|
capture_str += date_str;
|
||||||
this.captureInfo.innerHTML = capture_str;
|
this.captureInfo.innerHTML = capture_str;
|
||||||
window.document.title = title_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
|
// all banners will expose themselves by adding themselves as WBBanner on window
|
||||||
window.WBBanner = new DefaultBanner();
|
window.WBBanner = new DefaultBanner();
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ var decoder = new TextDecoder('utf-8');
|
|||||||
*/
|
*/
|
||||||
var bufferedPreviousChunk = null;
|
var bufferedPreviousChunk = null;
|
||||||
|
|
||||||
self.onmessage = function (event) {
|
self.onmessage = function(event) {
|
||||||
var data = event.data;
|
var data = event.data;
|
||||||
if (data.type === 'query') {
|
if (data.type === 'query') {
|
||||||
fetch(data.queryURL)
|
fetch(data.queryURL)
|
||||||
@ -42,7 +42,8 @@ function defaultErrorCatcher(error) {
|
|||||||
*/
|
*/
|
||||||
function consumeResponseBodyAsStream(response) {
|
function consumeResponseBodyAsStream(response) {
|
||||||
var reader = response.body.getReader();
|
var reader = response.body.getReader();
|
||||||
reader.read()
|
reader
|
||||||
|
.read()
|
||||||
.then(function consumeStream(result) {
|
.then(function consumeStream(result) {
|
||||||
if (result.done) {
|
if (result.done) {
|
||||||
if (bufferedPreviousChunk) {
|
if (bufferedPreviousChunk) {
|
||||||
@ -58,7 +59,10 @@ function consumeResponseBodyAsStream(response) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
transformChunk(result.value);
|
transformChunk(result.value);
|
||||||
reader.read().then(consumeStream).catch(defaultErrorCatcher);
|
reader
|
||||||
|
.read()
|
||||||
|
.then(consumeStream)
|
||||||
|
.catch(defaultErrorCatcher);
|
||||||
})
|
})
|
||||||
.catch(defaultErrorCatcher);
|
.catch(defaultErrorCatcher);
|
||||||
}
|
}
|
||||||
@ -154,8 +158,11 @@ function handleCDXRecord(binaryCDXRecord) {
|
|||||||
year: ts.substring(0, 4),
|
year: ts.substring(0, 4),
|
||||||
month: ts.substring(4, 6),
|
month: ts.substring(4, 6),
|
||||||
day: day.charAt(0) === '0' ? day.charAt(1) : day,
|
day: day.charAt(0) === '0' ? day.charAt(1) : day,
|
||||||
time: ts.substring(8, 10) + colon +
|
time:
|
||||||
ts.substring(10, 12) + colon +
|
ts.substring(8, 10) +
|
||||||
|
colon +
|
||||||
|
ts.substring(10, 12) +
|
||||||
|
colon +
|
||||||
ts.substring(12, 14)
|
ts.substring(12, 14)
|
||||||
},
|
},
|
||||||
wasError: false,
|
wasError: false,
|
||||||
@ -163,9 +170,3 @@ function handleCDXRecord(binaryCDXRecord) {
|
|||||||
recordCountFormatted: recordCount.toLocaleString()
|
recordCountFormatted: recordCount.toLocaleString()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
var dtRE = /^\d{4,14}$/;
|
var dtRE = /^\d{4,14}$/;
|
||||||
var didSetWasValidated = false;
|
var didSetWasValidated = false;
|
||||||
var showBadDateTimeClass = 'show-optional-bad-input';
|
var showBadDateTimeClass = 'show-optional-bad-input';
|
||||||
var filterMods = {
|
var filterMods = {
|
||||||
'=': 'Contains',
|
'=': 'Contains',
|
||||||
'==': 'Matches Exactly',
|
'==': 'Matches Exactly',
|
||||||
'=~': 'Matches Regex',
|
'=~': 'Matches Regex',
|
||||||
'=!': 'Does Not Contains',
|
'=!': 'Does Not Contains',
|
||||||
'=!=': 'Is Not',
|
'=!=': 'Is Not',
|
||||||
'=!~': 'Does Not Begins With'
|
'=!~': 'Does Not Begins With'
|
||||||
};
|
};
|
||||||
|
|
||||||
var elemIds = {
|
var elemIds = {
|
||||||
filtering: {
|
filtering: {
|
||||||
by: 'filter-by',
|
by: 'filter-by',
|
||||||
modifier: 'filter-modifier',
|
modifier: 'filter-modifier',
|
||||||
@ -30,13 +30,15 @@
|
|||||||
url: 'search-url',
|
url: 'search-url',
|
||||||
form: 'search-form',
|
form: 'search-form',
|
||||||
resultsNewWindow: 'open-results-new-window'
|
resultsNewWindow: 'open-results-new-window'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function makeCheckDateRangeChecker(dtInputId, dtBadNotice) {
|
||||||
function makeCheckDateRangeChecker(dtInputId, dtBadNotice) {
|
|
||||||
var dtInput = document.getElementById(dtInputId);
|
var dtInput = document.getElementById(dtInputId);
|
||||||
dtInput.onblur = function () {
|
dtInput.onblur = function() {
|
||||||
if (dtInput.validity.valid && dtBadNotice.classList.contains(showBadDateTimeClass)) {
|
if (
|
||||||
|
dtInput.validity.valid &&
|
||||||
|
dtBadNotice.classList.contains(showBadDateTimeClass)
|
||||||
|
) {
|
||||||
return dtBadNotice.classList.remove(showBadDateTimeClass);
|
return dtBadNotice.classList.remove(showBadDateTimeClass);
|
||||||
}
|
}
|
||||||
if (dtInput.validity.valueMissing) {
|
if (dtInput.validity.valueMissing) {
|
||||||
@ -58,16 +60,16 @@
|
|||||||
dtBadNotice.classList.add(showBadDateTimeClass);
|
dtBadNotice.classList.add(showBadDateTimeClass);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function createAndAddNoFilter(filterList) {
|
function createAndAddNoFilter(filterList) {
|
||||||
var nothing = document.createElement('li');
|
var nothing = document.createElement('li');
|
||||||
nothing.innerText = 'No Filter';
|
nothing.innerText = 'No Filter';
|
||||||
nothing.id = elemIds.filtering.nothing;
|
nothing.id = elemIds.filtering.nothing;
|
||||||
filterList.appendChild(nothing);
|
filterList.appendChild(nothing);
|
||||||
}
|
}
|
||||||
|
|
||||||
function addFilter(event) {
|
function addFilter(event) {
|
||||||
var by = document.getElementById(elemIds.filtering.by).value;
|
var by = document.getElementById(elemIds.filtering.by).value;
|
||||||
if (!by) return;
|
if (!by) return;
|
||||||
var modifier = document.getElementById(elemIds.filtering.modifier).value;
|
var modifier = document.getElementById(elemIds.filtering.modifier).value;
|
||||||
@ -80,7 +82,14 @@
|
|||||||
filterList.removeChild(filterNothing);
|
filterList.removeChild(filterNothing);
|
||||||
}
|
}
|
||||||
var li = document.createElement('li');
|
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;
|
li.dataset.filter = filterExpr;
|
||||||
var nukeButton = document.createElement('button');
|
var nukeButton = document.createElement('button');
|
||||||
nukeButton.type = 'button';
|
nukeButton.type = 'button';
|
||||||
@ -92,7 +101,7 @@
|
|||||||
buttonX.innerHTML = '×';
|
buttonX.innerHTML = '×';
|
||||||
buttonX.setAttribute('aria-hidden', 'true');
|
buttonX.setAttribute('aria-hidden', 'true');
|
||||||
nukeButton.appendChild(buttonX);
|
nukeButton.appendChild(buttonX);
|
||||||
nukeButton.onclick = function () {
|
nukeButton.onclick = function() {
|
||||||
filterList.removeChild(li);
|
filterList.removeChild(li);
|
||||||
if (filterList.children.length === 0) {
|
if (filterList.children.length === 0) {
|
||||||
createAndAddNoFilter(filterList);
|
createAndAddNoFilter(filterList);
|
||||||
@ -100,9 +109,9 @@
|
|||||||
};
|
};
|
||||||
li.appendChild(nukeButton);
|
li.appendChild(nukeButton);
|
||||||
filterList.appendChild(li);
|
filterList.appendChild(li);
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearFilters(event) {
|
function clearFilters(event) {
|
||||||
if (document.getElementById(elemIds.filtering.nothing)) return;
|
if (document.getElementById(elemIds.filtering.nothing)) return;
|
||||||
var filterList = document.getElementById(elemIds.filtering.list);
|
var filterList = document.getElementById(elemIds.filtering.list);
|
||||||
while (filterList.firstElementChild) {
|
while (filterList.firstElementChild) {
|
||||||
@ -110,11 +119,12 @@
|
|||||||
filterList.removeChild(filterList.firstElementChild);
|
filterList.removeChild(filterList.firstElementChild);
|
||||||
}
|
}
|
||||||
createAndAddNoFilter(filterList);
|
createAndAddNoFilter(filterList);
|
||||||
}
|
}
|
||||||
|
|
||||||
function performQuery(url) {
|
function performQuery(url) {
|
||||||
var query = [window.wb_prefix + '*?url=' + 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) {
|
if (filterExpressions.length) {
|
||||||
for (var i = 0; i < filterExpressions.length; ++i) {
|
for (var i = 0; i < filterExpressions.length; ++i) {
|
||||||
var fexpr = filterExpressions[i];
|
var fexpr = filterExpressions[i];
|
||||||
@ -146,20 +156,26 @@
|
|||||||
} else {
|
} else {
|
||||||
document.location.href = builtQuery;
|
document.location.href = builtQuery;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function() {
|
||||||
$('[data-toggle="tooltip"]').tooltip({
|
$('[data-toggle="tooltip"]').tooltip({
|
||||||
container: 'body',
|
container: 'body',
|
||||||
delay: { show: 1000 }
|
delay: { show: 1000 }
|
||||||
});
|
});
|
||||||
makeCheckDateRangeChecker(elemIds.dateTime.from, document.getElementById(elemIds.dateTime.fromBad));
|
makeCheckDateRangeChecker(
|
||||||
makeCheckDateRangeChecker(elemIds.dateTime.to, document.getElementById(elemIds.dateTime.toBad));
|
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.add).onclick = addFilter;
|
||||||
document.getElementById(elemIds.filtering.clear).onclick = clearFilters;
|
document.getElementById(elemIds.filtering.clear).onclick = clearFilters;
|
||||||
var searchURLInput = document.getElementById(elemIds.url);
|
var searchURLInput = document.getElementById(elemIds.url);
|
||||||
var form = document.getElementById(elemIds.form);
|
var form = document.getElementById(elemIds.form);
|
||||||
form.addEventListener('submit', function (event) {
|
form.addEventListener('submit', function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
var url = searchURLInput.value;
|
var url = searchURLInput.value;
|
||||||
@ -172,4 +188,4 @@
|
|||||||
}
|
}
|
||||||
performQuery(url);
|
performQuery(url);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -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/>.
|
along with pywb. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} content_info - Information about the contents to be replayed
|
* @param {Object} content_info - Information about the contents to be replayed
|
||||||
*/
|
*/
|
||||||
@ -39,10 +38,12 @@ function ContentFrame(content_info) {
|
|||||||
if (document.readyState === 'complete') {
|
if (document.readyState === 'complete') {
|
||||||
this.init_iframe();
|
this.init_iframe();
|
||||||
} else {
|
} 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) {
|
window.__WB_pmw = function(win) {
|
||||||
this.pm_source = win;
|
this.pm_source = win;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
@ -52,8 +53,8 @@ function ContentFrame(content_info) {
|
|||||||
* @desc Initializes the replay iframe. If a banner exists (exposed on window as WBBanner)
|
* @desc Initializes the replay iframe. If a banner exists (exposed on window as WBBanner)
|
||||||
* then the init function of the banner is called.
|
* then the init function of the banner is called.
|
||||||
*/
|
*/
|
||||||
ContentFrame.prototype.init_iframe = function () {
|
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);
|
this.iframe = document.querySelector(this.content_info.iframe);
|
||||||
} else {
|
} else {
|
||||||
this.iframe = this.content_info.iframe;
|
this.iframe = this.content_info.iframe;
|
||||||
@ -75,9 +76,10 @@ ContentFrame.prototype.init_iframe = function () {
|
|||||||
/**
|
/**
|
||||||
* @desc Initializes the prefixes used to load the pages to be replayed
|
* @desc Initializes the prefixes used to load the pages to be replayed
|
||||||
*/
|
*/
|
||||||
ContentFrame.prototype.extract_prefix = function () {
|
ContentFrame.prototype.extract_prefix = function() {
|
||||||
this.app_prefix = this.content_info.app_prefix || this.content_info.prefix;
|
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) {
|
if (this.app_prefix && this.content_prefix) {
|
||||||
return;
|
return;
|
||||||
@ -109,7 +111,7 @@ ContentFrame.prototype.extract_prefix = function () {
|
|||||||
* @param {?boolean} content_url - Is the abs URL to be constructed using the content_prefix or app_prefix
|
* @param {?boolean} content_url - Is the abs URL to be constructed using the content_prefix or app_prefix
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
ContentFrame.prototype.make_url = function (url, ts, content_url) {
|
ContentFrame.prototype.make_url = function(url, ts, content_url) {
|
||||||
var mod, prefix;
|
var mod, prefix;
|
||||||
|
|
||||||
if (content_url) {
|
if (content_url) {
|
||||||
@ -135,14 +137,14 @@ ContentFrame.prototype.make_url = function (url, ts, content_url) {
|
|||||||
* @desc Handles and routes all messages received from the replay iframe.
|
* @desc Handles and routes all messages received from the replay iframe.
|
||||||
* @param {MessageEvent} event - A message event potentially containing a message from the replay iframe
|
* @param {MessageEvent} event - A message event potentially containing a message from the replay iframe
|
||||||
*/
|
*/
|
||||||
ContentFrame.prototype.handle_event = function (event) {
|
ContentFrame.prototype.handle_event = function(event) {
|
||||||
var frame_win = this.iframe.contentWindow;
|
var frame_win = this.iframe.contentWindow;
|
||||||
if (event.source === window.parent) {
|
if (event.source === window.parent) {
|
||||||
// Pass to replay frame
|
// Pass to replay frame
|
||||||
frame_win.postMessage(event.data, '*');
|
frame_win.postMessage(event.data, '*');
|
||||||
} else if (event.source === frame_win) {
|
} else if (event.source === frame_win) {
|
||||||
// Check if iframe url change message
|
// 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);
|
this.handle_message(event);
|
||||||
} else {
|
} else {
|
||||||
// Pass to parent
|
// Pass to parent
|
||||||
@ -156,7 +158,7 @@ ContentFrame.prototype.handle_event = function (event) {
|
|||||||
* is exposed, calls the onMessage function of the exposed banner.
|
* is exposed, calls the onMessage function of the exposed banner.
|
||||||
* @param {MessageEvent} event - The message event containing a message from the replay iframe
|
* @param {MessageEvent} event - The message event containing a message from the replay iframe
|
||||||
*/
|
*/
|
||||||
ContentFrame.prototype.handle_message = function (event) {
|
ContentFrame.prototype.handle_message = function(event) {
|
||||||
if (this.wbBanner) {
|
if (this.wbBanner) {
|
||||||
this.wbBanner.onMessage(event);
|
this.wbBanner.onMessage(event);
|
||||||
}
|
}
|
||||||
@ -174,8 +176,11 @@ ContentFrame.prototype.handle_message = function (event) {
|
|||||||
* @desc Updates the URL of the top frame
|
* @desc Updates the URL of the top frame
|
||||||
* @param {Object} state - The contents of a message rreceived from the replay iframe
|
* @param {Object} state - The contents of a message rreceived from the replay iframe
|
||||||
*/
|
*/
|
||||||
ContentFrame.prototype.set_url = function (state) {
|
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);
|
var new_url = this.make_url(state.url, state.request_ts, false);
|
||||||
|
|
||||||
window.history.replaceState(state, '', new_url);
|
window.history.replaceState(state, '', new_url);
|
||||||
@ -194,12 +199,12 @@ ContentFrame.prototype.set_url = function (state) {
|
|||||||
* @param {?string} newTs - The new timestamp of the replay iframe. Is falsy if
|
* @param {?string} newTs - The new timestamp of the replay iframe. Is falsy if
|
||||||
* operating in live mode
|
* operating in live mode
|
||||||
*/
|
*/
|
||||||
ContentFrame.prototype.initBannerUpdateCheck = function (newUrl, newTs) {
|
ContentFrame.prototype.initBannerUpdateCheck = function(newUrl, newTs) {
|
||||||
if (!this.wbBanner) return;
|
if (!this.wbBanner) return;
|
||||||
var contentFrame = this;
|
var contentFrame = this;
|
||||||
var replayIframeLoaded = function () {
|
var replayIframeLoaded = function() {
|
||||||
contentFrame.iframe.removeEventListener('load', replayIframeLoaded);
|
contentFrame.iframe.removeEventListener('load', replayIframeLoaded);
|
||||||
contentFrame.checkBannerToId = setTimeout(function () {
|
contentFrame.checkBannerToId = setTimeout(function() {
|
||||||
contentFrame.checkBannerToId = null;
|
contentFrame.checkBannerToId = null;
|
||||||
if (contentFrame.wbBanner.stillIndicatesLoading()) {
|
if (contentFrame.wbBanner.stillIndicatesLoading()) {
|
||||||
contentFrame.wbBanner.updateCaptureInfo(
|
contentFrame.wbBanner.updateCaptureInfo(
|
||||||
@ -216,7 +221,6 @@ ContentFrame.prototype.initBannerUpdateCheck = function (newUrl, newTs) {
|
|||||||
this.iframe.addEventListener('load', replayIframeLoaded);
|
this.iframe.addEventListener('load', replayIframeLoaded);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc Navigates the replay iframe to a newURL and if a banner is exposed
|
* @desc Navigates the replay iframe to a newURL and if a banner is exposed
|
||||||
* the initBannerUpdateCheck function is called.
|
* the initBannerUpdateCheck function is called.
|
||||||
@ -224,7 +228,7 @@ ContentFrame.prototype.initBannerUpdateCheck = function (newUrl, newTs) {
|
|||||||
* @param {?string} newTs - The new timestamp of the replay iframe. Is falsy if
|
* @param {?string} newTs - The new timestamp of the replay iframe. Is falsy if
|
||||||
* operating in live mode
|
* operating in live mode
|
||||||
*/
|
*/
|
||||||
ContentFrame.prototype.load_url = function (newUrl, newTs) {
|
ContentFrame.prototype.load_url = function(newUrl, newTs) {
|
||||||
this.iframe.src = this.make_url(newUrl, newTs, true);
|
this.iframe.src = this.make_url(newUrl, newTs, true);
|
||||||
if (this.wbBanner) {
|
if (this.wbBanner) {
|
||||||
this.initBannerUpdateCheck(newUrl, newTs);
|
this.initBannerUpdateCheck(newUrl, newTs);
|
||||||
@ -235,7 +239,7 @@ ContentFrame.prototype.load_url = function (newUrl, newTs) {
|
|||||||
* @desc Updates this frames hash to the one inside the replay iframe
|
* @desc Updates this frames hash to the one inside the replay iframe
|
||||||
* @param {Object} state - The contents of message received from the replay iframe
|
* @param {Object} state - The contents of message received from the replay iframe
|
||||||
*/
|
*/
|
||||||
ContentFrame.prototype.inner_hash_changed = function (state) {
|
ContentFrame.prototype.inner_hash_changed = function(state) {
|
||||||
if (window.location.hash !== state.hash) {
|
if (window.location.hash !== state.hash) {
|
||||||
window.location.hash = state.hash;
|
window.location.hash = state.hash;
|
||||||
}
|
}
|
||||||
@ -246,13 +250,13 @@ ContentFrame.prototype.inner_hash_changed = function (state) {
|
|||||||
* @desc Updates the hash of the replay iframe on a hash change in this frame
|
* @desc Updates the hash of the replay iframe on a hash change in this frame
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
ContentFrame.prototype.outer_hash_changed = function (event) {
|
ContentFrame.prototype.outer_hash_changed = function(event) {
|
||||||
if (window.location.hash === this.last_inner_hash) {
|
if (window.location.hash === this.last_inner_hash) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.iframe) {
|
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);
|
this.iframe.contentWindow.postMessage(message, '*', undefined, true);
|
||||||
}
|
}
|
||||||
@ -261,7 +265,7 @@ ContentFrame.prototype.outer_hash_changed = function (event) {
|
|||||||
/**
|
/**
|
||||||
* @desc Cleans up any event listeners added by the content frame
|
* @desc Cleans up any event listeners added by the content frame
|
||||||
*/
|
*/
|
||||||
ContentFrame.prototype.close = function () {
|
ContentFrame.prototype.close = function() {
|
||||||
window.removeEventListener('hashchange', this.outer_hash_changed);
|
window.removeEventListener('hashchange', this.outer_hash_changed);
|
||||||
window.removeEventListener('message', this.handle_event);
|
window.removeEventListener('message', this.handle_event);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user