diff --git a/pywb/apps/rewriterapp.py b/pywb/apps/rewriterapp.py
index 13fb9875..25c6e2f7 100644
--- a/pywb/apps/rewriterapp.py
+++ b/pywb/apps/rewriterapp.py
@@ -71,13 +71,15 @@ class RewriterApp(object):
self.jinja_env = jinja_env
+ self.banner_view = BaseInsertView(self.jinja_env, self._html_templ('banner_html'))
+
self.head_insert_view = HeadInsertView(self.jinja_env,
self._html_templ('head_insert_html'),
- self._html_templ('banner_html'))
+ self.banner_view)
self.frame_insert_view = TopFrameView(self.jinja_env,
self._html_templ('frame_insert_html'),
- self._html_templ('banner_html'))
+ self.banner_view)
self.error_view = BaseInsertView(self.jinja_env, self._html_templ('error_html'))
self.not_found_view = BaseInsertView(self.jinja_env, self._html_templ('not_found_html'))
diff --git a/pywb/apps/test/test_rewriter.py b/pywb/apps/test/test_rewriter.py
index 834dc161..e77a7842 100644
--- a/pywb/apps/test/test_rewriter.py
+++ b/pywb/apps/test/test_rewriter.py
@@ -28,15 +28,13 @@ class TestRewriterApp(FakeRedisTests, BaseTestClass):
assert '"http://localhost:80/live/mp_/http://www.iana.org/domains/example"' in resp.text
- assert 'wbinfo.url = "http://example.com/"'
+ assert '"http://example.com/"'
def test_top_frame(self):
resp = self.testapp.get('/live/http://example.com/')
resp.charset = 'utf-8'
- assert '"http://localhost:80/live/mp_/http://example.com/"' in resp.text
-
- assert 'wbinfo.capture_url = "http://example.com/"' in resp.text
+ assert '"http://example.com/"' in resp.text
#def test_cookie_track_1(self):
# resp = self.testapp.get('/live/mp_/https://twitter.com/')
diff --git a/pywb/rewrite/templateview.py b/pywb/rewrite/templateview.py
index 4a7973b8..2d94fe89 100644
--- a/pywb/rewrite/templateview.py
+++ b/pywb/rewrite/templateview.py
@@ -109,10 +109,10 @@ class JinjaEnv(object):
# ============================================================================
class BaseInsertView(object):
- def __init__(self, jenv, insert_file, banner_file=''):
+ def __init__(self, jenv, insert_file, banner_view=None):
self.jenv = jenv
self.insert_file = insert_file
- self.banner_file = banner_file
+ self.banner_view = banner_view
def render_to_string(self, env, **kwargs):
template = None
@@ -134,6 +134,7 @@ class BaseInsertView(object):
params = env.get('webrec.template_params')
if params:
kwargs.update(params)
+ kwargs['env'] = env
return template.render(**kwargs)
@@ -149,27 +150,25 @@ class HeadInsertView(BaseInsertView):
coll='',
include_ts=True):
- url = wb_url.get_url()
-
- include_wombat = not wb_url.is_banner_only
-
- wbrequest = {'host_prefix': host_prefix,
- 'wb_prefix': wb_prefix,
- 'wb_url': wb_url,
- 'coll': coll,
- 'env': env,
- 'options': {'is_framed': is_framed},
- 'rewrite_opts': {}
- }
+ params = {'host_prefix': host_prefix,
+ 'wb_prefix': wb_prefix,
+ 'wb_url': wb_url,
+ 'coll': coll,
+ 'is_framed': 'true' if is_framed else 'false',
+ 'top_url': top_url,
+ }
def make_head_insert(rule, cdx):
- return (self.render_to_string(env, wbrequest=wbrequest,
- cdx=cdx,
- top_url=top_url,
- include_ts=include_ts,
- include_wombat=include_wombat,
- banner_html=self.banner_file,
- rule=rule))
+ params['wombat_ts'] = cdx['timestamp'] if include_ts else ''
+ params['wombat_sec'] = timestamp_to_sec(cdx['timestamp'])
+ params['is_live'] = 'true' if cdx.get('is_live') else 'false'
+
+ if self.banner_view:
+ banner_html = self.banner_view.render_to_string(env, cdx=cdx, **params)
+ params['banner_html'] = banner_html
+
+ return self.render_to_string(env, cdx=cdx, **params)
+
return make_head_insert
@@ -198,25 +197,27 @@ class TopFrameView(BaseInsertView):
else:
iframe_url = wb_prefix + embed_url
- wbrequest = {'host_prefix': host_prefix,
- 'wb_prefix': wb_prefix,
- 'wb_url': wb_url,
- 'coll': coll,
+ params = {'host_prefix': host_prefix,
+ 'wb_prefix': wb_prefix,
+ 'wb_url': wb_url,
+ 'coll': coll,
- 'options': {'frame_mod': frame_mod,
- 'replay_mod': replay_mod},
- }
+ 'options': {'frame_mod': frame_mod,
+ 'replay_mod': replay_mod},
- params = dict(embed_url=embed_url,
- iframe_url=iframe_url,
- wbrequest=wbrequest,
- timestamp=timestamp,
- url=wb_url.get_url(),
- banner_html=self.banner_file)
+ 'embed_url': embed_url,
+ 'iframe_url': iframe_url,
+ 'timestamp': timestamp,
+ 'url': wb_url.get_url()
+ }
if extra_params:
params.update(extra_params)
+ if self.banner_view:
+ banner_html = self.banner_view.render_to_string(env, **params)
+ params['banner_html'] = banner_html
+
return self.render_to_string(env, **params)
diff --git a/pywb/static/wb.css b/pywb/static/default_banner.css
similarity index 98%
rename from pywb/static/wb.css
rename to pywb/static/default_banner.css
index b285cfa6..0806cd91 100644
--- a/pywb/static/wb.css
+++ b/pywb/static/default_banner.css
@@ -28,7 +28,7 @@
height: 40px !important;
}
-.wb_iframe_div
+#wb_iframe_div
{
position: absolute;
width: 100%;
diff --git a/pywb/static/default_banner.js b/pywb/static/default_banner.js
index 3f24942f..5b7d189e 100644
--- a/pywb/static/default_banner.js
+++ b/pywb/static/default_banner.js
@@ -19,43 +19,85 @@ This file is part of pywb, https://github.com/ikreymer/pywb
*/
// Creates the default pywb banner.
-// Override this function/script to create a different type of banner
+(function() {
+ function ts_to_date(ts, is_gmt) {
+ if (!ts) {
+ return "";
+ }
-_wb_js.create_banner_element = function(banner_id)
-{
+ if (ts.length < 14) {
+ ts += "00000000000000".substr(ts.length);
+ }
- var banner = document.createElement("wb_div", true);
- banner.setAttribute("id", banner_id);
- banner.setAttribute("lang", "en");
+ 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 text;
+ var date = new Date(datestr);
- if (wbinfo.is_frame) {
- text = _wb_js.banner_labels.LOADING_MSG;
- } else if (wbinfo.is_live) {
- text = _wb_js.banner_labels.LIVE_MSG;
- } else {
- text = _wb_js.banner_labels.REPLAY_MSG;
- }
-
- text = "" + text + "";
-
- var capture_str = "";
- if (wbinfo && wbinfo.timestamp) {
- capture_str = _wb_js.ts_to_date(wbinfo.timestamp, true);
+ if (is_gmt) {
+ return date.toGMTString();
+ } else {
+ return date.toLocaleString();
+ }
}
- text += "" + capture_str + "";
+ function init(bid) {
+ var banner = document.createElement("wb_div", true);
- if (wbinfo.proxy_magic && wbinfo.url) {
- var select_url = wbinfo.proxy_magic + "/" + wbinfo.url;
- var query_url = wbinfo.proxy_magic + "/*/" + wbinfo.url;
- text += ' All Capture Times';
- text += '
'
- text += 'From collection "' + wbinfo.coll + '" All Collections';
+ banner.setAttribute("id", bid);
+ banner.setAttribute("lang", "en");
+
+ var text = "Loading...";
+
+ banner.innerHTML = text;
+ document.body.insertBefore(banner, document.body.firstChild);
}
-
- banner.innerHTML = text;
- document.body.insertBefore(banner, document.body.firstChild);
-}
+
+ function set_banner(url, ts, is_live) {
+ var capture_str;
+
+ if (!ts) {
+ return;
+ }
+
+ if (is_live) {
+ capture_str = "This is a live page from ";
+ } else {
+ capture_str = "This is an archived page from ";
+ }
+
+ capture_str += ts_to_date(ts, true);
+ document.querySelector("#_wb_capture_info").innerHTML = capture_str;
+ }
+
+ if (window.top != window) {
+ return;
+ }
+
+ window.addEventListener("load", function() {
+ if (window.wbinfo) {
+ init("_wb_plain_banner");
+
+ set_banner(window.wbinfo.url,
+ window.wbinfo.timestamp,
+ window.wbinfo.is_live);
+ } else {
+ init("_wb_frame_top_banner");
+
+ window.addEventListener("message", function(event) {
+ var state = event.data;
+ if (state.wb_type) {
+ set_banner(state.url, state.ts, state.is_live);
+ }
+ });
+ }
+ });
+
+})();
+
+
diff --git a/pywb/static/vidrw.js b/pywb/static/vidrw.js
index a17d0e32..0366bd1d 100644
--- a/pywb/static/vidrw.js
+++ b/pywb/static/vidrw.js
@@ -34,7 +34,7 @@ if (window.location.hash) {
if (_pywbvid == "html" || _pywbvid == "flash") {
var YT_W_E_RX = /^(https?:\/\/.*youtube.com)\/(watch|embed).*$/;
- if (wbinfo.url.match(YT_W_E_RX)) {
+ if (window.wbinfo && window.wbinfo.url.match(YT_W_E_RX)) {
// special case: prevent yt player from being inited
Object.defineProperty(window, 'yt', {writeable: false});
Object.defineProperty(window, 'ytplayer', {writeable: false});
@@ -45,6 +45,10 @@ if (window.location.hash) {
__wbvidrw = (function() {
+ if (!window.wbinfo) {
+ return;
+ }
+
var checked_embeds = false;
var FLASH_PLAYER = wbinfo.static_prefix + "/flowplayer/flowplayer-3.2.18.swf";
diff --git a/pywb/static/wb.js b/pywb/static/wb.js
deleted file mode 100644
index ecaeee91..00000000
--- a/pywb/static/wb.js
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
-Copyright(c) 2013-2014 Ilya Kreymer. Released under the GNU General Public License.
-
-This file is part of pywb, https://github.com/ikreymer/pywb
-
- pywb is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- pywb is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with pywb. If not, see