From 21334d2ae1046dbed8a15a3ea5b45c6cbe65db81 Mon Sep 17 00:00:00 2001 From: Stephan Classen Date: Wed, 5 Apr 2017 11:55:39 +0200 Subject: [PATCH] add types for angular-block-ui --- .../angular-block-ui-tests.ts | 41 +++++ types/angular-block-ui/index.d.ts | 171 ++++++++++++++++++ types/angular-block-ui/tsconfig.json | 23 +++ types/angular-block-ui/tslint.json | 1 + 4 files changed, 236 insertions(+) create mode 100644 types/angular-block-ui/angular-block-ui-tests.ts create mode 100644 types/angular-block-ui/index.d.ts create mode 100644 types/angular-block-ui/tsconfig.json create mode 100644 types/angular-block-ui/tslint.json diff --git a/types/angular-block-ui/angular-block-ui-tests.ts b/types/angular-block-ui/angular-block-ui-tests.ts new file mode 100644 index 0000000000..c3c69345c9 --- /dev/null +++ b/types/angular-block-ui/angular-block-ui-tests.ts @@ -0,0 +1,41 @@ +var app: angular.IModule = angular.module('at', ['blockUI']); + +app.config((blockUIConfig: angular.blockUI.IBlockUIConfig) => { + blockUIConfig.message = 'Please stop clicking!'; + blockUIConfig.delay = 100; + blockUIConfig.template = '
{{ state | json }}
'; + blockUIConfig.templateUrl = 'my-templates/block-ui-overlay.html'; + blockUIConfig.autoBlock = false; + blockUIConfig.resetOnException = false; + blockUIConfig.autoInjectBodyBlock = false; + blockUIConfig.cssClass = 'block-ui my-custom-class'; + blockUIConfig.blockBrowserNavigation = true; + + blockUIConfig.requestFilter = function (config) { + if (config.url.match(/^\/api\/quote($|\/).*/)) { + return false; + } + return true; + }; + + blockUIConfig.requestFilter = function (config) { + if (config.url.match(/^\/api\/quote($|\/).*/)) { + return 'Hello World'; + } + return 'Loading...'; + }; +}); + +app.controller('Ctrl', ($scope: ng.IScope, blockUI: angular.blockUI.IBlockUIService) => { + blockUI.start(); + blockUI.start('Hello'); + blockUI.start({}); + blockUI.start({message: 'World'}); + blockUI.start({delay: 100}); + + blockUI.stop(); + blockUI.reset(); + blockUI.message("Hello Types"); + blockUI.done(); + let b: boolean = blockUI.isBlocking(); +}); diff --git a/types/angular-block-ui/index.d.ts b/types/angular-block-ui/index.d.ts new file mode 100644 index 0000000000..4e67dbcb52 --- /dev/null +++ b/types/angular-block-ui/index.d.ts @@ -0,0 +1,171 @@ +// Type definitions for angular-block-ui v0.2.2 +// Project: https://github.com/McNull/angular-block-ui +// Definitions by: Lasse Nørregaard , Stephan Classen +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import * as angular from 'angular'; + +declare module 'angular' { + export namespace blockUI { + + interface IBlockUIConfig { + /** + * Changes the default message to be used when no message + * has been provided to the start method of the service. + * + * Default value is 'Loading ...'. + */ + message?: string; + + /** + * Specifies the amount in milliseconds before the block + * is visible to the user. By delaying a visible block your + * application will appear more responsive. + * + * The default value is 250. + */ + delay?: number; + + /** + * Specifies a custom template to use as the overlay. + */ + template?: string; + + /** + * Specifies a url to retrieve the template from. + * The current release only works with pre-cached templates, + * which means that this url should be known in the + * $templateCache service of Angular. + * + * If you're using the grunt with html2js or angular-templates, + * which I highly recommend, you're already set. + */ + templateUrl?: string; + + /** + * By default the BlockUI module will start a block whenever + * the Angular $http service has an pending request. + * + * If you don't want this behaviour and want to do all the + * blocking manually you can change this value to false. + */ + autoBlock?: boolean; + + /** + * By default the BlockUI module will reset the block count and + * hide the overlay whenever an exception has occurred. + * + * You can set this value to false if you don't want this behaviour. + */ + resetOnException?: boolean; + + /** + * Allows you to specify a filter function to exclude certain ajax + * requests from blocking the user interface. + * The blockUI service will ignore requests when the function returns `false`. + * + * If the filter function returns a string it will be passed as the message + * argument to the start method of the service. + * + * @param {angular.IRequestConfig} config - the Angular request config object. + * + */ + requestFilter?: (config: angular.IRequestConfig) => (string | boolean); + + /** + * When the module is started it will inject the main block element + * by adding the block-ui directive to the body element. + */ + autoInjectBodyBlock?: boolean; + + /** + * A string containing the default css classes, separated by spaces, + * that should be applied to each block-ui element. + * + * The default value is `block-ui block-ui-anim-fade` + */ + cssClass?: string; + + /** + * Whenever a user interface block is active, because the single page + * application is still waiting for a response from the backend server, + * the user can still navigate away using the back and forward buttons + * of the browser. + * + * Callbacks registered to handle the responses from the server will + * be executed even if a different view/controller is currently active. + * By setting the blockBrowserNavigation property to true the + * angular-block-ui module will prevent navigation while a fullscreen + * block is active. + * + * Programatic location changes via the $location service are still + * allowed however. + * The navigation block is disabled by default. + */ + blockBrowserNavigation?: boolean; + } + + interface IBlockUIService { + /** + * The start method will start the user interface block. + * Because multiple user interface elements can request + * a user interface block at the same time, the service + * keeps track of the number of start calls. + * + * Each call to start() will increase the count and every + * call to stop() will decrease the value. + * Whenever the count reaches 0 the block will end. + * + * Note: By default the block is immediately active after + * calling this method, but to prevent trashing the user + * interface each time a button is pressed, the block is + * visible after a short delay. + * + * This behaviour can be modified in the configuration. + * + * @param {string|IBlockUIConfig} messageOrOptions - + * Either supply the message (string) to be show in the + * overlay or specify an IBlockUIConfig object that will be + * merged/extended into the block ui instance state. + * If no argument is specified the default text message + * from the configuration is used. + */ + start: (messageOrOptions?: (string | IBlockUIConfig)) => void; + + /** + * This will decrease the block count. + * + * The block will end if the count is 0. + */ + stop: () => void; + + /** + * The reset will force an unblock by setting the block count to 0. + */ + reset: () => void; + + /** + * Queues a callback function to be called when the block has finished. + * + * This can be useful whenever you wish to redirect the user + * to a different location while there are still pending AJAX requests. + */ + done: () => void; + + /** + * Allows the message shown in the overlay to be updated + * while to block is active. + * + * @param {string} message - The message to show in the overlay. + */ + message: (message: string) => void; + + /** + * Returns whether currently a block is shown for the instance or not. + */ + isBlocking: () => boolean; + } + } +} diff --git a/types/angular-block-ui/tsconfig.json b/types/angular-block-ui/tsconfig.json new file mode 100644 index 0000000000..b1b705a6e5 --- /dev/null +++ b/types/angular-block-ui/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "angular-block-ui-tests.ts" + ] +} diff --git a/types/angular-block-ui/tslint.json b/types/angular-block-ui/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/types/angular-block-ui/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }