awesome-cordova-plugins/demo/www/app/plugin/plugin.js

76 lines
1.8 KiB
JavaScript
Raw Normal View History

2015-11-29 06:17:04 +08:00
import {Page, NavParams} from 'ionic/ionic';
2015-11-30 06:30:15 +08:00
import {Camera, StatusBar, Toast, ActionSheet} from 'ionic-native';
2015-11-29 06:52:05 +08:00
// To specify arguments for any plugin calls
var demoArgs = {};
2015-11-30 06:30:15 +08:00
demoArgs[ActionSheet] = {
show: {
2015-11-30 12:29:55 +08:00
'buttonLabels': ['Log out'],
2015-11-30 06:30:15 +08:00
'androidEnableCancelButton' : true, // default false
'winphoneEnableCancelButton' : true, // default false
2015-11-30 12:29:55 +08:00
'addCancelButtonWithLabel': 'Cancel'
2015-11-30 06:30:15 +08:00
}
}
2015-11-29 06:52:05 +08:00
demoArgs[Toast] = {
showWithOptions: [
{
message: "hey there",
duration: "short",
position: "bottom",
addPixelsY: -40 // added a negative value to move it up a bit (default 0)
}
]
}
2015-11-29 06:17:04 +08:00
@Page({
templateUrl: 'app/plugin/plugin.html',
})
export class Plugin {
constructor(params: NavParams) {
this.plugin = params.get('plugin');
console.log('Plugin', this.plugin);
this.methods = Object.keys(this.plugin).filter((k) => {
if(typeof this.plugin[k] === 'function') {
return true;
}
return false;
});
}
doMethod(method) {
2015-11-29 06:52:05 +08:00
let pluginMethodArgEntry = demoArgs[this.plugin];
let args = [];
if(pluginMethodArgEntry) {
2015-11-30 12:38:28 +08:00
args = [pluginMethodArgEntry[method]] || [];
2015-11-30 12:29:55 +08:00
console.log('Found some default args', args);
2015-11-29 06:52:05 +08:00
}
2015-11-29 08:26:55 +08:00
Toast.showWithOptions({
message: 'Doing ' + this.plugin.name + '.' + method + '()',
duration: "short",
position: "bottom",
addPixelsY: -40 // added a negative value to move it up a bit (default 0)
});
2015-11-29 06:52:05 +08:00
console.log('Doing method', method, 'on Plugin', this.plugin, 'args:', args);
2015-11-30 07:20:11 +08:00
let v = this.plugin[method].apply(this.plugin, args);
if(v && v.then) {
v.then(() => {
console.log('Success', arguments);
}, (err) => {
console.error('Error', err);
});
} else {
console.log('Response: ', v);
}
2015-11-29 06:17:04 +08:00
}
}