Fix issue with iframe targetWindow not being immediately available.

This commit is contained in:
ccd0 2015-06-21 14:40:26 -07:00
parent b937825747
commit f69cee50e4
3 changed files with 7 additions and 4 deletions

View File

@ -2,11 +2,14 @@ class Connection
constructor: (@target, @origin, @cb={}) ->
$.on window, 'message', @onMessage
targetWindow: ->
@target.contentWindow or @target
send: (data) =>
@target.postMessage "#{g.NAMESPACE}#{JSON.stringify data}", @origin
@targetWindow().postMessage "#{g.NAMESPACE}#{JSON.stringify data}", @origin
onMessage: (e) =>
return unless e.source is @target and
return unless e.source is @targetWindow() and
e.origin is @origin and
typeof e.data is 'string' and
e.data[...g.NAMESPACE.length] is g.NAMESPACE

View File

@ -98,7 +98,7 @@ Captcha.noscript =
id: 'qr-captcha-iframe'
src: @iframeURL()
$.add QR.nodes.el, @nodes.iframe
@conn.target = @nodes.iframe.contentWindow
@conn.target = @nodes.iframe
else if !@occupied or force
@nodes.iframe.src = @iframeURL()
@occupied = true

View File

@ -96,7 +96,7 @@ Captcha.v2 =
id: 'qr-captcha-iframe'
src: @noscriptURL()
$.add @nodes.container, iframe
@conn.target = iframe.contentWindow
@conn.target = iframe
setupJS: ->
$.globalEval '''