Last active
September 22, 2018 17:15
Revisions
-
zeroasterisk revised this gist
Apr 17, 2013 . 1 changed file with 8 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,14 @@ Session.set('CordovaLoaded', false); Meteor.startup(function() { console.log('cordova loading'); // delay loading of cordova until after DOM is ready // determine WHICH cordova to load var cordovajspath = '/cordova-2.6.0.js'; if (navigator.userAgent.match(/(iPad|iPhone|iOS)/) != null) { cordovajspath = '/cordova-2.6.0-ios.js'; } else if (navigator.userAgent.match(/(Android)/) != null) { cordovajspath = '/cordova-2.6.0-android.js'; } $.getScript(cordovajspath, function() { Session.set('CordovaLoaded', true); console.log('cordova loaded'); // -------------------------- -
zeroasterisk created this gist
Apr 17, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ // initialize as soon as the DOM is ready Session.set('CordovaLoaded', false); Meteor.startup(function() { console.log('cordova loading'); // delay loading of cordova until after DOM is ready $.getScript('/cordova-2.6.0.js', function() { Session.set('CordovaLoaded', true); console.log('cordova loaded'); // -------------------------- // SETUP for Devices // -------------------------- if (! (document.deviceEventsSetup)) { // http://docs.phonegap.com/en/2.6.0/cordova_events_events.md.html#Events document.deviceEventsSetup = true; // when an app 'resumes' // This is an event that fires when a Cordova application is retrieved from the background. document.addEventListener("resume", function() { // http://docs.meteor.com/#meteor_reconnect // Force an immediate reconnection attempt if the client is not connected // to the server. // This method does nothing if the client is already connected. Meteor.reconnect(); Meteor.resume(); }); // when an app goes into the background document.addEventListener("Pause", function() { Cookie.set('LastPage', Meteor.Router.page()); }); // when an app drops 'offline' document.addEventListener("offline", function() { if (Meteor.Router.page() != 'offline' && Meteor.Router.page() != 'loading') { Cookie.set('LastPage', Meteor.Router.page()); Meteor.Router.to('/offline'); } }); // when an app comes 'online' document.addEventListener("online", function() { Meteor.resume(); }); } }); }); // resume functionality, common (used in offline.js as well) Meteor.resume = function() { if (Meteor.status().status != 'connected') { return false; } if (Meteor.Router.page() != 'offline' && Meteor.Router.page() != 'loading') { return true; } var LastPage = Cookie.get('LastPage'); if (_.isString(LastPage) && LastPage.length && LastPage != 'loading') { console.log('resumed to: (LastPage)', '/' + LastPage); Meteor.Router.to('/' + LastPage); return true; } Meteor.Router.to('/'); return true; };