From 9ea072966d697b32eec28a760a610992b54b8bbe Mon Sep 17 00:00:00 2001 From: Joseph M Blank Date: Mon, 9 May 2016 08:01:48 -0700 Subject: [PATCH] Added definition for jQuery Steps. (#9230) * Added definition for jQuery Steps. * Renamed files to match npm naming. * Fixed reference in test file. --- jquery-steps/jquery-steps-tests.ts | 101 ++++++++ jquery-steps/jquery-steps.d.ts | 357 +++++++++++++++++++++++++++++ 2 files changed, 458 insertions(+) create mode 100644 jquery-steps/jquery-steps-tests.ts create mode 100644 jquery-steps/jquery-steps.d.ts diff --git a/jquery-steps/jquery-steps-tests.ts b/jquery-steps/jquery-steps-tests.ts new file mode 100644 index 0000000000..e0125a3c0f --- /dev/null +++ b/jquery-steps/jquery-steps-tests.ts @@ -0,0 +1,101 @@ +/// +/// + +var labels: JQuerySteps.LabelSettings = { + cancel: 'Cancel', + current: 'Current:', + pagination: 'Paging', + finish: 'Done', + next: 'Next >', + previous: '< Previous', + loading: 'Loading...' +} + +var onStepChangingFunc: JQuerySteps.FunctionOnStepChanging = (event, currentIndex, newIndex): boolean => true; + +var onStepChangedFunc: JQuerySteps.FunctionOnStepChanged = (event, currentIndex, priorIndex) => {}; + +var onCancelledFunc: JQuerySteps.FunctionOnCancelled = (event) => {}; + +var onFinishingFunc: JQuerySteps.FunctionOnFinishing= (event, currentIndex): boolean => true; + +var onFinishedFunc: JQuerySteps.FunctionOnFinished = (event, currentIndex) => {}; + +var onInitFunc: JQuerySteps.FunctionOnInit = (event, currentIndex) => {}; + +var onContentLoadedFunc: JQuerySteps.FunctionOnContentLoaded = (event, currentIndex) => {}; + +var settings: JQuerySteps.Settings = { + headerTag: 'h3', + bodyTag: 'section', + contentContainerTag: 'div', + actionContainerTag: 'div', + stepsContainerTag: 'div', + cssClass: 'wizard', + stepsOrientation: 'vertical', + titleTemplate: '#title#', + loadingTemplate: ' #text#', + autoFocus: true, + enableAllSteps: true, + enableKeyNavigation: false, + enablePagination: false, + suppressPaginationOnFocus: false, + enableContentCache: false, + enableCancelButton: true, + enableFinishButton: false, + showFinishButtonAlways: true, + forceMoveForward: true, + saveState: true, + startIndex: 1, + transitionEffect: 'slideLeft', + transitionEffectSpeed: 400, + labels: labels, + onCanceled: onCancelledFunc, + onContentLoaded: onContentLoadedFunc, + onFinished: onFinishedFunc, + onFinishing: onFinishingFunc, + onInit: onInitFunc, + onStepChanged: onStepChangedFunc, + onStepChanging: onStepChangingFunc +} + +var wizard = $('.wizard').JQuerySteps(settings); + +var newStep1: JQuerySteps.Step = { + content: '
Content
', + title: 'Step 1' +} + +var test1 = wizard.add(newStep1); + +var newStep2: JQuerySteps.Step = { + content: '
Content
', + title: 'Step 2', + contentMode: 'async', + contentUrl: 'data.xml' +} + +var test2 = wizard.insert(0, newStep2); + +var test3 = wizard.remove(1); + +var test4 = wizard.getCurrentStep(); + +var test5 = wizard.getCurrentIndex(); + +var test6 = wizard.getStep(0); + +var newStep3: JQuerySteps.Step = { + content: '
Content
', + title: 'Step 1' +} + +var test7 = wizard.insert(0, newStep3); + +var test8 = wizard.next(); + +var test9 = wizard.previous(); + +wizard.finish(); + +wizard.destroy(); diff --git a/jquery-steps/jquery-steps.d.ts b/jquery-steps/jquery-steps.d.ts new file mode 100644 index 0000000000..4b250e6708 --- /dev/null +++ b/jquery-steps/jquery-steps.d.ts @@ -0,0 +1,357 @@ +// Type definitions for jQuery Steps v1.1.0 +// Project: http://www.jquery-steps.com/ +// Definitions by: Joseph Blank +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface JQuery { + JQuerySteps(param?: JQuerySteps.Settings): JQuerySteps.JQuerySteps; +} + +declare module JQuerySteps { + + //#region "JQuerySteps" + + export interface JQuerySteps { + /** + * Adds a new step. (chainable) + */ + add(step: Step): JQuerySteps; + + /** + * Inserts a new step to a specific position. (chainable) + */ + insert(index: number, step: Step): JQuerySteps; + + /** + * Removes a specific step by an given index. + */ + remove(index: number): boolean; + + /** + * Gets the current step object. + */ + getCurrentStep(): Step; + + /** + * Gets the current step index. + */ + getCurrentIndex(): number; + + /** + * Gets a specific step object by index. + */ + getStep(index: number): Step; + + /** + * Routes to the previous step. + */ + next(): boolean; + + /** + * Routes to the next step. + */ + previous(): boolean; + + /** + * Triggers the onFinishing and onFinished event. + */ + finish(): void; + + /** + * Removes the control functionality completely and transforms the current state to the initial HTML structure. + */ + destroy(): void; + + /** + * Skips a certain amount of steps. Not yet implemented! + */ + skip(count: number): boolean; + } + + //#endregion "JQuerySteps" + + //#region "Settings" + export interface Settings { + //#region "Appearance" + + /** + * The header tag is used to find the step button text within the declared wizard area. Default value is h1. + */ + headerTag?: string; + + /** + * The body tag is used to find the step content within the declared wizard area. Default value is div. + */ + bodyTag?: string; + + /** + * The content container tag which will be used to wrap all step contents. Default value is div. + */ + contentContainerTag?: string; + + /** + * The action container tag which will be used to wrap the pagination navigation. Default value is div. + */ + actionContainerTag?: string; + + /** + * The steps container tag which will be used to wrap the steps navigation. Default value is div. + */ + stepsContainerTag?: string; + + /** + * The css class which will be added to the outer component wrapper. Default value is wizard. + */ + cssClass?: string; + + /** + * Determines whether the steps are vertically or horizontally oriented. Default value is horizontal or 0. + * This can be horizontal (0) or vertical (1). + */ + stepsOrientation?: string|number; + + //#endregion "Appearance" + + //#region "Templates" + + /** + * The title template which will be used to create a step button. Default value is span class="number">#index#. #title#. + */ + titleTemplate?: string; + + /** + * The loading template which will be used to create the loading animation. Default value is #text#. + */ + loadingTemplate?: string; + + //#endregion "Templates" + + //#region "Behavior" + + /** + * Sets the focus to the first wizard instance in order to enable the key navigation from the begining if true. Default value is false. + */ + autoFocus?: boolean; + + /** + * Enables all steps from the begining if true (all steps are clickable). Default value is false. + */ + enableAllSteps?: boolean; + + /** + * Enables keyboard navigation if true (arrow left and arrow right). Default value is true. + */ + enableKeyNavigation?: boolean; + + /** + * Enables pagination (next, previous and finish button) if true. Default value is true. + */ + enablePagination?: boolean; + + /** + * Suppresses pagination if a form field is focused. Default value is true. + */ + suppressPaginationOnFocus?: boolean; + + /** + * Enables cache for async loaded or iframe embedded content. Default value is true. + */ + enableContentCache?: boolean; + + /** + * Shows the cancel button if enabled. Default value is false. + */ + enableCancelButton?: boolean; + + /** + * Shows the finish button if enabled. Default value is true. + */ + enableFinishButton?: boolean; + + /** + * Shows the finish button always (on each step; right beside the next button) if true. Otherwise the next button will be replaced by the finish button if the last step becomes active. Default value is false. + */ + showFinishButtonAlways?: boolean; + + /** + * Prevents jumping to a previous step. Default value is false. + */ + forceMoveForward?: boolean; + + /** + * Saves the current state (step position) to a cookie. By coming next time the last active step becomes activated. Default value is false. + */ + saveState?: boolean; + + /** + * The position to start on (zero-based). Default value is 0. + */ + startIndex?: number; + + //#endregion "Behavior" + + //#region "Transition Effects" + + /** + * The animation effect which will be used for step transitions. Default value is none or 0. + * This can be none (0), fade (1), slide (2) or slideLeft (3). + */ + transitionEffect?: string|number; + + /** + * Animation speed for step transitions (in milliseconds). Default value is 200. + */ + transitionEffectSpeed?: number; + + //#endregion "Transition Effects" + + //#region "Events" + + /** + * Fires before the step changes and can be used to prevent step changing by returning false. + */ + onStepChanging?: FunctionOnStepChanging; + + /** + * Fires after the step has changed. + */ + onStepChanged?: FunctionOnStepChanged; + + /** + * Fires after cancellation. + */ + onCanceled?: FunctionOnCancelled; + + /** + * Fires before finishing and can be used to prevent completion by returning false. Very useful for form validation. + */ + onFinishing?: FunctionOnFinishing; + + /** + * Fires after completion. + */ + onFinished?: FunctionOnFinished; + + /** + * Fires when the wizard is initialized. + */ + onInit?: FunctionOnInit; + + /** + * Fires after async content is loaded. + */ + onContentLoaded?: FunctionOnContentLoaded; + + //#endregion "Events" + + //#region "Labels" + + labels?: LabelSettings; + + //#endregion "Labels" + } + //#endregion "Settings" + + //#region "Label Settings" + + interface LabelSettings { + + /** + * Label for the cancel button. Default value is Cancel. + */ + cancel?: string; + + /** + * This label is important for accessability reasons. Indicates which step is activated. Default value is current step:. + */ + current?: string; + + /** + * This label is important for accessability reasons and describes the kind of navigation. Default value is Pagination. + */ + pagination?: string; + + /** + * Label for the finish button. Default value is Finish. + */ + finish?: string; + + /** + * Label for the next button. Default value is Next. + */ + next?: string; + + /** + * Label for the previous button. Default value is Previous. + */ + previous?: string; + + /** + * Label for the loading animation. Default value is Loading ... . + */ + loading?: string; + + } + + //#endregion "Label Settings" + + //#region "Callback Functions" + + interface FunctionOnStepChanging { + (event: string, currentIndex: number, newIndex: number): boolean; + } + + interface FunctionOnStepChanged { + (event: string, currentIndex: number, priorIndex: number): void; + } + + interface FunctionOnCancelled { + (event: string): void; + } + + interface FunctionOnFinishing { + (event: string, currentIndex: number): boolean; + } + + interface FunctionOnFinished { + (event: string, currentIndex: number): void; + } + + interface FunctionOnInit { + (event: string, currentIndex: number): void; + } + + interface FunctionOnContentLoaded { + (event: string, currentIndex: number): void; + } + + //#endregion "Callback Functions" + + //#region "Step Object" + + interface Step { + + /** + * The step title (HTML). + */ + title?: string; + + /** + * The step content (HTML). + */ + content?: string; + + /** + * Indicates how the content will be loaded. + * This can be html (0), iframe (1), or async (2). + */ + contentMode?: string|number; + + /** + * The URI that refers to the content. + */ + contentUrl?: string; + } + + //#endregion "Step Object" +}