Merge pull request #26232 from Wkalmar/master

Add types to jquery.nicescroll
This commit is contained in:
Daniel Rosenwasser
2018-06-04 00:32:21 -07:00
committed by GitHub
4 changed files with 173 additions and 0 deletions
+105
View File
@@ -0,0 +1,105 @@
// Type definitions for jquery.nicescroll 3.7
// Project: https://nicescroll.areaaperta.com
// Definitions by: Bohdan Stupak <https://github.com/Wkalmar>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="jquery"/>
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;
}
@@ -0,0 +1,41 @@
// cases from documentation
// 1. Simple mode, it styles document scrollbar:
$(() => {
$("body").niceScroll();
});
// 2. Instance with object returned:
let nice;
$(() => {
nice = $("body").niceScroll();
});
// 3. Style a DIV and change cursor color:
$(() => {
$("#thisdiv").niceScroll({cursorcolor: "#00F"});
});
// 4. DIV with "wrapper", formed by two divs, the first is the vieport, the latter is the content:
$(() => {
$("#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"
});
+24
View File
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"jquery.nicescroll-tests.ts"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}