Added readmore-js 3.0.0-Beta support (#35079)

This commit is contained in:
AntonDemarczyk
2019-04-29 19:37:41 +02:00
committed by Wesley Wigham
parent ff5e639cb4
commit dd1dcf68bf
4 changed files with 83 additions and 0 deletions

30
types/readmore-js/index.d.ts vendored Normal file
View File

@@ -0,0 +1,30 @@
// Type definitions for readmore-js 3.0
// Project: https://github.com/jedfoster/Readmore.js
// Definitions by: AntonDemarczyk <https://github.com/AntonDemarczyk>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare class Readmore {
constructor(element: string | Element | NodeList, options?: Readmore.Options);
toggle(element: null | string | Element | NodeList): void;
destroy(): void;
}
declare namespace Readmore {
interface Options {
speed?: number; // 100 in milliseconds
collapsedHeight?: number; // 200 in pixels
heightMargin?: number; // 16 in pixels, avoids collapsing blocks that are only slightly larger than collapsedHeight
moreLink?: ((element: Element) => string) | string; // HTML string for the "more" toggle link; also accepts a callback function that returns an HTML string
lessLink?: ((element: Element) => string) | string; // HTML string for the "less" toggle link; also accepts a callback function that returns an HTML string
embedCSS?: boolean; // insert required CSS dynamically, set this to false if you include the necessary CSS in a stylesheet
blockCSS?: string; // sets the styling of the blocks, ignored if embedCSS is false
startOpen?: boolean;
sourceOrder?: 'after' | 'before';
beforeToggle?: (trigger: Element, element: Element, expanded: boolean) => void; // called once per block during initilization after Readmore.js has processed the block
afterToggle?: (trigger: Element, element: Element, expanded: boolean) => void; // called after a more or less link is clicked, but before the block is collapsed or expanded
blockProcessed?: (element: Element, collapsable: boolean) => void; // called after the block is collapsed or expanded
}
}
export = Readmore;

View File

@@ -0,0 +1,28 @@
import * as Readmore from 'readmore-js';
const options: Readmore.Options = {
speed: 100,
collapsedHeight: 200,
heightMargin: 16,
moreLink: '<a href="#">Read more</a>',
lessLink: () => '<a href="#">Close</a>',
embedCSS: true,
blockCSS: 'display: block; width: 100%;',
startOpen: false,
sourceOrder: 'after',
beforeToggle: (trigger: Element, element: Element, expanded: boolean) => {
console.log(trigger, element, element);
},
afterToggle: (trigger: Element, element: Element, expanded: boolean) => {
console.log(trigger, element, element);
},
blockProcessed: (element: Element, collapsable: boolean) => {
console.log(element, element);
}
};
new Readmore('.selector', options);
const outer = new Readmore('.outer');
outer.toggle('.inner');
outer.destroy();

View 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",
"readmore-js-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }