mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
feat(headroom.js): correctted module definition (#46487)
This commit corrects definition of `headroom.js` to support proper NPM name and also adds some more details to the implementation. Authors of `types/headroom` are left as the owners of original implementation in this PR. Changes: - package name - DT header details - default settings for linter/styles - maintainer added https://github.com/WickyNilliams/headroom.js https://github.com/WickyNilliams/headroom.js/blob/master/src/Headroom.js See tests of the 'types/headroom' version, which does not match package name:6970a8fffa/types/headroom/headroom-tests.ts (L1)and the header of current `types/headroom`:6970a8fffa/types/headroom/index.d.ts (L1)The types should be `types/headroom.js`: https://www.npmjs.com/package/headroom.js6970a8fffa/types/headroom/tslint.json (L8)Thanks!
This commit is contained in:
parent
6c071c6ff8
commit
d046b352bf
33
types/headroom.js/headroom.js-tests.ts
Normal file
33
types/headroom.js/headroom.js-tests.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import Headroom = require('headroom.js');
|
||||
|
||||
new Headroom(document.getElementById('siteHead')!);
|
||||
|
||||
new Headroom(document.getElementsByClassName('siteHead')[0]);
|
||||
|
||||
new Headroom(document.getElementsByClassName('siteHead')[0], {
|
||||
tolerance: 34,
|
||||
});
|
||||
|
||||
new Headroom(document.getElementsByClassName('siteHead')[0], {
|
||||
classes: {
|
||||
bottom: 'headroom--bottom',
|
||||
frozen: 'headeroom--frozen',
|
||||
initial: 'headroom',
|
||||
notBottom: 'headroom--not-bottom',
|
||||
notTop: 'headeroom--not-top',
|
||||
pinned: 'headeroom--pinned',
|
||||
top: 'headroom--top',
|
||||
unpinned: 'headroom--unpinned',
|
||||
},
|
||||
offset: 500,
|
||||
});
|
||||
|
||||
const header = document.querySelector('header')!;
|
||||
|
||||
const headroom = new Headroom(header);
|
||||
headroom.init();
|
||||
headroom.freeze();
|
||||
headroom.pin();
|
||||
headroom.unpin();
|
||||
headroom.unfreeze();
|
||||
headroom.destroy();
|
||||
119
types/headroom.js/index.d.ts
vendored
Normal file
119
types/headroom.js/index.d.ts
vendored
Normal file
@ -0,0 +1,119 @@
|
||||
// Type definitions for headroom.js 0.11
|
||||
// Project: http://wicky.nillia.ms/headroom.js
|
||||
// Definitions by: Jakub Olek <https://github.com/hakubo>
|
||||
// Juninho Cruz <https://github.com/juninhocruzg3>
|
||||
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export as namespace Headroom;
|
||||
|
||||
/**
|
||||
* UI enhancement for fixed headers.
|
||||
* Hides header when scrolling down
|
||||
* Shows header when scrolling up
|
||||
*/
|
||||
declare class Headroom {
|
||||
constructor(element: HTMLElement | Node, options?: headroom.HeadroomOptions);
|
||||
|
||||
static options: headroom.HeadroomOptions;
|
||||
static cutsTheMustard: boolean;
|
||||
|
||||
/** initialise */
|
||||
init(): void;
|
||||
|
||||
/** destroy the headroom instance, removing event listeners and any classes added */
|
||||
destroy(): void;
|
||||
|
||||
/** forcibly set the headroom instance's state to pinned */
|
||||
pin(): void;
|
||||
|
||||
/** forcibly set the headroom instance's state to unpinned */
|
||||
unpin(): void;
|
||||
|
||||
/** freeze the headroom instance's state (pinned or unpinned), and no longer respond to scroll events */
|
||||
freeze(): void;
|
||||
|
||||
/** resume responding to scroll events */
|
||||
unfreeze(): void;
|
||||
}
|
||||
|
||||
declare namespace headroom {
|
||||
interface HeadroomOptions {
|
||||
/**
|
||||
* vertical offset in px before element is first unpinned
|
||||
* @default 0
|
||||
*/
|
||||
offset?: number;
|
||||
/** scroll tolerance in px before state changes or you can specify tolerance individually for up/down scroll */
|
||||
tolerance?: Tolerance | number;
|
||||
/** css classes to apply multiple classes are also supported with a space-separated list */
|
||||
classes?: {
|
||||
/**
|
||||
* when element is initialised
|
||||
* @default 'headroom'
|
||||
*/
|
||||
initial?: string;
|
||||
/**
|
||||
* when scrolling up
|
||||
* @default 'headroom--pinned'
|
||||
*/
|
||||
pinned?: string;
|
||||
/**
|
||||
* when scrolling down
|
||||
* @default 'headroom--unpinned'
|
||||
*/
|
||||
unpinned?: string;
|
||||
/**
|
||||
* when above offset
|
||||
* @default 'headroom--top'
|
||||
*/
|
||||
top?: string;
|
||||
/**
|
||||
* when below offset
|
||||
* @default 'headroom--not-top'
|
||||
*/
|
||||
notTop?: string;
|
||||
/**
|
||||
* when at bottom of scroll area
|
||||
* @default 'headroom--bottom'
|
||||
*/
|
||||
bottom?: string;
|
||||
/**
|
||||
* when not at bottom of scroll area
|
||||
* @default 'headroom--not-bottom'
|
||||
*/
|
||||
notBottom?: string;
|
||||
/**
|
||||
* when frozen method has been called
|
||||
* @default 'headroom--frozen'
|
||||
*/
|
||||
frozen?: string;
|
||||
};
|
||||
/**
|
||||
* element to listen to scroll events on
|
||||
* @default window
|
||||
*/
|
||||
scroller?: HTMLElement;
|
||||
/** callback when pinned, `this` is headroom object */
|
||||
onPin?: () => void;
|
||||
/** callback when unpinned, `this` is headroom object */
|
||||
onUnpin?: () => void;
|
||||
/** callback when above offset, `this` is headroom object */
|
||||
onTop?: () => void;
|
||||
/** callback when below offset, `this` is headroom object */
|
||||
onNotTop?: () => void;
|
||||
/** callback when at bottom of page, `this` is headroom object */
|
||||
onBottom?: () => void;
|
||||
/** callback when moving away from bottom of page, `this` is headroom object */
|
||||
onNotBottom?: () => void;
|
||||
}
|
||||
|
||||
interface Tolerance {
|
||||
/** @default 0 */
|
||||
up?: number;
|
||||
/** @default 0 */
|
||||
down?: number;
|
||||
}
|
||||
}
|
||||
|
||||
export = Headroom;
|
||||
24
types/headroom.js/tsconfig.json
Normal file
24
types/headroom.js/tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"DOM"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"headroom.js-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/headroom.js/tslint.json
Normal file
1
types/headroom.js/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user