Fix issue with iframe targetWindow not being immediately available.
This commit is contained in:
parent
b937825747
commit
f69cee50e4
@ -2,11 +2,14 @@ class Connection
|
|||||||
constructor: (@target, @origin, @cb={}) ->
|
constructor: (@target, @origin, @cb={}) ->
|
||||||
$.on window, 'message', @onMessage
|
$.on window, 'message', @onMessage
|
||||||
|
|
||||||
|
targetWindow: ->
|
||||||
|
@target.contentWindow or @target
|
||||||
|
|
||||||
send: (data) =>
|
send: (data) =>
|
||||||
@target.postMessage "#{g.NAMESPACE}#{JSON.stringify data}", @origin
|
@targetWindow().postMessage "#{g.NAMESPACE}#{JSON.stringify data}", @origin
|
||||||
|
|
||||||
onMessage: (e) =>
|
onMessage: (e) =>
|
||||||
return unless e.source is @target and
|
return unless e.source is @targetWindow() and
|
||||||
e.origin is @origin and
|
e.origin is @origin and
|
||||||
typeof e.data is 'string' and
|
typeof e.data is 'string' and
|
||||||
e.data[...g.NAMESPACE.length] is g.NAMESPACE
|
e.data[...g.NAMESPACE.length] is g.NAMESPACE
|
||||||
|
|||||||
@ -98,7 +98,7 @@ Captcha.noscript =
|
|||||||
id: 'qr-captcha-iframe'
|
id: 'qr-captcha-iframe'
|
||||||
src: @iframeURL()
|
src: @iframeURL()
|
||||||
$.add QR.nodes.el, @nodes.iframe
|
$.add QR.nodes.el, @nodes.iframe
|
||||||
@conn.target = @nodes.iframe.contentWindow
|
@conn.target = @nodes.iframe
|
||||||
else if !@occupied or force
|
else if !@occupied or force
|
||||||
@nodes.iframe.src = @iframeURL()
|
@nodes.iframe.src = @iframeURL()
|
||||||
@occupied = true
|
@occupied = true
|
||||||
|
|||||||
@ -96,7 +96,7 @@ Captcha.v2 =
|
|||||||
id: 'qr-captcha-iframe'
|
id: 'qr-captcha-iframe'
|
||||||
src: @noscriptURL()
|
src: @noscriptURL()
|
||||||
$.add @nodes.container, iframe
|
$.add @nodes.container, iframe
|
||||||
@conn.target = iframe.contentWindow
|
@conn.target = iframe
|
||||||
|
|
||||||
setupJS: ->
|
setupJS: ->
|
||||||
$.globalEval '''
|
$.globalEval '''
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user