From 6d5592f890cfc7b6427fc428b701b89fae24d8d5 Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Sun, 7 Dec 2014 23:33:21 -0800 Subject: [PATCH] wb js: add guard around wb js to prevent double-inits (such as from fragments!) --- pywb/static/wb.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pywb/static/wb.js b/pywb/static/wb.js index 00592bbf..f6b2fb41 100644 --- a/pywb/static/wb.js +++ b/pywb/static/wb.js @@ -35,10 +35,14 @@ function init_banner() { bid = PLAIN_BANNER_ID; } + if (!document || !document.body) { + return; + } + if (document.getElementById(bid) != null) { return; } - + _wb_js.create_banner_element(bid); } @@ -56,14 +60,14 @@ this.ts_to_date = function(ts, is_gmt) if (ts.length < 14) { return ts; } - - var datestr = (ts.substring(0, 4) + "-" + + + 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); if (is_gmt) { return date.toGMTString(); @@ -117,6 +121,12 @@ function notify_top() { } this.load = function() { + if (window._wb_js_inited) { + return; + } + + window._wb_js_inited = true; + if ((window.self == window.top) && wbinfo) { if (wbinfo.top_url && (window.location.href != wbinfo.top_url) && wbinfo.mod != "bn_") { // Auto-redirect to top frame