X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=editor.coffee;h=0a023966681c6f41007be3e38be6cb2a692b4cd1;hb=d78c8fb078ffe27653da73aaf9800cc0b8228fc1;hp=b3fb3721a022e8fe2f356ff752ba1a284c349981;hpb=c70c22bfd17cbe6097e5499e62631ea23a04f36d;p=peach-html5-editor.git diff --git a/editor.coffee b/editor.coffee index b3fb372..0a02396 100644 --- a/editor.coffee +++ b/editor.coffee @@ -622,6 +622,7 @@ class PeachHTML5Editor @cursor_visible = false @poll_for_blur_timeout = null @iframe_offset = null + @iframe_height = null opt_fragment = @options.fragment ? true @parser_opts = {} if opt_fragment @@ -684,8 +685,11 @@ class PeachHTML5Editor # so add a tag @idoc.head.appendChild domify @idoc, base: href: this_url_sans_path() if @options.css_file - # TODO test this - @idoc.head.appendChild domify @idoc, link: rel: 'stylesheet', type: 'text/css', href: @options.css_file + istyle = domify @idoc, link: rel: 'stylesheet', type: 'text/css', href: @options.css_file + '?foo=baz' + istyle.onload = => + @adjust_iframe_height() + @idoc.head.appendChild istyle + @idoc.head.appendChild domify @idoc, style: children: [domify @idoc, text: "body { overflow: hidden; }"] @load_html @in_el.value @inited = true if @options.on_init? @@ -812,8 +816,15 @@ class PeachHTML5Editor @in_el.value = @pretty_html @tree @in_el.onchange = => @load_html @in_el.value - @iframe.style.height = "0" - @iframe.style.height = "#{@idoc.body.scrollHeight}px" + @adjust_iframe_height() + adjust_iframe_height: -> + h = parseInt(@idoc.body.scrollHeight, 10) + if @iframe_height isnt h + @iframe_height = h + s = @wrap2.scrollTop + @iframe.style.height = "0" + @iframe.style.height = "#{h}px" + @wrap2.scrollTop = s kill_cursor: -> # remove it, forget where it was if @cursor_visible @cursor_el.parentNode.removeChild @cursor_el