Page 1 of 1

Trapping Touch Events in Browser Object

Posted: Sat Jan 05, 2013 7:48 am
by jstarkman
I've been successful in loading a local PDF file for display using the ios native Browser object, but I can't seem to trap touch events on the browser object. I'm using the simulator. Touching (touch/drag/pinch) on the simulator all work well, but I can't do something as simple as trap a touchStart or touchEnd event. Any ideas how to go about this?

Thanks.

Joel

Re: Trapping Touch Events in Browser Object

Posted: Sat Jan 05, 2013 1:14 pm
by endernafi
Hi Joel,

Simply put, you have to trap the browserLoadRequest command.
Something like this:

Code: Select all

on browserLoadRequest pUrl, pType
   # do your thing with pUrl
end browserLoadRequest
Don't forget to add this line, though:

Code: Select all

mobileControlSet tControl, "delayRequests", true

I don't know this works for you because you didn't clarify what you want to do by trapping touch events.
You may open a link which is embedded in the pdf in an in-app-browser with this method.
Or as a scenario which I use often,
you may have a full-screen html photo gallery page.
And to close the page and return back to the previous card,
you can place a close button inside the html of the photo gallery:

Code: Select all

<a style="position: fixed; top:5px;left:5px;" href="closeThePage"><img style="border: none; width:64px; height:32px;" src="images/close.png"/></a>
Then your trapped command would be like this:

Code: Select all

on browserLoadRequest pUrl, pType
   if pUrl contains "closeThePage" then
      visual effect push right fast
      go to card sPreviousCard
   end if
end browserLoadRequest

Best,

~ Ender Nafi

Re: Trapping Touch Events in Browser Object

Posted: Sun Jan 06, 2013 3:55 am
by jstarkman
Ender,

Thanks for your response, although I'm still not sure if what you're suggesting works for my application.

I am working with PDF files that I display in the iOS Browser object. These are 'other peoples' files, so I am not creating them, but using my app to view them. There are many functions I wish to implement, but for starters I want to be able to simply trap a touch event in the Browser to that I can, for instance, toggle the display of menus using a 'tap' type of event. Even though LiveCode may not distinguish a tap from a touch, I can deal with that programmatically.

The other thing I want to be able to do is determine where, on a pdf, the use is touching, relative to the document origin.

Joel

Re: Trapping Touch Events in Browser Object

Posted: Sun Jan 06, 2013 4:38 am
by endernafi
Hi Joel,

There isn't an easy way to get what you want.
Native browser object sends only these messages to the engine:
browserStartedLoading url
browserFinishedLoading url
browserLoadRequest url, type
browserLoadFailed url, error
browserLoadRequested url, type

according to the iOS Release Notes.

I'm not sure whether a workaround might be found.
It would be good, though.
'cause, I need this, too:
...toggle the display of menus using a 'tap' type of event...
If you happen to find a solution/workaround, please share 8)


Best,

~ Ender Nafi

Re: Trapping Touch Events in Browser Object

Posted: Sun Jan 06, 2013 12:13 pm
by Simon
Hi,
Are you two looking for the mouse loc within the browser rect?

Simon

Re: Trapping Touch Events in Browser Object

Posted: Sun Jan 06, 2013 12:26 pm
by endernafi
Simon,

mouseLoc() is a function, right?
So in order to evaluate that function and build a code upon it,
first we have to place it inside a message, since in LiveCode it's all about messages.
Where do you suggest to place that function?
The native browser object, I mean the iOS Browser Object not revBrowser or anything, doesn't send any messages related to touch events.
That means, no matter how much or how hard you click within the rect of the browser, it doesn't fire any message which the coder can use.
It does only a couple of things:
* Zooming
* Scrolling
* Go to an url if the clicked portion of the screen consists a link

That's it and that's the problem...


Best,

~ Ender Nafi

Re: Trapping Touch Events in Browser Object

Posted: Mon Jan 07, 2013 3:09 am
by Simon
Where do you suggest to place that function?
In the script of a substack who's:
blendlevel is 99
loc , hight, width = browser rect
windowshape = a grid with alpha
mode set to palette
Window Decorations = none

Don't know what will happen touchMove events.

Simon EDIT: Forget it windowshape is not supported in mobile. Oh Well, got close.

Re: Trapping Touch Events in Browser Object

Posted: Sun Feb 03, 2013 12:11 am
by seaniepie
Hi,

You need to do all the trapping within HTML. From there you can send a URL request of some kind that can then be registered by LC. So you have a PDF reader in HTML that then has another layer above it that can collect info about the touch and either pass it on to the PDF reader and/or send a message onto LC coded with the mouse position, it's movement, and any other action you might want your LC script to be aware of etc. :)

If you need help with HTML5 then heres a good place to start: http://www.html5rocks.com/en/

All the best
Pi