Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now you can easily detect the running platform and wait for the device to be ready even if that ready even already fired.
- Loading branch information
Showing
3 changed files
with
151 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
angular.module('ionic.platform', []) | ||
|
||
/** | ||
* The platformProvider makes it easy to set and detect which platform | ||
* the app is currently running on. It has some auto detection built in | ||
* for PhoneGap and Cordova. This provider also takes care of | ||
* initializing some defaults that depend on the platform, such as the | ||
* height of header bars on iOS 7. | ||
*/ | ||
.provider('platform', function() { | ||
var platform = 'unknown'; | ||
var isPlatformReady = false; | ||
|
||
if(window.cordova || window.PhoneGap || window.phonegap) { | ||
platform = 'cordova'; | ||
} | ||
|
||
console.log('Detected platform', platform); | ||
|
||
var isReady = function() { | ||
if(platform == 'cordova') { | ||
return window.device; | ||
} | ||
return true; | ||
}; | ||
|
||
// We need to do some stuff as soon as we know the platform, | ||
// like adjust header margins for iOS 7, etc. | ||
setTimeout(function afterReadyWait() { | ||
if(isReady()) { | ||
ionic.Platform.detect(); | ||
} else { | ||
setTimeout(afterReadyWait, 50); | ||
} | ||
}, 10); | ||
|
||
return { | ||
setPlatform: function(p) { | ||
platform = p; | ||
}, | ||
$get: ['$q', '$timeout', function($q, $timeout) { | ||
return { | ||
ready: function(cb) { | ||
var self = this; | ||
var q = $q.defer(); | ||
|
||
$timeout(function readyWait() { | ||
if(isReady()) { | ||
isPlatformReady = true; | ||
q.resolve(); | ||
cb(); | ||
} else { | ||
$timeout(readyWait, 50); | ||
} | ||
}, 50); | ||
|
||
return q.promise; | ||
} | ||
}; | ||
}] | ||
}; | ||
}); | ||
|
||
})(ionic); |
This file contains 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