From 502b45cf1534228e1e1033393b833900788d5e69 Mon Sep 17 00:00:00 2001 From: Bohdan Stupak Date: Sat, 2 Jun 2018 20:36:23 +0300 Subject: [PATCH 1/2] Add types to jquery.nicescroll --- types/jquery.nicescroll/index.d.ts | 105 ++++++++++++++++++ .../jquery.nicescroll-tests.ts | 41 +++++++ types/jquery.nicescroll/tsconfig.json | 24 ++++ types/jquery.nicescroll/tslint.json | 3 + 4 files changed, 173 insertions(+) create mode 100644 types/jquery.nicescroll/index.d.ts create mode 100644 types/jquery.nicescroll/jquery.nicescroll-tests.ts create mode 100644 types/jquery.nicescroll/tsconfig.json create mode 100644 types/jquery.nicescroll/tslint.json diff --git a/types/jquery.nicescroll/index.d.ts b/types/jquery.nicescroll/index.d.ts new file mode 100644 index 0000000000..1b5b714cb8 --- /dev/null +++ b/types/jquery.nicescroll/index.d.ts @@ -0,0 +1,105 @@ +// Type definitions for jquery.nicescroll 3.7.6 +// Project: https://nicescroll.areaaperta.com +// Definitions by: Bohdan Stupak +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +/// + +declare namespace JQueryNiceScroll { + interface NiceScrollPage { + maxw: number + maxh: number + width: number + height: number + w: number + h: number + } + + interface NiceScroll { + show(): NiceScroll + hide(): NiceScroll + toggle(): NiceScroll + onResize(e?: Event, page?: NiceScrollPage): NiceScroll + resize(e?: Event, page?: NiceScrollPage): NiceScroll + remove(): void + stop(): NiceScroll + doScrollPos(x: number, y: number, spd: number): void + doScrollLeft(x: number, duration: number): void + doScrollTop(x: number, duration: number): void + } + + interface NiceScrollOptions { + zindex?: "auto" | number + cursoropacitymin?: number + cursoropacitymax?: number + cursorcolor?: string + cursorwidth?: string + cursorborder?: string + cursorborderradius?: string + scrollspeed?: number + mousescrollstep?: number + touchbehavior?: boolean + emulatetouch?: boolean + hwacceleration?: boolean + usetransition?: boolean + boxzoom?: boolean + dblclickzoom?: boolean + gesturezoom?: boolean + grabcursorenabled?: boolean + autohidemode?: "leave" | "scroll" | "cursor" | "hidden" | boolean + background?: string + iframeautoresize?: boolean + cursorminheight?: number + preservenativescrolling?: boolean + railoffset?: boolean | { + top?: number + left?: number + } + railhoffset?: boolean | { + top?: number + left?: number + } + bouncescroll?: boolean + spacebarenabled?: boolean + railpadding?: { + top: number + right: number + left: number + bottom: number + } + disableoutline?: boolean + horizrailenabled?: boolean + railalign?: "right" | "left" | "top" | "bottom" + railvalign?: "right" | "left" | "top" | "bottom" + enabletranslate3d?: boolean + enablemousewheel?: boolean + enablekeyboard?: boolean + smoothscroll?: boolean + sensitiverail?: boolean + enablemouselockapi?: boolean + cursorfixedheight?: number + directionlockdeadzone?: number + hidecursordelay?: number + nativeparentscrolling?: boolean + enablescrollonselection?: boolean + overflowx?: "auto" | "hidden" | "inherit" | "initial" | "overlay" | "scroll" | "unset" | "visible" + overflowy?: "auto" | "hidden" | "inherit" | "initial" | "overlay" | "scroll" | "unset" | "visible" + cursordragspeed?: number + rtlmode?: "auto" | boolean + cursordragontouch?: boolean + oneaxismousemode?: "auto" | boolean + scriptpath?: string + preventmultitouchscrolling?: boolean + disablemutationobserver?: boolean + enableobserver?: boolean + scrollbarid?: string + scrollCLass?: string + } +} + +interface JQuery { + niceScroll(options?: JQueryNiceScroll.NiceScrollOptions) : JQueryNiceScroll.NiceScroll; + niceScroll(wrapper: string, options: JQueryNiceScroll.NiceScrollOptions) : JQueryNiceScroll.NiceScroll; + getNiceScroll(index?: number) : JQueryNiceScroll.NiceScroll; +} \ No newline at end of file diff --git a/types/jquery.nicescroll/jquery.nicescroll-tests.ts b/types/jquery.nicescroll/jquery.nicescroll-tests.ts new file mode 100644 index 0000000000..2d4599d8d6 --- /dev/null +++ b/types/jquery.nicescroll/jquery.nicescroll-tests.ts @@ -0,0 +1,41 @@ +//cases from documentation +// 1. Simple mode, it styles document scrollbar: +$(function() { + $("body").niceScroll(); +}); + +// 2. Instance with object returned: +let nice; +$(function() { + nice = $("body").niceScroll(); +}); + +// 3. Style a DIV and change cursor color: +$(function() { + $("#thisdiv").niceScroll({cursorcolor:"#00F"}); +}); + +// 4. DIV with "wrapper", formed by two divs, the first is the vieport, the latter is the content: +$(function() { + $("#viewportdiv").niceScroll("#wrapperdiv",{cursorcolor:"#00F"}); +}); + +// 5. Get nicescroll object: +nice = $("#mydiv").getNiceScroll(); + +// 6. Hide scrollbars: +$("#mydiv").getNiceScroll().hide(); + +// 7. Check for scrollbars resize (when content or position have changed): +$("#mydiv").getNiceScroll().resize(); + +// 8. Scrolling to a position: +$("#mydiv").getNiceScroll(0).doScrollLeft(1, 2); // Scroll X Axis +$("#mydiv").getNiceScroll(0).doScrollTop(1, 14); // Scroll Y Axis + +//other cases +$(".ui-grid-viewport").niceScroll({ + cursorcolor: "#fff", + cursorwidth: "8px", + autohidemode: "leave" +}); \ No newline at end of file diff --git a/types/jquery.nicescroll/tsconfig.json b/types/jquery.nicescroll/tsconfig.json new file mode 100644 index 0000000000..a5d8cb44a3 --- /dev/null +++ b/types/jquery.nicescroll/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "jquery.nicescroll-tests.ts" + ] +} \ No newline at end of file diff --git a/types/jquery.nicescroll/tslint.json b/types/jquery.nicescroll/tslint.json new file mode 100644 index 0000000000..8bc7a53d89 --- /dev/null +++ b/types/jquery.nicescroll/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json", +} From 7f45ca974743972bfcf521ed51fc4c4a9a7dcb0d Mon Sep 17 00:00:00 2001 From: Bohdan Stupak Date: Sat, 2 Jun 2018 22:11:27 +0300 Subject: [PATCH 2/2] Fixing tslint errors --- types/jquery.nicescroll/index.d.ts | 172 +++++++++--------- .../jquery.nicescroll-tests.ts | 18 +- types/jquery.nicescroll/tsconfig.json | 2 +- types/jquery.nicescroll/tslint.json | 4 +- 4 files changed, 98 insertions(+), 98 deletions(-) diff --git a/types/jquery.nicescroll/index.d.ts b/types/jquery.nicescroll/index.d.ts index 1b5b714cb8..8228ae5209 100644 --- a/types/jquery.nicescroll/index.d.ts +++ b/types/jquery.nicescroll/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for jquery.nicescroll 3.7.6 +// Type definitions for jquery.nicescroll 3.7 // Project: https://nicescroll.areaaperta.com // Definitions by: Bohdan Stupak // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -8,98 +8,98 @@ declare namespace JQueryNiceScroll { interface NiceScrollPage { - maxw: number - maxh: number - width: number - height: number - w: number - h: number + maxw: number; + maxh: number; + width: number; + height: number; + w: number; + h: number; } - + interface NiceScroll { - show(): NiceScroll - hide(): NiceScroll - toggle(): NiceScroll - onResize(e?: Event, page?: NiceScrollPage): NiceScroll - resize(e?: Event, page?: NiceScrollPage): NiceScroll - remove(): void - stop(): NiceScroll - doScrollPos(x: number, y: number, spd: number): void - doScrollLeft(x: number, duration: number): void - doScrollTop(x: number, duration: number): void + show(): NiceScroll; + hide(): NiceScroll; + toggle(): NiceScroll; + onResize(e?: Event, page?: NiceScrollPage): NiceScroll; + resize(e?: Event, page?: NiceScrollPage): NiceScroll; + remove(): void; + stop(): NiceScroll; + doScrollPos(x: number, y: number, spd: number): void; + doScrollLeft(x: number, duration: number): void; + doScrollTop(x: number, duration: number): void; } - + interface NiceScrollOptions { - zindex?: "auto" | number - cursoropacitymin?: number - cursoropacitymax?: number - cursorcolor?: string - cursorwidth?: string - cursorborder?: string - cursorborderradius?: string - scrollspeed?: number - mousescrollstep?: number - touchbehavior?: boolean - emulatetouch?: boolean - hwacceleration?: boolean - usetransition?: boolean - boxzoom?: boolean - dblclickzoom?: boolean - gesturezoom?: boolean - grabcursorenabled?: boolean - autohidemode?: "leave" | "scroll" | "cursor" | "hidden" | boolean - background?: string - iframeautoresize?: boolean - cursorminheight?: number - preservenativescrolling?: boolean + zindex?: "auto" | number; + cursoropacitymin?: number; + cursoropacitymax?: number; + cursorcolor?: string; + cursorwidth?: string; + cursorborder?: string; + cursorborderradius?: string; + scrollspeed?: number; + mousescrollstep?: number; + touchbehavior?: boolean; + emulatetouch?: boolean; + hwacceleration?: boolean; + usetransition?: boolean; + boxzoom?: boolean; + dblclickzoom?: boolean; + gesturezoom?: boolean; + grabcursorenabled?: boolean; + autohidemode?: "leave" | "scroll" | "cursor" | "hidden" | boolean; + background?: string; + iframeautoresize?: boolean; + cursorminheight?: number; + preservenativescrolling?: boolean; railoffset?: boolean | { - top?: number - left?: number - } + top?: number; + left?: number; + }; railhoffset?: boolean | { - top?: number - left?: number - } - bouncescroll?: boolean - spacebarenabled?: boolean + top?: number; + left?: number; + }; + bouncescroll?: boolean; + spacebarenabled?: boolean; railpadding?: { - top: number - right: number - left: number - bottom: number - } - disableoutline?: boolean - horizrailenabled?: boolean - railalign?: "right" | "left" | "top" | "bottom" - railvalign?: "right" | "left" | "top" | "bottom" - enabletranslate3d?: boolean - enablemousewheel?: boolean - enablekeyboard?: boolean - smoothscroll?: boolean - sensitiverail?: boolean - enablemouselockapi?: boolean - cursorfixedheight?: number - directionlockdeadzone?: number - hidecursordelay?: number - nativeparentscrolling?: boolean - enablescrollonselection?: boolean - overflowx?: "auto" | "hidden" | "inherit" | "initial" | "overlay" | "scroll" | "unset" | "visible" - overflowy?: "auto" | "hidden" | "inherit" | "initial" | "overlay" | "scroll" | "unset" | "visible" - cursordragspeed?: number - rtlmode?: "auto" | boolean - cursordragontouch?: boolean - oneaxismousemode?: "auto" | boolean - scriptpath?: string - preventmultitouchscrolling?: boolean - disablemutationobserver?: boolean - enableobserver?: boolean - scrollbarid?: string - scrollCLass?: string - } + top: number; + right: number; + left: number; + bottom: number; + }; + disableoutline?: boolean; + horizrailenabled?: boolean; + railalign?: "right" | "left" | "top" | "bottom"; + railvalign?: "right" | "left" | "top" | "bottom"; + enabletranslate3d?: boolean; + enablemousewheel?: boolean; + enablekeyboard?: boolean; + smoothscroll?: boolean; + sensitiverail?: boolean; + enablemouselockapi?: boolean; + cursorfixedheight?: number; + directionlockdeadzone?: number; + hidecursordelay?: number; + nativeparentscrolling?: boolean; + enablescrollonselection?: boolean; + overflowx?: "auto" | "hidden" | "inherit" | "initial" | "overlay" | "scroll" | "unset" | "visible"; + overflowy?: "auto" | "hidden" | "inherit" | "initial" | "overlay" | "scroll" | "unset" | "visible"; + cursordragspeed?: number; + rtlmode?: "auto" | boolean; + cursordragontouch?: boolean; + oneaxismousemode?: "auto" | boolean; + scriptpath?: string; + preventmultitouchscrolling?: boolean; + disablemutationobserver?: boolean; + enableobserver?: boolean; + scrollbarid?: string; + scrollCLass?: string; + } } interface JQuery { - niceScroll(options?: JQueryNiceScroll.NiceScrollOptions) : JQueryNiceScroll.NiceScroll; - niceScroll(wrapper: string, options: JQueryNiceScroll.NiceScrollOptions) : JQueryNiceScroll.NiceScroll; - getNiceScroll(index?: number) : JQueryNiceScroll.NiceScroll; -} \ No newline at end of file + niceScroll(options?: JQueryNiceScroll.NiceScrollOptions): JQueryNiceScroll.NiceScroll; + niceScroll(wrapper: string, options: JQueryNiceScroll.NiceScrollOptions): JQueryNiceScroll.NiceScroll; + getNiceScroll(index?: number): JQueryNiceScroll.NiceScroll; +} diff --git a/types/jquery.nicescroll/jquery.nicescroll-tests.ts b/types/jquery.nicescroll/jquery.nicescroll-tests.ts index 2d4599d8d6..f4362530f9 100644 --- a/types/jquery.nicescroll/jquery.nicescroll-tests.ts +++ b/types/jquery.nicescroll/jquery.nicescroll-tests.ts @@ -1,23 +1,23 @@ -//cases from documentation +// cases from documentation // 1. Simple mode, it styles document scrollbar: -$(function() { +$(() => { $("body").niceScroll(); }); // 2. Instance with object returned: let nice; -$(function() { +$(() => { nice = $("body").niceScroll(); }); // 3. Style a DIV and change cursor color: -$(function() { - $("#thisdiv").niceScroll({cursorcolor:"#00F"}); +$(() => { + $("#thisdiv").niceScroll({cursorcolor: "#00F"}); }); // 4. DIV with "wrapper", formed by two divs, the first is the vieport, the latter is the content: -$(function() { - $("#viewportdiv").niceScroll("#wrapperdiv",{cursorcolor:"#00F"}); +$(() => { + $("#viewportdiv").niceScroll("#wrapperdiv", {cursorcolor: "#00F"}); }); // 5. Get nicescroll object: @@ -33,9 +33,9 @@ $("#mydiv").getNiceScroll().resize(); $("#mydiv").getNiceScroll(0).doScrollLeft(1, 2); // Scroll X Axis $("#mydiv").getNiceScroll(0).doScrollTop(1, 14); // Scroll Y Axis -//other cases +// other cases $(".ui-grid-viewport").niceScroll({ cursorcolor: "#fff", cursorwidth: "8px", autohidemode: "leave" -}); \ No newline at end of file +}); diff --git a/types/jquery.nicescroll/tsconfig.json b/types/jquery.nicescroll/tsconfig.json index a5d8cb44a3..9d94444fc2 100644 --- a/types/jquery.nicescroll/tsconfig.json +++ b/types/jquery.nicescroll/tsconfig.json @@ -7,7 +7,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ diff --git a/types/jquery.nicescroll/tslint.json b/types/jquery.nicescroll/tslint.json index 8bc7a53d89..e60c15844f 100644 --- a/types/jquery.nicescroll/tslint.json +++ b/types/jquery.nicescroll/tslint.json @@ -1,3 +1,3 @@ { - "extends": "dtslint/dt.json", -} + "extends": "dtslint/dt.json" +} \ No newline at end of file