Jump to content

[Solved] OnClick & Ontouchstart simulateously without firing twice


wongadob
 Share

Recommended Posts

Hi I have a bit of HTML (infact I use this all over the place) that needs an onclick and an ontouchstart, but having both is causing double entry of the data. I need touchstart to work as a full click. The software I am writing is for the blackberry the normal functionality of touch has been disabled as I do not want any guestures, or scrolling or anything else. Just leaving in the onclick means the user has to press the screen twice. once to move the focus to the object, then the second time to 'click the object'. I need just a single press to execute the element. So in my HTML I am using doing the following

<div id = 'enterbutton' class = 'basic_button' x-blackberry-focusable="true" x-blackberry-onDown=""; onmouseover="highlight_basic(this);"	 onmouseout="unhighlight_basic(this);" ontouchstart="triggerClick(this);" onclick="postThreadMessage()">Submit</div>

The code for the ontouchstart function is as follows:-

function triggerClick(el){	 $(el).trigger('click');}

So it is simulating a click. I have tried changing the ontouchstart fucntion to call the same function call as onclick, but get the same results. Is there any command that informs the system to only trigger one event per element. or any sugggestions how to get around this. Any help much appreciated.

Edited by wongadob
Link to comment
Share on other sites

Sadly they don't that is the point. If I just had onclick. Then the ontouchstart event has 2 stages. The first stage is to set the focus on the item. The second 'touch' would trigger the actual event. But the client wants the first touch to be the only touch and trigger the event. Hence me trying to force a click.

Link to comment
Share on other sites

Also I tried onmousedown in the hope it would catch both. It caught the ontouchstart, but not on the click. BTW click on blackberry in navigation mode is pressing the scrollwheel or trackpad.

Edited by wongadob
Link to comment
Share on other sites

I could not use onfocus, because it uses focus based navigation. i,e you move around the screen in the same way tab would work so when something is in focus it is not seleted it just highlights a cursor. The select state is triggered by a click. However mixed with that you face the touch screen technology that also has to work at the same time. This tech needs the item to be 'clicked' immediately when it is tocuhed. In normal touch tech mode the first touch highlights the element then the second touch selects (clicks) it. I need to do both of these simultaneously. I have tried using onmousedown, which should work for both, but sadly it does not and in the latest BB library release notes it state that onmousedown does not work. So I am stuck trying it that way. I was hoping there might be a simple way to say only accept an event once for this element.

Link to comment
Share on other sites

for the record I have to solve this by leaving both in but then setting a flag in the function that gets executed, then putting a timed callback to clear the flag. So any calls to the same function within 2 seconds would not get called. This works for me becuase if somebody wanted to legitimately send again they would have to create a new message and then send and the chances of doing that witthin 2 seconds is extremely unlikely. For the record here is the code

if (!stopDoubleSend){    stopDoubleSend=true;    setTimeout(function(){stopDoubleSend=false},2000);

the code for the function follows the set Timeout and only gets called if stopDoubleSend is false

Link to comment
Share on other sites

What you could do is to perform checks to see if the client uses a mobile phone or a desktop computer, then you can set conditions to the HTML elements whether to use onclick or ontouchstart. I think it's the simplest approach and there is a method of checking the client's browsing platform using Javascript.

Edited by getty
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...