Moved to Plugins

This commit is contained in:
Max Lynch
2015-09-15 10:53:14 -05:00
parent c9686eb418
commit a8482a660a
14 changed files with 92 additions and 19 deletions

View File

@ -24,4 +24,4 @@ export * from './transitions/transition'
export * from './transitions/ios-transition' export * from './transitions/ios-transition'
export * from './transitions/md-transition' export * from './transitions/md-transition'
export * from './native/plugins' export * from './plugins/plugins'

View File

@ -6,6 +6,9 @@ import {NativePlugin} from '../plugin';
name: 'Camera', name: 'Camera',
platforms: { platforms: {
cordova: 'cordova-plugin-camera' cordova: 'cordova-plugin-camera'
},
pluginCheck: () => {
return !!navigator.camera;
} }
}) })
export class Camera { export class Camera {

View File

@ -8,6 +8,9 @@ import {NativePlugin} from '../plugin';
name: 'Device', name: 'Device',
platforms: { platforms: {
cordova: 'cordova-plugin-device' cordova: 'cordova-plugin-device'
},
pluginCheck: () => {
return !!window.device;
} }
}) })
export class Device { export class Device {
@ -17,7 +20,7 @@ export class Device {
* @returns {Object} The device object. * @returns {Object} The device object.
*/ */
static getDevice() { static getDevice() {
return this.ifPlugin(window.device, () => { return this.ifPlugin(() => {
return device; return device;
}, () => { }, () => {
return { return {
@ -36,7 +39,7 @@ export class Device {
* @returns {String} The Cordova version. * @returns {String} The Cordova version.
*/ */
static getCordova() { static getCordova() {
this.ifPlugin(window.device, () => { this.ifPlugin(() => {
return device.cordova; return device.cordova;
}); });
} }
@ -47,7 +50,7 @@ export class Device {
* @returns {String} The name of the device's model or product. * @returns {String} The name of the device's model or product.
*/ */
static getModel() { static getModel() {
this.ifPlugin(window.device, () => { this.ifPlugin(() => {
return device.model; return device.model;
}, () => { }, () => {
return 'unknown' return 'unknown'
@ -59,7 +62,7 @@ export class Device {
* @returns {String} * @returns {String}
*/ */
static getName() { static getName() {
this.ifPlugin(window.device, () => { this.ifPlugin(() => {
return device.name; return device.name;
}, () => { }, () => {
return 'unknown' return 'unknown'
@ -72,7 +75,7 @@ export class Device {
* @returns {String} The device's operating system name. * @returns {String} The device's operating system name.
*/ */
static getPlatform() { static getPlatform() {
this.ifPlugin(window.device, () => { this.ifPlugin(() => {
return device.name; return device.name;
}, () => { }, () => {
return 'unknown' return 'unknown'
@ -85,7 +88,7 @@ export class Device {
* @returns {String} The device's Universally Unique Identifier * @returns {String} The device's Universally Unique Identifier
*/ */
static getUUID() { static getUUID() {
this.ifPlugin(window.device, () => { this.ifPlugin(() => {
return device.uuid; return device.uuid;
}, () => { }, () => {
return 'unknown'; return 'unknown';
@ -98,7 +101,7 @@ export class Device {
* @returns {String} * @returns {String}
*/ */
static getVersion() { static getVersion() {
this.ifPlugin(window.device, () => { this.ifPlugin(() => {
return device.version; return device.version;
}, () => { }, () => {
return 'unknown'; return 'unknown';
@ -110,7 +113,7 @@ export class Device {
* @returns {String} * @returns {String}
*/ */
static getManufacturer() { static getManufacturer() {
this.ifPlugin(window.device, () => { this.ifPlugin(() => {
return device.manufacturer; return device.manufacturer;
}, () => { }, () => {
return 'unknown'; return 'unknown';

View File

@ -0,0 +1,61 @@
import * as Rx from 'rx';
import * as util from 'ionic/util';
import {NativePlugin} from '../plugin';
/**
* Manage the native keyboard. Note: this plugin performs mainly in the native
* app context. Most operations are non-functional in a normal web browser as
* keyboard control is limited.
*/
@NativePlugin({
name: 'Keyboard',
platforms: {
cordova: 'ionic-plugin-keyboard'
},
pluginCheck: () => {
return window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard;
}
})
export class Keyboard {
/**
* Set whether hte accessory bar is visible.
*
* Note: this only works while running natively (accessory bar cannot be removed
* in most web browsers), and by default the bar is hidden when running natively.
*
* @param isVisible whether the accessory bar is visible
*/
static setAccessoryBarVisible(isVisible) {
this.ifPlugin(() => {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(!isVisible);
})
}
/**
* Close the keyboard.
*/
static close() {
this.ifPlugin(() => {
cordova.plugins.Keyboard.close();
})
}
/**
* Show the keyboard.
*/
static show() {
this.ifPlugin(() => {
cordova.plugins.Keyboard.show();
})
}
/**
* @return the visibility of the keyboard.
*/
static isVisible() {
return this.ifPlugin(() => {
return cordova.plugins.Keyboard.isVisible;
});
}
}

View File

@ -3,18 +3,20 @@ export class NativePluginDecorator {
this.cls = cls; this.cls = cls;
this.config = config; this.config = config;
cls.ifPlugin = (check, cb, returnType=null) => { cls.ifPlugin = (cb, returnType=null) => {
// Convert to boolean the plugin param // Convert to boolean the plugin param
var exists = !!check; var exists = !!check;
if(typeof check === 'function') { if(typeof this.config.pluginCheck === 'function') {
exists = check(); exists = this.config.pluginCheck();
} }
if(exists) { if(exists) {
return cb(); return cb();
} }
// We don't have the plugin, so print a warning message
cls.pluginWarn(); cls.pluginWarn();
// If the user supplied a default return value, return it here.
return (typeof returnType === 'function') ? returnType() : returnType; return (typeof returnType === 'function') ? returnType() : returnType;
}; };

View File

@ -7,5 +7,6 @@ export * from './device/device'
export * from './device-motion/device-motion' export * from './device-motion/device-motion'
export * from './device-orientation/device-orientation' export * from './device-orientation/device-orientation'
export * from './geolocation/geolocation' export * from './geolocation/geolocation'
export * from './keyboard/keyboard'
export * from './statusbar/statusbar' export * from './statusbar/statusbar'
export * from './vibration/vibration' export * from './vibration/vibration'

View File

@ -10,6 +10,9 @@ import {NativePlugin} from '../plugin';
name: 'StatusBar', name: 'StatusBar',
platforms: { platforms: {
cordova: 'cordova-plugin-statusbar' cordova: 'cordova-plugin-statusbar'
},
pluginCheck: () => {
return !!window.StatusBar;
} }
}) })
export class StatusBar { export class StatusBar {
@ -22,16 +25,16 @@ export class StatusBar {
* Show the StatusBar * Show the StatusBar
*/ */
static show() { static show() {
this.ifPlugin(window.StatusBar, () => { this.ifPlugin(() => {
window.StatusBar.show(); window.StatusBar.show();
}) })
} }
/** /**
* Hide the StatusBar * Hide the StatusBar
*/ */
static hide() { static hide() {
this.ifPlugin(window.StatusBar, () => { this.ifPlugin(() => {
window.StatusBar.hide(); window.StatusBar.hide();
}) })
} }
@ -49,7 +52,7 @@ export class StatusBar {
* @param style the style from above * @param style the style from above
*/ */
static setStyle(style) { static setStyle(style) {
this.ifPlugin(window.StatusBar, () => { this.ifPlugin(() => {
switch(style) { switch(style) {
case StatusBar.DEFAULT: case StatusBar.DEFAULT:
window.StatusBar.styleDefault(); window.StatusBar.styleDefault();
@ -75,7 +78,7 @@ export class StatusBar {
* @param hex the hex value of the color. * @param hex the hex value of the color.
*/ */
static setHexColor(hex) { static setHexColor(hex) {
this.ifPlugin(window.StatusBar, () => { this.ifPlugin(() => {
window.StatusBar.backgroundColorByHexName(hex); window.StatusBar.backgroundColorByHexName(hex);
}); });
} }
@ -89,7 +92,7 @@ export class StatusBar {
* @param name the name of the color (from above) * @param name the name of the color (from above)
*/ */
static setNamedColor(name) { static setNamedColor(name) {
this.ifPlugin(window.StatusBar, () => { this.ifPlugin(() => {
window.StatusBar.backgroundColorByName(name); window.StatusBar.backgroundColorByName(name);
}); });
} }
@ -101,7 +104,7 @@ export class StatusBar {
* @param doesOverlay whether the status bar overlays the main app view. * @param doesOverlay whether the status bar overlays the main app view.
*/ */
static setOverlays(doesOverlay) { static setOverlays(doesOverlay) {
this.ifPlugin(window.StatusBar, () => { this.ifPlugin(() => {
window.StatusBar.overlaysWebView(doesOverlay); window.StatusBar.overlaysWebView(doesOverlay);
}); });
} }