Merge pull request #8759 from jpmnteiro/master

Created typings for angular-match-queries module
This commit is contained in:
Masahiro Wakame
2016-03-31 01:04:03 +09:00
2 changed files with 90 additions and 0 deletions
@@ -0,0 +1,60 @@
/// <reference path="match-media.d.ts" />
var myApp = angular.module('testModule', ['matchMedia']);
myApp.controller('TestController', ($log: angular.ILogService,
$scope: angular.IScope,
screenSize: angular.matchmedia.IScreenSize) => {
var fnCallback = (result: boolean) => {
$log.info(`Result: ${result}`);
}
// '.isRetina' examples
if(screenSize.isRetina) {
$log.info("Retina screen detected")
}
// '.is(...)' examples
var res = screenSize.is(["xs", "sm"]);
fnCallback(res);
res = screenSize.is("xs, lg")
fnCallback(res);
// '.on(...)' examples
res = screenSize.on(["xs", "sm"], fnCallback);
fnCallback(res);
res = screenSize.on("xs, lg", fnCallback);
fnCallback(res);
res = screenSize.on(["xs", "sm"], fnCallback, $scope);
fnCallback(res);
res = screenSize.on("xs, lg", fnCallback, $scope);
fnCallback(res);
// '.onChange(...)' examples
res = screenSize.onChange($scope, ["xs", "sm"], fnCallback);
fnCallback(res);
res = screenSize.onChange($scope, "xs, lg", fnCallback);
fnCallback(res);
// '.when(...)' examples
res = screenSize.when(["xs", "sm"], fnCallback);
fnCallback(res);
res = screenSize.when("xs, lg", fnCallback);
fnCallback(res);
res = screenSize.when(["xs", "sm"], fnCallback, $scope);
fnCallback(res);
res = screenSize.when("xs, lg", fnCallback, $scope);
fnCallback(res);
});
+30
View File
@@ -0,0 +1,30 @@
// Type definitions for Angular matchMedia 0.6.0 (angular.matchMedia module)
// Project: https://github.com/jacopotarantino/angular-match-media
// Definitions by: Joao Monteiro <https://github.com/jpmnteiro>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../angularjs/angular.d.ts" />
declare namespace angular.matchmedia {
interface IScreenSize {
// Returns a value indicating if the current device has a retina screen
isRetina: boolean;
is(list: Array<string> | string): boolean;
// Executes the callback function on window resize with the match truthiness as the first argument.
// Returns the current match truthiness.
// The 'scope' parameter is optional. If it's not passed in, '$rootScope' is used.
on(list: Array<string> | string, callback: (result: boolean) => void, scope?: angular.IScope): boolean;
// Executes the callback function ONLY when the match differs from previous match.
// Returns the current match truthiness.
// The 'scope' parameter is required for cleanup reasons (destroy event).
onChange(scope: angular.IScope, list: Array<string> | string, callback: (result: boolean) => void): boolean;
// Executes the callback only when inside of the particular screensize.
// The 'scope' parameter is optional. If it's not passed in, '$rootScope' is used.
when(list: Array<string> | string, callback: (result: boolean) => void, scope?: angular.IScope): boolean;
}
}