2015-12-01 13:33:08 -06:00
|
|
|
declare var window;
|
|
|
|
|
|
|
|
/**
|
2016-06-09 21:22:05 -04:00
|
|
|
* Initialize the ionic.native Angular module if we're running in ng1.
|
2016-06-09 11:24:38 -05:00
|
|
|
* This iterates through the list of registered plugins and dynamically
|
2016-08-17 00:59:02 -05:00
|
|
|
* creates Angular 1 services of the form $cordovaSERVICE, ex: $cordovaStatusBar.
|
2015-12-01 13:33:08 -06:00
|
|
|
*/
|
2016-06-09 11:24:38 -05:00
|
|
|
export function initAngular1(plugins) {
|
2016-04-29 23:56:49 -04:00
|
|
|
if (window.angular) {
|
2016-09-07 02:42:29 +01:00
|
|
|
|
|
|
|
const ngModule = window.angular.module('ionic.native', []);
|
2015-12-01 13:33:08 -06:00
|
|
|
|
2016-06-09 21:22:05 -04:00
|
|
|
for (var name in plugins) {
|
2016-06-09 11:24:38 -05:00
|
|
|
let serviceName = '$cordova' + name;
|
|
|
|
let cls = plugins[name];
|
|
|
|
|
|
|
|
(function(serviceName, cls, name) {
|
2016-09-07 02:42:29 +01:00
|
|
|
ngModule.service(serviceName, [function() {
|
2016-08-04 09:40:24 -05:00
|
|
|
var funcs = window.angular.copy(cls);
|
|
|
|
funcs.prototype['name'] = name;
|
2016-06-09 11:24:38 -05:00
|
|
|
return funcs;
|
2016-06-09 21:20:55 -04:00
|
|
|
}]);
|
2016-06-09 11:24:38 -05:00
|
|
|
})(serviceName, cls, name);
|
2015-12-01 13:33:08 -06:00
|
|
|
}
|
2016-06-09 11:24:38 -05:00
|
|
|
}
|
2016-08-04 09:40:24 -05:00
|
|
|
}
|