Commit cb4fc4ab authored by Robert Hodan's avatar Robert Hodan Committed by Juan Corona

Add support for automatic discovery of newly added/removed iframes

parent df5b0824
...@@ -39,6 +39,12 @@ module.exports = class CrossFrame extends Plugin ...@@ -39,6 +39,12 @@ module.exports = class CrossFrame extends Plugin
# Find, and inject Hypothesis into Guest's iframes # Find, and inject Hypothesis into Guest's iframes
# _discoverOwnFrames() # _discoverOwnFrames()
# Listen for DOM mutations, to know when iframes are added / removed
observer = new MutationObserver(_checkForIFrames)
config = {childList: true, subtree: true};
# THESIS TODO: Disabled until multi-guest support is fully implemented
# observer.observe(elem, config);
this.destroy = -> this.destroy = ->
# super doesnt work here :( # super doesnt work here :(
Plugin::destroy.apply(this, arguments) Plugin::destroy.apply(this, arguments)
...@@ -62,6 +68,23 @@ module.exports = class CrossFrame extends Plugin ...@@ -62,6 +68,23 @@ module.exports = class CrossFrame extends Plugin
iframes = frameUtil.findIFrames(elem) iframes = frameUtil.findIFrames(elem)
_handleIFrames(iframes) _handleIFrames(iframes)
_checkForIFrames = (mutations) ->
for own key, mutation of mutations
addedNodes = mutation.addedNodes
removedNodes = mutation.removedNodes
# Add iframes
for own key, node of addedNodes
if (node.tagName == 'IFRAME' && node.className != 'h-sidebar-iframe')
node.addEventListener 'load', ->
bridge.call('addedIFrame')
_handleIFrame(node)
# Remove iframes
for own key, node of removedNodes
if (node.tagName == 'IFRAME')
bridge.call('removedIFrame')
_handleIFrame = (iframe) -> _handleIFrame = (iframe) ->
if !frameUtil.isAccessible(iframe) then return if !frameUtil.isAccessible(iframe) then return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment