views:

36

answers:

2

Dear experts,

I am currently working on a WYSIWYG web editor.

The problem i ran into is a little complicated.

When I select a section of text and click on something on my tools, the command works but immediately the text becomes unselected.

Just like when we select text in any webpage, when we click on something else, the text becomes unselected and everything returns to normal.

Is there a way to suppress the mouse clicks when a text is already selected so that the text will remain selected?

Thanks in advance.

A: 

Add an event listener on the elements in question, and make the function return false - this will catch the default behaviour (which is unselecting your text). You'll need to set useCapture to true for this to work.

Greg
Thanks Greg,I've messed around with return false; event.preventDefault();, returnValue=false and non of them workedCould you be a little more specific.
Dennis D
+2  A: 

You need to add an attribute to all html elements in the toolbar:

unselectable = "on"

This works for IE, don't know for other browsres. I remember this from when i was playing with attempting to the reinvent teh wheel by doing the nth WYSIWYG HTML editor. After I decied to use TinyMCE, even if sometimes I still regret not to have fun in developing it from scratch

Marco Demajo
According to here: http://help.dottoro.com/lhwdpnva.php apparently for Safari and FF you can use a specific inline style: -moz-user-select:none; -webkit-user-select: none
Marco Demajo
Believe me, once you got deep into developing your own WYSIWYG editor, you would not be having fun.
Tim Down
+1, but the bit about the CSS solution in non-IE browsers would be better in the answer. Just to confirm, `unselectable = "on"` is indeed IE-only.
Tim Down
@Tim Down: I never tested those CSS for FF/Safari, because my WYSIWYG prototype was only for IE. So I didn't want to suggest using them since I never tried them.
Marco Demajo
Thanks experts, but the issue I am having now I realized is Double click. WHen I double click any element, the selected text once again became unselected
Dennis D