Got questions, comments, patches, etc.?
Contact Jason Woofenden
gitweb
/
peach-html5-editor.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
a1a9a18
)
hide cursor/etc when focus leaves iframe
author
Jason Woofenden
<jason@jasonwoof.com>
Sun, 13 Mar 2016 20:09:45 +0000
(16:09 -0400)
committer
Jason Woofenden
<jason@jasonwoof.com>
Sun, 13 Mar 2016 20:09:45 +0000
(16:09 -0400)
editor.coffee
patch
|
blob
|
history
diff --git
a/editor.coffee
b/editor.coffee
index
8bc72ef
..
a2af4a5
100644
(file)
--- a/
editor.coffee
+++ b/
editor.coffee
@@
-18,6
+18,11
@@
overlay_padding = 10
timeout = (ms, cb) -> return setTimeout cb, ms
overlay_padding = 10
timeout = (ms, cb) -> return setTimeout cb, ms
+next_frame = (cb) ->
+ if (window.requestAnimationFrame?)
+ window.requestAnimationFrame cb
+ else
+ timeout 16, cb
# xml 1.0 spec, chromium and firefox accept these, plus lots of unicode chars
valid_attr_regex = new RegExp '^[a-zA-Z_:][-a-zA-Z0-9_:.]*$'
# xml 1.0 spec, chromium and firefox accept these, plus lots of unicode chars
valid_attr_regex = new RegExp '^[a-zA-Z_:][-a-zA-Z0-9_:.]*$'
@@
-593,6
+598,7
@@
class PeachHTML5Editor
@cursor = null
@cursor_el = null
@cursor_visible = false
@cursor = null
@cursor_el = null
@cursor_visible = false
+ @poll_for_blur_timeout = null
@iframe_offset = null
opt_fragment = @options.fragment ? true
@parser_opts = {}
@iframe_offset = null
opt_fragment = @options.fragment ? true
@parser_opts = {}
@@
-637,14
+643,19
@@
class PeachHTML5Editor
init: -> # called by @iframe's onload (or timeout on firefox)
@idoc = @iframe.contentDocument
@overlay.onclick = (e) =>
init: -> # called by @iframe's onload (or timeout on firefox)
@idoc = @iframe.contentDocument
@overlay.onclick = (e) =>
+ @have_focus()
return event_return e, @onclick e
@overlay.ondoubleclick = (e) =>
return event_return e, @onclick e
@overlay.ondoubleclick = (e) =>
+ @have_focus()
return event_return e, @ondoubleclick e
@outer_idoc.body.onkeyup = (e) =>
return event_return e, @ondoubleclick e
@outer_idoc.body.onkeyup = (e) =>
+ @have_focus()
return event_return e, @onkeyup e
@outer_idoc.body.onkeydown = (e) =>
return event_return e, @onkeyup e
@outer_idoc.body.onkeydown = (e) =>
+ @have_focus()
return event_return e, @onkeydown e
@outer_idoc.body.onkeypress = (e) =>
return event_return e, @onkeydown e
@outer_idoc.body.onkeypress = (e) =>
+ @have_focus()
return event_return e, @onkeypress e
if @options.stylesheet
# TODO test this
return event_return e, @onkeypress e
if @options.stylesheet
# TODO test this
@@
-938,6
+949,21
@@
class PeachHTML5Editor
if prev_in_flow_is_block or parent_flags.block
ret += "\n#{indent.substr 4}"
return ret
if prev_in_flow_is_block or parent_flags.block
ret += "\n#{indent.substr 4}"
return ret
+ onblur: ->
+ @kill_cursor()
+ have_focus: ->
+ @editor_is_focused = true
+ @poll_for_blur()
+ poll_for_blur: ->
+ return if @poll_for_blur_timeout? # already polling
+ @poll_for_blur_timeout = timeout 150, =>
+ next_frame => # pause polling when browser knows we're not active/visible/etc.
+ @poll_for_blur_timeout = null
+ if document.activeElement is @outer_iframe
+ @poll_for_blur()
+ else
+ @editor_is_focused = false
+ @onblur()
window.peach_html5_editor = (args...) ->
return new PeachHTML5Editor args...
window.peach_html5_editor = (args...) ->
return new PeachHTML5Editor args...