refactory-id / bootstrap-markdown

Bootstrap plugin for markdown editing
Apache License 2.0
1.99k stars 371 forks source link

multiple focus and blur events when using showPreview() #146

Closed eliasjames closed 9 years ago

eliasjames commented 9 years ago

Hello. Please see the following jsfiddle example: http://jsfiddle.net/v4pv27tL/15/

I have a client who has this need:

In other words, it appears like native HTML until click, when it turns into ordinary editor. Seemed like it should be straightforward from the API.

The problem I ran into is in certain cases, onBlur is firing immediately after onFocus. I didn't do any more research than the fiddle above, but is seems that showPreview may be creating multiple DOM elements and the shift from one to another triggers blur.

If there's a better implementation that doesn't expose these issues, please advise.

Please let me know if I can provide further information or help in any way. And thank you for all the effort to share this library!

Best,

E

toopay commented 9 years ago

In your use-case, the blur event are not intended, although it actually properly fired since the editor is really leaving focus state.

I think you can use some initialization flag combined with some recursion callback to toggle the editor back to html vice-versa. http://jsfiddle.net/hbLr7tt0/37/

toopay commented 9 years ago

I'll close this one, with assumption your issue were resolved (at least, in my example).