From 8527f0915ccb0f403b6c49a331410492d1dd6026 Mon Sep 17 00:00:00 2001 From: jpmnteiro Date: Tue, 29 Mar 2016 13:20:38 +0100 Subject: [PATCH 1/2] created typings for angular-media-queries module --- angular-media-queries/match-media-tests.ts | 55 ++++++++++++++++++++++ angular-media-queries/match-media.d.ts | 27 +++++++++++ 2 files changed, 82 insertions(+) create mode 100644 angular-media-queries/match-media-tests.ts create mode 100644 angular-media-queries/match-media.d.ts diff --git a/angular-media-queries/match-media-tests.ts b/angular-media-queries/match-media-tests.ts new file mode 100644 index 0000000000..8b87dedb72 --- /dev/null +++ b/angular-media-queries/match-media-tests.ts @@ -0,0 +1,55 @@ +/// + +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}`); + } + + // '.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); +}); \ No newline at end of file diff --git a/angular-media-queries/match-media.d.ts b/angular-media-queries/match-media.d.ts new file mode 100644 index 0000000000..7e43160699 --- /dev/null +++ b/angular-media-queries/match-media.d.ts @@ -0,0 +1,27 @@ +// Type definitions for Angular matchMedia 0.6.0 (angular.matchMedia module) +// Project: https://github.com/jacopotarantino/angular-match-media +// Definitions by: Joao Monteiro +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +declare namespace angular.matchmedia { + + interface IScreenSize { + + is(list: Array | 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, 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, 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, callback: (result: boolean) => void, scope?: angular.IScope): boolean; + } +} \ No newline at end of file From 1604efc1659d9f3dfacd95e3779be4c5e16ca927 Mon Sep 17 00:00:00 2001 From: jpmnteiro Date: Tue, 29 Mar 2016 13:54:48 +0100 Subject: [PATCH 2/2] added missing `.isRetina` property --- angular-media-queries/match-media-tests.ts | 5 +++++ angular-media-queries/match-media.d.ts | 3 +++ 2 files changed, 8 insertions(+) diff --git a/angular-media-queries/match-media-tests.ts b/angular-media-queries/match-media-tests.ts index 8b87dedb72..a9331751ae 100644 --- a/angular-media-queries/match-media-tests.ts +++ b/angular-media-queries/match-media-tests.ts @@ -10,6 +10,11 @@ myApp.controller('TestController', ($log: angular.ILogService, $log.info(`Result: ${result}`); } + // '.isRetina' examples + if(screenSize.isRetina) { + $log.info("Retina screen detected") + } + // '.is(...)' examples var res = screenSize.is(["xs", "sm"]); fnCallback(res); diff --git a/angular-media-queries/match-media.d.ts b/angular-media-queries/match-media.d.ts index 7e43160699..401c61f46c 100644 --- a/angular-media-queries/match-media.d.ts +++ b/angular-media-queries/match-media.d.ts @@ -8,6 +8,9 @@ declare namespace angular.matchmedia { interface IScreenSize { + // Returns a value indicating if the current device has a retina screen + isRetina: boolean; + is(list: Array | string): boolean; // Executes the callback function on window resize with the match truthiness as the first argument.