diff --git a/angular-media-queries/match-media-tests.ts b/angular-media-queries/match-media-tests.ts new file mode 100644 index 0000000000..a9331751ae --- /dev/null +++ b/angular-media-queries/match-media-tests.ts @@ -0,0 +1,60 @@ +/// + +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); +}); \ 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..401c61f46c --- /dev/null +++ b/angular-media-queries/match-media.d.ts @@ -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 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +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. + // 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