From 195fcbd17ca0da06489e836ed28d4875d02f0bb4 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Mon, 12 Jan 2015 22:55:34 -0600 Subject: [PATCH] Adding Definitions for Ladda jQuery Plugin 0.9.4 --- ladda/ladda-tests.ts | 27 +++++++++++++++++++++++++++ ladda/ladda.d.ts | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/ladda/ladda-tests.ts b/ladda/ladda-tests.ts index 710407de60..745032ea1f 100644 --- a/ladda/ladda-tests.ts +++ b/ladda/ladda-tests.ts @@ -48,3 +48,30 @@ laddaBtn.start().stop().toggle().setProgress(42).enable().disable().start(); // Test isLoading console.assert(laddaBtn.isLoading() === true); + +//Test jQuery plugin Support +// Automatically trigger the loading animation on click +$('input[type=submit]').ladda('bind'); + +// Same as the above but automatically stops after two seconds +$('input[type=submit]').ladda('bind', { timeout: 2000 }); + +// Create a new instance of ladda for the specified button +var ljq = $('.my-button').ladda(); + +// Start loading +ljq.ladda('start'); + +// Will display a progress bar for 50% of the button width +ljq.ladda('setProgress', 0.5); + +// Stop loading +ljq.ladda('stop'); + +// Toggle between loading/not loading states +ljq.ladda('toggle'); + +// Check the current state +ljq.ladda('isLoading'); + +$.ladda('stopAll'); \ No newline at end of file diff --git a/ladda/ladda.d.ts b/ladda/ladda.d.ts index b464a31c50..0d510378b6 100644 --- a/ladda/ladda.d.ts +++ b/ladda/ladda.d.ts @@ -1,8 +1,10 @@ // Type definitions for Ladda 0.9.4 // Project: https://github.com/hakimel/Ladda -// Definitions by: Danil Flores +// Definitions by: Danil Flores , Michael Lee // Definitions: https://github.com/borisyankov/DefinitelyTyped +/// + interface ILaddaButton { start(): ILaddaButton; startAfter(delay: number): ILaddaButton @@ -34,3 +36,32 @@ declare var Ladda: ILadda; declare module "ladda" { export = Ladda; } + + +interface JQuery { + /** + * Creates a new instance of ladda for the selected button + */ + ladda(): JQuery; + + /** + * The action controls or checks the state of the ladda button. + * Possible actions are 'start', 'stop', 'toggle', 'stopAll' + * Possible check 'isLoading' + */ + ladda(action: string): JQuery; + + /** + * When the action is 'setProgress' you can pass a number between + * 0 and 1 for the options to represent the progress. For example .5 would be 50% + * When the action is 'bind' you can pass an object with a property + * called timeout with the timeout value in milliseconds. + * For example { timeout: 2000 } + */ + ladda(action: string, options: any): JQuery; +} + + +interface JQueryStatic { + ladda(action: string): JQuery; +}