Page 1 of 2

is there a callback in builder to get touch position?

Posted: Mon Jul 15, 2013 5:36 pm
by Shuang Liu

is there a callback in builder to get touch position rather than adding some codes in the source?


is there a callback in builder to get touch position?

Posted: Mon Jul 15, 2013 7:49 pm
by Kateryna Grynko

Hi Shuang,

You can read about available events here: http://api.jquerymobile.com/category/...

Most often, the click/touch coordinates are inside the event object that is passed as an event handler argument.


is there a callback in builder to get touch position?

Posted: Tue Dec 31, 2013 9:57 am
by Ivan6481911

Hello!
Can you tell, how to retrieve those x,y coords? I could not find out it with docs above...
Thanks!


is there a callback in builder to get touch position?

Posted: Tue Dec 31, 2013 10:01 am
by Oleg Danchenkov

is there a callback in builder to get touch position?

Posted: Tue Dec 31, 2013 10:45 am
by Ivan6481911

Great, it works!
But... My alert appears on other screens also. It seems, I have to disable that callback, right?
And another question - how can I assign tap handler to specific element (image)? I tried like this, but did not work:

$( "#lblTourID" ).bind( "tap", function tapHandler(event){
alert('x : ' + event.pageX + ' , y : ' + event.pageY);
});

lblTourID - is Name of element, assigned in UI builder

This code works, but on next screens also:

$( document ).bind( "tap", function tapHandler(event){
alert('x : ' + event.pageX + '\ny : ' + event.pageY);
});


is there a callback in builder to get touch position?

Posted: Tue Dec 31, 2013 10:54 am
by Ivan6481911

Oh-h-h...... I ' ve just found out that I can call JS on Tap event on image (and outer elements) in UI builder. How can I get tap coordinates? There is no parameter, like in handler function.


is there a callback in builder to get touch position?

Posted: Tue Dec 31, 2013 11:05 am
by Ivan6481911

:) A-m-m.... I have found the solution for getting the location of an image click.
here is the code:

$('[dsid="Image1"]').bind('tap', function(e){
var x = e.pageX;
var y = e.pageY;

alert([x, y]);
})

Please, let me know, if this is good solution.
Thank you very much for your help and sorry for bothering...


is there a callback in builder to get touch position?

Posted: Tue Dec 31, 2013 11:18 am
by Oleg Danchenkov

There is easier way.
Add Run JavaScript action on Tap event on image component. Use this js code
precodevar e = arguments[0];
var x = e.pageX;
var y = e.pageY;
alert([x, y]);
/code/pre


is there a callback in builder to get touch position?

Posted: Tue Dec 31, 2013 1:51 pm
by Ivan6481911

:) WOW, cool !
Thank you, Oleg!


is there a callback in builder to get touch position?

Posted: Tue Dec 31, 2013 2:14 pm
by Ivan6481911

How can I get relative position in Tap event?

Code: Select all

I use this code on Load Event and it works: 

// SET TOUCH EVENT (relatively to parent, not on screen)

$('[dsid="iii"]').bind('tap', function(e){

var posX = $(this).position().left,
posY = $(this).position().top;
alert((e.pageX - posX) + ' , ' + (e.pageY - posY));

})

But on Tap Event I got Nan. I think "this" is not correct object.
When I change this to document I got exception:
Uncaught TypeError: Cannot read property 'top' of undefined

var posX = $(document).position().left,
posY = $(document).position().top;