-
-
Save andreioprisan/6158918 to your computer and use it in GitHub Desktop.
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 characters
| // 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 | |
| // 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'); | |
| // -------------------------- | |
| // 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; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment