mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2026-05-02 00:07:23 +08:00
Demo
This commit is contained in:
Vendored
+5
-2
@@ -1,2 +1,5 @@
|
||||
declare const promisifyCordova: (pluginObj: any, pluginName: any, methodName: any) => (...args: any[]) => any;
|
||||
export { promisifyCordova };
|
||||
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
+41
-26
@@ -1,27 +1,42 @@
|
||||
var promisifyCordova = function (pluginObj, pluginName, methodName) {
|
||||
return function () {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i - 0] = arguments[_i];
|
||||
}
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (!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 (!pluginObj.installed()) {
|
||||
console.warn('Cordova: tried calling', '"' + pluginName + '.' + methodName + '"', 'but the ' + pluginObj.plugin + ' plugin is not installed.');
|
||||
reject({
|
||||
error: 'plugin_not_installed'
|
||||
});
|
||||
return;
|
||||
}
|
||||
console.log('Cordova: exec(' + pluginName + ', ' + methodName + ')');
|
||||
cordova.exec(resolve, reject, pluginName, methodName, args);
|
||||
});
|
||||
var util_1 = require('./util');
|
||||
var Cordova = (function () {
|
||||
function Cordova() {
|
||||
}
|
||||
Cordova.hasPlugin = function (pluginRef) {
|
||||
return !!this.plugin(pluginRef);
|
||||
};
|
||||
};
|
||||
exports.promisifyCordova = promisifyCordova;
|
||||
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
+1
@@ -1 +1,2 @@
|
||||
export * from './plugins/camera';
|
||||
export * from './plugins/statusbar';
|
||||
|
||||
Vendored
+1
@@ -2,6 +2,7 @@ function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
__export(require('./plugins/camera'));
|
||||
__export(require('./plugins/statusbar'));
|
||||
/*
|
||||
let wrappedPlugins = {}
|
||||
|
||||
|
||||
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
+8
-7
@@ -1,9 +1,10 @@
|
||||
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 = {
|
||||
// Metadata
|
||||
name: 'Camera',
|
||||
plugin: 'cordova-plugin-camera',
|
||||
// Methods
|
||||
getPicture: util_1.promisify(PLUGIN_REF, 'getPicture', 0, 1),
|
||||
cleanup: util_1.promisify(PLUGIN_REF, 'cleanup', 0, 1)
|
||||
};
|
||||
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
export declare var StatusBar: {
|
||||
name: string;
|
||||
plugin: string;
|
||||
overlaysWebView: (...args: any[]) => any;
|
||||
styleDefault: (...args: any[]) => any;
|
||||
styleLightContent: (...args: any[]) => any;
|
||||
styleBlackTranslucent: (...args: any[]) => any;
|
||||
styleBlackOpaque: (...args: any[]) => any;
|
||||
backgroundColorByName: (...args: any[]) => any;
|
||||
backgroundColorByHexString: (...args: any[]) => any;
|
||||
hide: (...args: any[]) => any;
|
||||
show: (...args: any[]) => any;
|
||||
};
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
var util_1 = require('../util');
|
||||
var PLUGIN_REF = 'StatusBar';
|
||||
exports.StatusBar = {
|
||||
// Metadata
|
||||
name: 'StatusBar',
|
||||
plugin: 'cordova-plugin-statusbar',
|
||||
// Methods
|
||||
overlaysWebView: util_1.wrap(PLUGIN_REF, 'overlaysWebView'),
|
||||
styleDefault: util_1.wrap(PLUGIN_REF, 'styleDefault'),
|
||||
styleLightContent: util_1.wrap(PLUGIN_REF, 'styleLightContent'),
|
||||
styleBlackTranslucent: util_1.wrap(PLUGIN_REF, 'styleBlackTranslucent'),
|
||||
styleBlackOpaque: util_1.wrap(PLUGIN_REF, 'styleBlackOpaque'),
|
||||
backgroundColorByName: util_1.wrap(PLUGIN_REF, 'backgroundColorByName'),
|
||||
backgroundColorByHexString: util_1.wrap(PLUGIN_REF, 'backgroundColorByHexString'),
|
||||
hide: util_1.wrap(PLUGIN_REF, 'hide'),
|
||||
show: util_1.wrap(PLUGIN_REF, 'show')
|
||||
};
|
||||
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);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
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