UIWebview detect form text change - ios

I'm wondering if there is any good way to essentially apply - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string to forms in a webview.
The result would be reacting to every typed/deleted letter in a web form.
Right now I'm using a timer that fires every .1 seconds to check the but it's not a very good solution and causes some bad behavior that appears to lock up the ability to call any other Javascript evalutations..

One way to go about this would be to "inject" some javascript code into the page, that would attempt navigation whenever the event you are interested in happens.
You'd catch and cancel that Navigation on the UIWebView, and use the navigation event as your event handler (possibly passing data in the url itself).
The series of events will be like this:
Event (e.g. change of value in a field) fires in JS.
Injected code Navigates to a certain (bogus) url.
Your app's Obj-C code will (listen to and) receive a navigation event. your code will check the url and find it is the one expected by the event. You can pass additional event data on the url itself.
The app code will cancel the navigation, so nothing actually changes on the page
Your app will react in whatever way you want to that event.
You didn't mention if you had control over the content of the web pages, so I'm not going into details on how to inject that javascript code. Let me know if that's something you want described.
I have been successful in augmenting/changing many DOM events, without actually owning the web pages that my UIWebView is navigating to, essentially giving the user a different experience when browsing these pages through my app than through a regular mobile browser.
hope that helps.
P.S. there might be an easier way using PhoneGap. I would be interested to know if that can shorten things.

Related

Can you intercept hyperlink clicks with FireMonkey (cross platform)

I have a TWebBrowser on a FireMonkey app (Android and iOS).
I'd like to be able to intercept (trap) hyperlink clicks in the TWebBrowser and do something different with them.
I've found references to working with the BeforeNavigate2 event. However, I see no way of adding a procedure for that event in the Object Inspector. And I'm not sure if that event exists for Android or iOS; or if it's just a Windows event.
Is there any way to get to intercept hyperlink clicks cross platform?
[Edit]
My ultimate goal here is to intercept a hyperlink click in the browser component and do something different with it (e.g., I'd like to spawn it off to the native browser instead).
OnShouldStartLoadWithRequest doesn't trigger on a click. Actually it doesn't seem to trigger anywhere for me. Others have had this issue (Incus J).
OnDidStartLoad does trigger; however, it appears to carry on with the page load in the background regardless of what's going on in the trigger. I can add a myWebBrowser.Stop in the trigger; however, it does not reliably work. I suspect that sometimes the page load completes before the Stop gets fired off.
Playing with OnDidFinishLoad and using the GoBack method proved awkward because the previous page would reload to the top of the page instead of what was being shown in the control (if the user scrolled).
Am I stuck trying to hack Android/iOS equivalents of TWindowsWebBrowserService as Incus J suggests in the thread I reference above?

CakePhP jquery debuging modal dialogs data flow

I have quite a big application, sometimes with pretty complicate data being created by the user (on the way to the database the data is being altered a lot). The issue is, that any time I need to alter the code, I get stuck for quite a few hours before finding the problem.
Actions in my app:
User opens the jquery modal dialog
There is a form in the modal dialog
User alerts the data and saves it
About app:
The application contains of one site with a table and several buttons
Each of these buttons open a different modal dialog
Each form submission is handled via ajax -> cakephps this->js->submit
How I wrote the code:
For each modal dialog I created an element
After clicking the button I open the element as a jquery modal dialog
Lots of these modals gain information via for example: "On click/on double click etc" events.
My problem:
Every time I alter the cakephp code which is called by $this->Js->submit I feel like putting a gun to my face and pulling the trigger.
I dont know of any easy way of how to debug variables in these functions (cakephps debug doesnt show anything ofc -> the view of those ajax/php functions are not in the main site)
Dont know if firebug has any features for debugging php, but I dont know of any.
The only thing that works for me a bit is commenting out lines of code and putting an alert in the success like this to maybe sometimes get to the values, but it doesnt feel right.
Being used to write code in c++/java and printing or debugging with breakpoints makes me frustrated, when I use such a modern programming language and try to guess out where the bugs might be..
Most errors:
Mostly null pointers or checking !isset index being accessed, but since I know of no way of printing these errors from modals no checking on the indexes helps me.
Use FirePHP it is a great enhancment of firebug. Works well.

detecting a change in the page including refresh

so i am working in a .tpl file meaning i am open to js, html and php answers. what i want to do is whenever a person refreshes the page, experience a change in the url or exits the browser, my site would take an action based on this change of state. so basically, when they leave that specific page of mines in any way, i would call a function. the reason i want this is because i am saving this editable image on my site. but whenever they leave the page, i want the image the created to be autosaved.
this task splits into client-side and server-side parts. At client side you should bind to interesting browser events, triggering some background http requests to some service URLs of your website, this is probably JS. At the server side, you should provide corresponding reaction to these requests, which is probably PHP.
As long as these service URLs are to be called intermittently by various visitors, be sure to keep an eye on what request came from which client's window. PHP sessions should help you.
I'd propose to work this separately, first to get saving machinery working -- just bind everything to explicit big buttons at the page (page close, url change, etc), then replace each button with the binding to exact JS event. Keep in mind differencies among browsers.

Jquery Mobile Logon Loop

Knocked-out a simple jQuery Mobile site with [logon -> index -> content] pages.
If I use the back button to the logon page, I can't escape no matter what I do - forward, back, filling it in, nothing.
I'd like to remove the #logon page from the navigation, so you cannot get back to it without typing it in, or logging out - any advice?
Easiest way to keep a page from showing up in history (with jquery mobile) is show that page in a dialog. This model works particularly well in situations where the content that would be in a dialog is either tangential to the main content or some sort of interrupt (which the login process is). See an example here. DISLAIMER: this is not the right way to implement content like this in the long run, it is only meant to show the effect of using a dialog in a login process to bypass insertion into history.
Another (more manual) route would be to use the a normal jqm page and do your login by way of an ajax posting. If the response came back as successful, then use location.replace() to remove the the current (logon) page from history.
I ended up removing the ajax navigation full stop and sticking to manual, not as pretty but headaches avoided!

How can I make something similar to that cool bar on the top of stackoverflow that pops up when you get a new badge?

When you get a new badge on stackoverflow.com, a bar appears at the top of the screen informing you of your achievement. It sticks around until the user closes it.
I rather like that system of informing the user about new news related to the site or their account. It's fairly unintrusive, but still clearly communicates the information. Even if all users receive a notification this way, it sticks around for each user until they have acknowledged seeing it.
I'm running a system using Ruby on Rails on a PostGres database. What's the best way to implement a similar system on my setup?
Edit: Just to clarify, I'm interested both in the server side and client side of the setup.
The effect can be accomplished with jQuery and the slideDown method (http://api.jquery.com/slideDown/). Set an onClick event to make the element slideUp, hide, or hit an AJAX call to let you know that the user got the message and dismissed it.
You could set the contents of the element (I'd go with a div) via an AJAX call, or you could simply populate the div with the appropriate message when generating your page, start the div off as hidden, and then kick off the slideDown method when the page load is complete via a $(document).ready definition (http://think2loud.com/jquery-document-ready-howto/).
You could use something like the jquery popup bubble extension: http://www.farmcode.org/post/2009/04/06/jQuery-popup-bubble-extension.aspx

Resources