Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #14004
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
|---|---|
| From | Jason C <jwcarlton@gmail.com> |
| Newsgroups | comp.lang.javascript |
| Subject | CSS menu, onClick takes focus from highlighted text |
| Date | Tue, 15 May 2012 22:09:35 -0700 (PDT) |
| Organization | http://groups.google.com |
| Lines | 46 |
| Message-ID | <16672113.987.1337144975975.JavaMail.geo-discussion-forums@ynmk20> (permalink) |
| NNTP-Posting-Host | 71.53.106.183 |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | posting.google.com 1337144976 1551 127.0.0.1 (16 May 2012 05:09:36 GMT) |
| X-Complaints-To | groups-abuse@google.com |
| NNTP-Posting-Date | Wed, 16 May 2012 05:09:36 +0000 (UTC) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=71.53.106.183; posting-account=494U9QkAAACJUH6jIcyb5E30maZZLsu7 |
| User-Agent | G2/1.0 |
| X-Received-Bytes | 2574 |
| Xref | csiph.com comp.lang.javascript:14004 |
Show key headers only | View raw
I'm changing a regular <select> menu to a CSS menu, like so:
// toggle() changes the display value for menu
function toggle(e, id) {
var el = document.getElementById(id);
el.style.display = (el.style.display == 'none') ? 'block' : 'none';
toggle.el = el;
if (e.stopPropagation) e.stopPropagation();
e.cancelBubble = true;
return false;
}
// CSS Menu
<div onClick="toggle(event, 'menu')">
Choose
</div>
<div id="menu" style="display: none; position: absolute">
<div onMouseDown="doSomething('a')">
Option 1
</div>
<div onMouseDown="doSomething('b')">
Option 2
</div>
</div>
When the user selects an option, doSomething(x) works with highlighted text inside of a separate contenteditable field.
The problem I'm having is that when they click on "Choose", the contenteditable field loses focus, so I lose the highlighted text.
If I change the "toggle" command from onClick() to onMouseOver(), everything works as expected, so I'm 99% sure that the problem is that the onClick is making me lose focus. If I change it to onMouseDown, though, then I think toggle() is called on both MouseDown and MouseUp; when I click down, the menu toggles on, but then when I let off, it toggles back off. I don't think this would solve the problem of losing the highlighted text anyway, though; I'm pretty sure that I would still lose it as soon as I let off of the click.
Can you guys suggest a way that I can click to toggle this menu, without losing the highlighted text in the contenteditable field?
Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread
CSS menu, onClick takes focus from highlighted text Jason C <jwcarlton@gmail.com> - 2012-05-15 22:09 -0700 Re: CSS menu, onClick takes focus from highlighted text Jason C <jwcarlton@gmail.com> - 2012-05-16 00:24 -0700
csiph-web