JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
work around bug in firefox (nested iframe onload)
authorJason Woofenden <jason@jasonwoof.com>
Tue, 8 Mar 2016 16:18:05 +0000 (11:18 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Tue, 8 Mar 2016 16:18:05 +0000 (11:18 -0500)
editor.coffee

index 440bb3e..370f2a1 100644 (file)
@@ -564,6 +564,7 @@ class PeachHTML5Editor
                if @options.editor_id?
                        @outer_iframe.setAttribute 'id', @options.editor_id
                @outer_iframe.onload = =>
+                       console.log 'outer onload'
                        @outer_idoc = @outer_iframe.contentDocument
                        icss = domify @outer_idoc, style: children: [
                                domify @outer_idoc, text: css
@@ -572,6 +573,7 @@ class PeachHTML5Editor
                        @iframe = domify @outer_idoc, iframe: {}
                        @iframe.onload = =>
                                @init()
+                       setTimeout (=> @init()), 200 # firefox never fires this onload
                        @outer_idoc.body.appendChild(
                                domify @outer_idoc, div: id: 'wrap1', children: [
                                        domify @outer_idoc, div: id: 'wrap2', children: [
@@ -593,7 +595,8 @@ class PeachHTML5Editor
                @outer_iframe.setAttribute 'style', outer_iframe_style
                css = outer_css w: outer_bounds.w, h: outer_bounds.h
                outer_wrap.appendChild @outer_iframe
-       init: -> # called by @iframe's onload
+       init: -> # called by @iframe's onload (or timeout on firefox)
+               return if @initialized # ignore timeout for non-broken browsers
                @idoc = @iframe.contentDocument
                @overlay.onclick = (e) =>
                        return @onclick e