Download files and store them locally with Phonegap/jQuery Mobile Android and iOS Apps

Use FileTransfer.download, here is an example: function downloadFile(){ window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function onFileSystemSuccess(fileSystem) { fileSystem.root.getFile( “dummy.html”, {create: true, exclusive: false}, function gotFileEntry(fileEntry) { var sPath = fileEntry.fullPath.replace(“dummy.html”,””); var fileTransfer = new FileTransfer(); fileEntry.remove(); fileTransfer.download( “http://www.w3.org/2011/web-apps-ws/papers/Nitobi.pdf”, sPath + “theFile.pdf”, function(theFile) { console.log(“download complete: ” + theFile.toURI()); showLink(theFile.toURI()); }, function(error) { console.log(“download error source ” + error.source); console.log(“download … Read more

fullcalendar multiple cell select on mobile device?

How about adding event listeners to the cells of already initialized calendar and applying some magic, like this: $(‘#calendar table.fc-border-separate td.ui-widget-content’).on(‘touchstart’, function (event) { /* touch start processing, probably cancelling like*/ event.preventDefault(); event.stopImmediatePropagation(); function mouseMoveHandler (event) { /* processing actual drag */ /* possible also cancelling default behavior and instead calling Calendar API */ } … Read more

Screen orientation ios

Check some JQM API here…( haven’t test yet ) http://api.jquerymobile.com/orientationchange/ Orientationchange Timing The timing of the orientationchange event with relation to the change of the client height and width is different between browsers, though the current implementation will give you the correct value for event.orientation derived from window.orientation. This means that if your bindings are … Read more

Correct way of using JQuery-Mobile/Phonegap together?

You can use deferred feature of JQuery. var deviceReadyDeferred = $.Deferred(); var jqmReadyDeferred = $.Deferred(); document.addEventListener(“deviceReady”, deviceReady, false); function deviceReady() { deviceReadyDeferred.resolve(); } $(document).one(“mobileinit”, function () { jqmReadyDeferred.resolve(); }); $.when(deviceReadyDeferred, jqmReadyDeferred).then(doWhenBothFrameworksLoaded); function doWhenBothFrameworksLoaded() { // TBD }

Setting up the jQuery Mobile script

Update: jQuery Mobile 1.4 The following events are deprecated and will be removed on jQuery Mobile 1.5: pageshow Replacement: pagecontainershow Usage: It is used to retrieve id of previous page. $(document).on(“pagecontainershow”, function (e, ui) { var previous = ui.prevPage; }); This event cant be attached to a specific page ID. Recommendation: Use pagebeforeshow instead to … Read more

How can I control the back button event in jQuery Mobile?

Recommended method pagecontainerbeforechange: https://jqmtricks.wordpress.com/2014/12/01/detect-back-navigation/ You need to listen to the navigation event and state.direction. $(window).on(“navigate”, function (event, data) { var direction = data.state.direction; if (direction == ‘back’) { // Do something } if (direction == ‘forward’) { // Do something else } }); jQuery Mobile API: Navigation event Demo

How to fallback to local stylesheet (not script) if CDN fails

One could use onerror for that: <link rel=”stylesheet” href=”cdn.css” onerror=”this.onerror=null;this.href=”https://stackoverflow.com/questions/7383163/local.css”;” /> The this.onerror=null; is to avoid endless loops in case the fallback it self is not available. But it could also be used to have multiple fallbacks. However, this currently only works in Firefox and Chrome. Update: Meanwhile, this seems to be supported by all … Read more