From f69cee50e41a358fab60c63604a9712840d3aad8 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sun, 21 Jun 2015 14:40:26 -0700 Subject: [PATCH] Fix issue with iframe targetWindow not being immediately available. --- src/General/lib/connection.class | 7 +++++-- src/Posting/Captcha.noscript.coffee | 2 +- src/Posting/Captcha.v2.coffee | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/General/lib/connection.class b/src/General/lib/connection.class index 00d90ae3f..ee23674ec 100644 --- a/src/General/lib/connection.class +++ b/src/General/lib/connection.class @@ -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 diff --git a/src/Posting/Captcha.noscript.coffee b/src/Posting/Captcha.noscript.coffee index f9b03d8ae..cbcb614b2 100644 --- a/src/Posting/Captcha.noscript.coffee +++ b/src/Posting/Captcha.noscript.coffee @@ -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 diff --git a/src/Posting/Captcha.v2.coffee b/src/Posting/Captcha.v2.coffee index d4bb8c533..c3a67e675 100644 --- a/src/Posting/Captcha.v2.coffee +++ b/src/Posting/Captcha.v2.coffee @@ -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 '''