Commit 758fc27f authored by Juan Corona's avatar Juan Corona

Add helper to FrameUtil that calls back when an iframe is ready

parent 7d142bd0
......@@ -90,10 +90,7 @@ module.exports = class CrossFrame extends Plugin
_handleFrame = (frame) ->
if !FrameUtil.isAccessible(frame) then return
if frame.contentDocument.readyState != 'complete'
frame.addEventListener 'load', ->
_injectToFrame(frame)
else
FrameUtil.isLoaded frame, () ->
_injectToFrame(frame)
_iframeUnloaded = (frame) ->
......
......@@ -43,10 +43,21 @@ function isValid (iframe) {
return iframe.className !== 'h-sidebar-iframe';
}
function isLoaded (iframe, callback) {
if (iframe.contentDocument.readyState !== 'complete') {
iframe.addEventListener('load', function () {
callback();
});
} else {
callback();
}
}
module.exports = {
findFrames: findFrames,
hasHypothesis: hasHypothesis,
injectHypothesis: injectHypothesis,
isAccessible: isAccessible,
isValid: isValid,
isLoaded: isLoaded,
};
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