X-Git-Url: https://jasonwoof.com/gitweb/?p=peach-html5-editor.git;a=blobdiff_plain;f=editor.coffee;h=8290b37cd640dd63067a6cadf25269f4ed8756b7;hp=9b4ad4f5eae8490343cdbe21ad4b9fb6620aff31;hb=ed31e427bb738c1673b1fbf9465aa4f5324f9a3c;hpb=7e3ab4e397ff9d274d2aaa1ef467727f2107bccd diff --git a/editor.coffee b/editor.coffee index 9b4ad4f..8290b37 100644 --- a/editor.coffee +++ b/editor.coffee @@ -51,7 +51,7 @@ debug_dot_at = (doc, x, y) -> # text nodes don't have getBoundingClientRect(), so use selection api to find # it. -get_el_bounds = (el) -> +get_el_bounds = window.bounds = (el) -> if el.getBoundingClientRect? rect = el.getBoundingClientRect() else @@ -623,7 +623,7 @@ class PeachHTML5Editor @cursor_el = null @cursor_visible = false @poll_for_blur_timeout = null - @iframe_offset = null + @wrap2_offset = null @iframe_height = null opt_fragment = @options.fragment ? true @parser_opts = {} @@ -703,12 +703,11 @@ class PeachHTML5Editor if @options.on_init? @options.on_init() overlay_event_to_inner_xy: (e) -> - unless @iframe_offset? - @iframe_offset = get_el_bounds @iframe - x = e.pageX # TODO ?cross-browserify - y = e.pageY + @wrap2.scrollTop # TODO ?cross-browserify - # TODO adjust for scrolling - return x: x - @iframe_offset.x, y: y - @iframe_offset.y + unless @wrap2_offset? + @wrap2_offset = get_el_bounds @wrap2 + x = e.pageX - overlay_padding + y = e.pageY - overlay_padding + @wrap2.scrollTop + return x: x - @wrap2_offset.x, y: y - @wrap2_offset.y onclick: (e) -> xy = @overlay_event_to_inner_xy e new_cursor = find_loc_cursor_position @tree, xy