diff --git a/README.md b/README.md index 3374a10a1..2be341c8e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,10 @@ # Ionic Native -Native plugins to replace ngCordova +Ionic Native comes with a curated set of Native Cordova plugins that you can use to +pretty much do any native function you need from your [Ionic](http://ionicframework.com/), Cordova, or Web View mobile apps. + +# Credits + +Max Lynch - [@maxlynch](http://twitter.com/maxlynch) + +Rob Wormald - [@robwormald](https://twitter.com/robwormald) diff --git a/dist/plugins/plugin.js b/dist/plugins/plugin.js index ab81e56da..9e0f42e1a 100644 --- a/dist/plugins/plugin.js +++ b/dist/plugins/plugin.js @@ -49,7 +49,7 @@ function Cordova(opts) { if (opts.promise) { console.log('TODO: Promise'); } - obj[methodName] = exports.wrap(obj, methodName, opts); + obj[methodName] = exports.wrap(obj, methodName, opts).bind(obj); }; } exports.Cordova = Cordova; diff --git a/dist/plugins/toast.js b/dist/plugins/toast.js index 1b80cdaae..aa3ea8b4b 100644 --- a/dist/plugins/toast.js +++ b/dist/plugins/toast.js @@ -18,8 +18,8 @@ var Toast = (function () { ], Toast, "hide"); __decorate([ plugin_1.Cordova({ - successIndex: 0, - errIndex: 1 + successIndex: 1, + errIndex: 2 }) ], Toast, "showWithOptions"); Toast = __decorate([ diff --git a/dist/src/cordova.d.ts b/dist/src/cordova.d.ts index bc833b0fd..e69de29bb 100644 --- a/dist/src/cordova.d.ts +++ b/dist/src/cordova.d.ts @@ -1,5 +0,0 @@ -export declare class Cordova { - static hasPlugin(pluginRef: string): boolean; - static plugin(pluginRef: string): any; - static promisify(pluginRef: any, pluginName: any, methodName: any, successIndex: any, errorIndex: any): (...args: any[]) => any; -} diff --git a/dist/src/cordova.js b/dist/src/cordova.js index 822d01b26..e69de29bb 100644 --- a/dist/src/cordova.js +++ b/dist/src/cordova.js @@ -1,42 +0,0 @@ -var util_1 = require('./util'); -var Cordova = (function () { - function Cordova() { - } - Cordova.hasPlugin = function (pluginRef) { - return !!this.plugin(pluginRef); - }; - Cordova.plugin = function (pluginRef) { - return util_1.get(window, pluginRef); - }; - Cordova.promisify = function (pluginRef, pluginName, methodName, successIndex, errorIndex) { - var _this = this; - return function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; - } - return new Promise(function (resolve, reject) { - if (!window.cordova) { - console.warn('Cordova: tried calling', '"' + pluginName + '.' + methodName + '"', 'but Cordova is not defined. Please make sure you have cordova.js included in your index.html file and you are running in a proper cordova environment'); - reject({ - error: 'cordova_not_available' - }); - return; - } - if (!_this.hasPlugin(pluginRef)) { - console.warn('Cordova: tried calling', '"' + pluginName + '.' + methodName + '"', 'but the ' + pluginName + ' plugin is not installed.'); - reject({ - error: 'plugin_not_installed' - }); - return; - } - console.log('Cordova: exec(' + pluginName + ', ' + methodName + ')'); - args[successIndex] = resolve; - args[errorIndex] = reject; - util_1.get(window, pluginRef)[methodName].apply(_this, args); - }); - }; - }; - return Cordova; -})(); -exports.Cordova = Cordova; diff --git a/dist/src/plugins/plugin.js b/dist/src/plugins/plugin.js index 07ba08fc0..76b00903d 100644 --- a/dist/src/plugins/plugin.js +++ b/dist/src/plugins/plugin.js @@ -48,7 +48,7 @@ function Cordova(opts) { if (opts.promise) { console.log('TODO: Promise'); } - obj[methodName] = exports.wrap(obj, methodName, opts); + obj[methodName] = exports.wrap(obj, methodName, opts).bind(obj); }; } exports.Cordova = Cordova; diff --git a/dist/src/plugins/toast.js b/dist/src/plugins/toast.js index b19e91164..c69aec705 100644 --- a/dist/src/plugins/toast.js +++ b/dist/src/plugins/toast.js @@ -20,8 +20,8 @@ var Toast = (function () { ], Toast, "hide", void 0); __decorate([ plugin_1.Cordova({ - successIndex: 0, - errIndex: 1 + successIndex: 1, + errIndex: 2 }), __metadata('design:type', Object) ], Toast, "showWithOptions", void 0); diff --git a/src/cordova.ts b/src/cordova.ts deleted file mode 100644 index 14064ab3b..000000000 --- a/src/cordova.ts +++ /dev/null @@ -1,43 +0,0 @@ -//patch the window definition -declare var Promise; -declare var cordova; -declare var window; - -import {get} from './util'; - -export class Cordova { - static hasPlugin(pluginRef: string) { - return !!this.plugin(pluginRef); - } - static plugin(pluginRef: string) { - return get(window, pluginRef); - } - - static promisify(pluginRef, pluginName, methodName, successIndex, errorIndex) { - return (...args) => { - return new Promise((resolve, reject) => { - if(!window.cordova) { - console.warn('Cordova: tried calling', '"' + pluginName + '.' + methodName + '"', 'but Cordova is not defined. Please make sure you have cordova.js included in your index.html file and you are running in a proper cordova environment'); - reject({ - error: 'cordova_not_available' - }); - return; - } - - if(!this.hasPlugin(pluginRef)) { - console.warn('Cordova: tried calling', '"' + pluginName + '.' + methodName + '"', 'but the ' + pluginName + ' plugin is not installed.'); - reject({ - error: 'plugin_not_installed' - }); - return; - } - console.log('Cordova: exec(' + pluginName + ', ' + methodName +')'); - - args[successIndex] = resolve; - args[errorIndex] = reject; - - get(window, pluginRef)[methodName].apply(this, args); - }) - } - } -} diff --git a/src/plugins/plugin.ts b/src/plugins/plugin.ts index 6b6a40166..afcc0b9df 100644 --- a/src/plugins/plugin.ts +++ b/src/plugins/plugin.ts @@ -57,6 +57,6 @@ export function Cordova(opts:any = {}) { console.log('TODO: Promise'); } - obj[methodName] = wrap(obj, methodName, opts); + obj[methodName] = wrap(obj, methodName, opts).bind(obj); } } diff --git a/src/plugins/toast.ts b/src/plugins/toast.ts index 9a07f23f0..85d4cbb2b 100644 --- a/src/plugins/toast.ts +++ b/src/plugins/toast.ts @@ -13,8 +13,8 @@ export class Toast { static hide; @Cordova({ - successIndex: 0, - errIndex: 1 + successIndex: 1, + errIndex: 2 }) static showWithOptions; }