Add the ngCordova type definitions

This changeset add the bindings for $cordovaDevice & $cordovaToast
services
This commit is contained in:
Kapil Sachdeva
2015-10-28 19:01:23 -05:00
parent 62eedc3121
commit 3637fe5a06
5 changed files with 193 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
/// <reference path="device.d.ts" />
/// <reference path="../angularjs/angular.d.ts" />
/// <reference path="../ionic/ionic.d.ts" />
// For the full application demo please see follow repo :
// https://github.com/ksachdeva/ngCordova-typescript-demo
namespace demo.device {
'use strict';
interface IDeviceViewModel {
available:boolean;
cordova:string;
model:string;
platform:string;
uuid:string;
version:string;
}
export class DeviceController {
public vm:IDeviceViewModel;
static $inject:Array<string> = ["$ionicPlatform", "$cordovaDevice"];
constructor($ionicPlatform:ionic.platform.IonicPlatformService, $cordovaDevice:ngCordova.IDeviceService) {
$ionicPlatform.ready(() => {
this.vm = {
available : $cordovaDevice.getDevice().available,
cordova : $cordovaDevice.getCordova(),
model : $cordovaDevice.getModel(),
platform : $cordovaDevice.getPlatform(),
uuid : $cordovaDevice.getUUID(),
version : $cordovaDevice.getVersion()
};
});
}
}
angular.module("demo.device").controller("DeviceController", DeviceController);
}
+77
View File
@@ -0,0 +1,77 @@
// Type definitions for ngCordova device plugin
// Project: https://github.com/driftyco/ng-cordova
// Definitions by: Kapil Sachdeva <https://github.com/ksachdeva/DefinitelyTyped>
declare module ngCordova {
interface IDeviceInfo {
available:boolean;
platform:string;
version:string;
uuid:string;
cordova:string;
model:string;
manufacturer:string;
isVirtual:boolean;
serial:string;
}
interface IDeviceService {
/**
* Returns the whole device object.
* @see https://github.com/apache/cordova-plugin-device
* @returns {Object} The device object.
*/
getDevice():IDeviceInfo;
/**
* Returns the Cordova version.
* @see https://github.com/apache/cordova-plugin-device#devicecordova
* @returns {String} The Cordova version.
*/
getCordova():string;
/**
* Returns the name of the device's model or product.
* @see https://github.com/apache/cordova-plugin-device#devicemodel
* @returns {String} The name of the device's model or product.
*/
getModel():string;
/**
* @deprecated device.name is deprecated as of version 2.3.0. Use device.model instead.
* @returns {String}
*/
getName():string;
/**
* Returns the device's operating system name.
* @see https://github.com/apache/cordova-plugin-device#deviceplatform
* @returns {String} The device's operating system name.
*/
getPlatform():string;
/**
* Returns the device's Universally Unique Identifier.
* @see https://github.com/apache/cordova-plugin-device#deviceuuid
* @returns {String} The device's Universally Unique Identifier
*/
getUUID():string;
/**
* Returns the operating system version.
* @see https://github.com/apache/cordova-plugin-device#deviceversion
* @returns {String}
*/
getVersion():string;
/**
* Returns the device manufacturer.
* @returns {String}
*/
getManufacturer():string;
}
}
+51
View File
@@ -0,0 +1,51 @@
/// <reference path="toast.d.ts" />
/// <reference path="../angularjs/angular.d.ts" />
/// <reference path="../ionic/ionic.d.ts" />
// For the full application demo please see follow repo :
// https://github.com/ksachdeva/ngCordova-typescript-demo
namespace demo.toast {
'use strict';
export class ToastController {
toastMessage:string = 'enter a message';
msg:string;
static $inject:Array<string> = ["$cordovaToast"];
constructor(private $cordovaToast:ngCordova.IToastService) {
}
center() {
this.$cordovaToast.show(this.toastMessage, 'long', 'center')
.then((success) => {
console.log("center msg displayed");
}, (error) => {
this.msg = error.message;
});
}
top() {
this.$cordovaToast.showShortTop(this.toastMessage)
.then((success) => {
console.log("short top msg displayed");
}, (error) => {
this.msg = error.message;
});
}
bottom() {
this.$cordovaToast.showLongBottom(this.toastMessage)
.then((success) => {
console.log("long bottom msg displayed");
}, (error) => {
this.msg = error.message;
});
}
}
angular.module("demo.toast").controller("ToastController", ToastController);
}
+21
View File
@@ -0,0 +1,21 @@
// Type definitions for ngCordova toast plugin
// Project: https://github.com/driftyco/ng-cordova
// Definitions by: Kapil Sachdeva <https://github.com/ksachdeva/DefinitelyTyped>
/// <reference path="../angularjs/angular.d.ts" />
declare module ngCordova {
interface IToastService {
showShortTop(message:string):angular.IPromise<any>;
showShortCenter(message:string):angular.IPromise<any>;
showShortBottom(message:string):angular.IPromise<any>;
showLongTop(message:string):angular.IPromise<any>;
showLongCenter(message:string):angular.IPromise<any>;
showLongBottom(message:string):angular.IPromise<any>;
show(message:string, duration:string, position:string):angular.IPromise<any>;
}
}
+2
View File
@@ -0,0 +1,2 @@
/// <reference path="device.d.ts"/>
/// <reference path="toast.d.ts"/>