0

I have a div with contentEditable=true. It supports markdown formatting for **word** and _word_.

On the blur event on the div, markdown is converted to html.
On the focus event on the div, html is converted to markdown.

This is ok. But when the browser finds an unknown word (red underline) and I want to fix it with a right click to see the suggested words, the div takes the focus and the word is not underlined.

Have you an idea please? (sorry for my English language)

jwnace
  • 360
  • 3
  • 11
  • @jwnace Did my answer solve your problem – elzi Nov 06 '14 at 21:13
  • @elzi, It's not my question, I just edited it. Sven, did elzi's answer solve your problem? – jwnace Nov 06 '14 at 21:16
  • @elzi : Thanks, but my problem is not solve with your answer. I would like the browser context menu appears before the change of state in focus, for choose a word suggested by the browser's dictionary in the context menu. –  Nov 06 '14 at 22:59
  • http://stackoverflow.com/questions/7621711/how-to-prevent-blur-running-when-clicking-a-link-in-jquery ? – mb21 Nov 07 '14 at 09:39

1 Answers1

0

Use oncontextmenu - since the right click could also be achieved by CTRL/CMD+click, etc.

$('#content').on('contextmenu', function (event) {
  event.preventDefault();

  console.log('context menu opened');
})

EDIT Adjusting based on your comment feedback:

$('#content').on('mousedown', function (event) {

    if ( event.which == 3 ) {
      console.log('Right mouse button pressed');
    }
})
elzi
  • 5,442
  • 7
  • 37
  • 61
  • I do not have a context menu with this solution. –  Nov 06 '14 at 23:13
  • The second solution? I get a context menu fine: http://jsbin.com/kewucujafa/1/edit?js,console,output – elzi Nov 06 '14 at 23:14
  • ok, sorry. But left click is now inactive and my div can not take the focus. –  Nov 06 '14 at 23:22
  • Just remove `event.preventDefault()`. New JSBIN: http://jsbin.com/gimatidati/2/edit – elzi Nov 06 '14 at 23:24
  • Works great for me. What's the problem? – elzi Nov 06 '14 at 23:39
  • By steps : 1-add space at the end of sentence / 2-"worrd" is underlined / 3-click other place for blur / 4-right-click on "worrd" for show suggested words. On step 4, the contextual menu appears, but no suggestions because sentence is different, with html to markdown –  Nov 06 '14 at 23:45
  • Now we're getting into a second phase of the problem. I was only intending to show you how to get into the right click event. Give me some time. – elzi Nov 06 '14 at 23:50