From 80e80e97d31e82ea2d950704901b46d3dcf5864d Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Sat, 14 Jun 2014 18:26:19 -0700 Subject: [PATCH] replay: support 'framed_replay' option in config for both replay and live rewrite split replay view into BaseContentView and ReplayView refactor RewriteLiveHandler into RewriteLiveView add additional tests for framed and non-framed mode default to framed replay! --- config.yaml | 2 + pywb/static/wb.js | 55 +++++++++----- pywb/ui/frame_insert.html | 53 ++++++++++---- pywb/ui/head_insert.html | 1 + pywb/webapp/live_rewrite_handler.py | 63 ++-------------- pywb/webapp/pywb_init.py | 36 ++-------- pywb/webapp/replay_views.py | 108 ++++++++++++++++++++++++---- tests/test_config.yaml | 18 ++++- tests/test_integration.py | 53 ++++++++------ 9 files changed, 237 insertions(+), 152 deletions(-) diff --git a/config.yaml b/config.yaml index b1daa517..312f05cb 100644 --- a/config.yaml +++ b/config.yaml @@ -104,3 +104,5 @@ enable_memento: true # Use lxml parser, if available use_lxml_parser: false +# Replay content in an iframe +framed_replay: true diff --git a/pywb/static/wb.js b/pywb/static/wb.js index 1a5ef8db..84588324 100644 --- a/pywb/static/wb.js +++ b/pywb/static/wb.js @@ -17,9 +17,12 @@ This file is part of pywb. along with pywb. If not, see . */ +_wb_js = (function() { + function init_banner() { var PLAIN_BANNER_ID = "_wb_plain_banner"; var FRAME_BANNER_ID = "_wb_frame_top_banner"; + var bid; if (wbinfo.is_embed) { return; @@ -44,7 +47,7 @@ function init_banner() { text = "This is an archived page "; if (wbinfo && wbinfo.capture_str) { - text += " from " + wbinfo.capture_str + ""; + text += " from " + wbinfo.capture_str + ""; } banner.innerHTML = text; @@ -76,31 +79,51 @@ function remove_event(name, func, object) { } } -var notified_top = false; - -var detect_on_init = function() { - if (!notified_top && window && window.top && (window.self != window.top) && window.WB_wombat_location) { - if (!wbinfo.is_embed) { - window.top.postMessage(window.WB_wombat_location.href, "*"); - } - notified_top = true; +function notify_top(event) { + if (window.self == window.top) { + return; + } + + if (window.top.top != window.top) { + return; + } + + if (!window.WB_wombat_location) { + return; + } + + if (wbinfo.is_embed) { + return; + } + + if (event.target != window.document) { + return; } - if (document.readyState === "interactive" || - document.readyState === "complete") { - - init_banner(); - - remove_event("readystatechange", detect_on_init, document); + if (typeof(window.WB_wombat_location.href) != "string") { + return; } + + if (window.top.update_wb_url) { + window.top.update_wb_url(window.WB_wombat_location.href, wbinfo.timestamp, wbinfo.capture_str); + } +} + +var detect_on_init = function(event) { + init_banner(); + notify_top(event); + remove_event("readystatechange", detect_on_init, document); } add_event("readystatechange", detect_on_init, document); + if (wbinfo.is_frame_mp && wbinfo.canon_url && - (window.self == window.top) && + (window.self == window.top) && (window.self.top == window.top) && window.location.href != wbinfo.canon_url) { window.location.replace(wbinfo.canon_url); } + +})(); diff --git a/pywb/ui/frame_insert.html b/pywb/ui/frame_insert.html index 3ba9a406..f8821547 100644 --- a/pywb/ui/frame_insert.html +++ b/pywb/ui/frame_insert.html @@ -3,7 +3,8 @@