mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2026-05-20 00:06:24 +08:00
Demo
This commit is contained in:
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
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;
|
||||
}
|
||||
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
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;
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export * from './plugins/camera';
|
||||
export * from './plugins/statusbar';
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
__export(require('./plugins/camera'));
|
||||
__export(require('./plugins/statusbar'));
|
||||
Vendored
+6
-3
@@ -1,3 +1,6 @@
|
||||
export declare class Camera {
|
||||
static getPicture: (...args: any[]) => any;
|
||||
}
|
||||
export declare var Camera: {
|
||||
name: string;
|
||||
plugin: string;
|
||||
getPicture: (...args: any[]) => any;
|
||||
cleanup: (...args: any[]) => any;
|
||||
};
|
||||
|
||||
Vendored
+6
-7
@@ -1,9 +1,8 @@
|
||||
var util_1 = require('../util');
|
||||
var PLUGIN_REF = 'navigator.camera';
|
||||
var Camera = (function () {
|
||||
function Camera() {
|
||||
}
|
||||
Camera.getPicture = util_1.promisify(PLUGIN_REF, 'getPicture', 0, 1);
|
||||
return Camera;
|
||||
})();
|
||||
exports.Camera = Camera;
|
||||
exports.Camera = {
|
||||
name: 'Camera',
|
||||
plugin: 'cordova-plugin-camera',
|
||||
getPicture: util_1.promisify(PLUGIN_REF, 'getPicture', 0, 1),
|
||||
cleanup: util_1.promisify(PLUGIN_REF, 'cleanup', 0, 1)
|
||||
};
|
||||
|
||||
Vendored
+1
@@ -1,2 +1,3 @@
|
||||
export declare function get(obj: any, path: any): any;
|
||||
export declare const promisify: (pluginRef: any, methodName: any, successIndex: any, errorIndex: any) => (...args: any[]) => any;
|
||||
export declare const wrap: (pluginRef: any, methodName: any, successIndex?: any, errorIndex?: any) => (...args: any[]) => any;
|
||||
|
||||
Vendored
+19
@@ -20,3 +20,22 @@ exports.promisify = function (pluginRef, methodName, successIndex, errorIndex) {
|
||||
});
|
||||
};
|
||||
};
|
||||
exports.wrap = function (pluginRef, methodName, successIndex, errorIndex) {
|
||||
if (successIndex === void 0) { successIndex = null; }
|
||||
if (errorIndex === void 0) { errorIndex = null; }
|
||||
return function () {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i - 0] = arguments[_i];
|
||||
}
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (successIndex) {
|
||||
args[successIndex] = resolve;
|
||||
}
|
||||
if (errorIndex) {
|
||||
args[errorIndex] = reject;
|
||||
}
|
||||
get(window, pluginRef)[methodName].apply(_this, args);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user