mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
Moved to Plugins
This commit is contained in:
@@ -24,4 +24,4 @@ export * from './transitions/transition'
|
||||
export * from './transitions/ios-transition'
|
||||
export * from './transitions/md-transition'
|
||||
|
||||
export * from './native/plugins'
|
||||
export * from './plugins/plugins'
|
||||
|
||||
@@ -6,6 +6,9 @@ import {NativePlugin} from '../plugin';
|
||||
name: 'Camera',
|
||||
platforms: {
|
||||
cordova: 'cordova-plugin-camera'
|
||||
},
|
||||
pluginCheck: () => {
|
||||
return !!navigator.camera;
|
||||
}
|
||||
})
|
||||
export class Camera {
|
||||
@@ -8,6 +8,9 @@ import {NativePlugin} from '../plugin';
|
||||
name: 'Device',
|
||||
platforms: {
|
||||
cordova: 'cordova-plugin-device'
|
||||
},
|
||||
pluginCheck: () => {
|
||||
return !!window.device;
|
||||
}
|
||||
})
|
||||
export class Device {
|
||||
@@ -17,7 +20,7 @@ export class Device {
|
||||
* @returns {Object} The device object.
|
||||
*/
|
||||
static getDevice() {
|
||||
return this.ifPlugin(window.device, () => {
|
||||
return this.ifPlugin(() => {
|
||||
return device;
|
||||
}, () => {
|
||||
return {
|
||||
@@ -36,7 +39,7 @@ export class Device {
|
||||
* @returns {String} The Cordova version.
|
||||
*/
|
||||
static getCordova() {
|
||||
this.ifPlugin(window.device, () => {
|
||||
this.ifPlugin(() => {
|
||||
return device.cordova;
|
||||
});
|
||||
}
|
||||
@@ -47,7 +50,7 @@ export class Device {
|
||||
* @returns {String} The name of the device's model or product.
|
||||
*/
|
||||
static getModel() {
|
||||
this.ifPlugin(window.device, () => {
|
||||
this.ifPlugin(() => {
|
||||
return device.model;
|
||||
}, () => {
|
||||
return 'unknown'
|
||||
@@ -59,7 +62,7 @@ export class Device {
|
||||
* @returns {String}
|
||||
*/
|
||||
static getName() {
|
||||
this.ifPlugin(window.device, () => {
|
||||
this.ifPlugin(() => {
|
||||
return device.name;
|
||||
}, () => {
|
||||
return 'unknown'
|
||||
@@ -72,7 +75,7 @@ export class Device {
|
||||
* @returns {String} The device's operating system name.
|
||||
*/
|
||||
static getPlatform() {
|
||||
this.ifPlugin(window.device, () => {
|
||||
this.ifPlugin(() => {
|
||||
return device.name;
|
||||
}, () => {
|
||||
return 'unknown'
|
||||
@@ -85,7 +88,7 @@ export class Device {
|
||||
* @returns {String} The device's Universally Unique Identifier
|
||||
*/
|
||||
static getUUID() {
|
||||
this.ifPlugin(window.device, () => {
|
||||
this.ifPlugin(() => {
|
||||
return device.uuid;
|
||||
}, () => {
|
||||
return 'unknown';
|
||||
@@ -98,7 +101,7 @@ export class Device {
|
||||
* @returns {String}
|
||||
*/
|
||||
static getVersion() {
|
||||
this.ifPlugin(window.device, () => {
|
||||
this.ifPlugin(() => {
|
||||
return device.version;
|
||||
}, () => {
|
||||
return 'unknown';
|
||||
@@ -110,7 +113,7 @@ export class Device {
|
||||
* @returns {String}
|
||||
*/
|
||||
static getManufacturer() {
|
||||
this.ifPlugin(window.device, () => {
|
||||
this.ifPlugin(() => {
|
||||
return device.manufacturer;
|
||||
}, () => {
|
||||
return 'unknown';
|
||||
61
ionic/plugins/keyboard/keyboard.ts
Normal file
61
ionic/plugins/keyboard/keyboard.ts
Normal 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;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -3,18 +3,20 @@ export class NativePluginDecorator {
|
||||
this.cls = cls;
|
||||
this.config = config;
|
||||
|
||||
cls.ifPlugin = (check, cb, returnType=null) => {
|
||||
cls.ifPlugin = (cb, returnType=null) => {
|
||||
// Convert to boolean the plugin param
|
||||
var exists = !!check;
|
||||
if(typeof check === 'function') {
|
||||
exists = check();
|
||||
if(typeof this.config.pluginCheck === 'function') {
|
||||
exists = this.config.pluginCheck();
|
||||
}
|
||||
if(exists) {
|
||||
return cb();
|
||||
}
|
||||
|
||||
// We don't have the plugin, so print a warning message
|
||||
cls.pluginWarn();
|
||||
|
||||
// If the user supplied a default return value, return it here.
|
||||
return (typeof returnType === 'function') ? returnType() : returnType;
|
||||
};
|
||||
|
||||
@@ -7,5 +7,6 @@ export * from './device/device'
|
||||
export * from './device-motion/device-motion'
|
||||
export * from './device-orientation/device-orientation'
|
||||
export * from './geolocation/geolocation'
|
||||
export * from './keyboard/keyboard'
|
||||
export * from './statusbar/statusbar'
|
||||
export * from './vibration/vibration'
|
||||
@@ -10,6 +10,9 @@ import {NativePlugin} from '../plugin';
|
||||
name: 'StatusBar',
|
||||
platforms: {
|
||||
cordova: 'cordova-plugin-statusbar'
|
||||
},
|
||||
pluginCheck: () => {
|
||||
return !!window.StatusBar;
|
||||
}
|
||||
})
|
||||
export class StatusBar {
|
||||
@@ -22,16 +25,16 @@ export class StatusBar {
|
||||
* Show the StatusBar
|
||||
*/
|
||||
static show() {
|
||||
this.ifPlugin(window.StatusBar, () => {
|
||||
this.ifPlugin(() => {
|
||||
window.StatusBar.show();
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Hide the StatusBar
|
||||
*/
|
||||
static hide() {
|
||||
this.ifPlugin(window.StatusBar, () => {
|
||||
this.ifPlugin(() => {
|
||||
window.StatusBar.hide();
|
||||
})
|
||||
}
|
||||
@@ -49,7 +52,7 @@ export class StatusBar {
|
||||
* @param style the style from above
|
||||
*/
|
||||
static setStyle(style) {
|
||||
this.ifPlugin(window.StatusBar, () => {
|
||||
this.ifPlugin(() => {
|
||||
switch(style) {
|
||||
case StatusBar.DEFAULT:
|
||||
window.StatusBar.styleDefault();
|
||||
@@ -75,7 +78,7 @@ export class StatusBar {
|
||||
* @param hex the hex value of the color.
|
||||
*/
|
||||
static setHexColor(hex) {
|
||||
this.ifPlugin(window.StatusBar, () => {
|
||||
this.ifPlugin(() => {
|
||||
window.StatusBar.backgroundColorByHexName(hex);
|
||||
});
|
||||
}
|
||||
@@ -89,7 +92,7 @@ export class StatusBar {
|
||||
* @param name the name of the color (from above)
|
||||
*/
|
||||
static setNamedColor(name) {
|
||||
this.ifPlugin(window.StatusBar, () => {
|
||||
this.ifPlugin(() => {
|
||||
window.StatusBar.backgroundColorByName(name);
|
||||
});
|
||||
}
|
||||
@@ -101,7 +104,7 @@ export class StatusBar {
|
||||
* @param doesOverlay whether the status bar overlays the main app view.
|
||||
*/
|
||||
static setOverlays(doesOverlay) {
|
||||
this.ifPlugin(window.StatusBar, () => {
|
||||
this.ifPlugin(() => {
|
||||
window.StatusBar.overlaysWebView(doesOverlay);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user