diff --git a/dotdotdot/dotdotdot-tests.ts b/dotdotdot/dotdotdot-tests.ts new file mode 100644 index 0000000000..95fe346745 --- /dev/null +++ b/dotdotdot/dotdotdot-tests.ts @@ -0,0 +1,54 @@ +/// +/// + +$("span").dotdotdot({ ellipsis: ":::" }); +$("span").dotdotdot({ wrap: "letter" }); +$("span").dotdotdot({ fallbackToLetter: false }); +$("span").dotdotdot({ after: $("#after") }); +$("span").dotdotdot({ watch: true }); +$("span").dotdotdot({ height: 42 }); +$("span").dotdotdot({ tolerance: 69 }); +$("span").dotdotdot({ callback: () => { } }); +$("span").dotdotdot({ callback: (isTruncated: boolean) => { } }); +$("span").dotdotdot({ callback: (isTruncated: boolean, orgContent: any) => { } }); +$("span").dotdotdot({ lastCharacter: {} }); +$("span").dotdotdot({ lastCharacter: { remove: [','] } }); +$("span").dotdotdot({ lastCharacter: { noEllipsis: ['.', '.'] } }); + +// Copied from documentation +$("#wrapper").dotdotdot({ + /* The text to add as ellipsis. */ + ellipsis: '... ', + + /* How to cut off the text/html: 'word'/'letter'/'children' */ + wrap: 'word', + + /* Wrap-option fallback to 'letter' for long words */ + fallbackToLetter: true, + + /* jQuery-selector for the element to keep and put after the ellipsis. */ + after: null, + + /* Whether to update the ellipsis: true/'window' */ + watch: false, + + /* Optionally set a max-height, if null, the height will be measured. */ + height: null, + + /* Deviation for the height-option. */ + tolerance: 0, + + /* Callback function that is fired after the ellipsis is added, + receives two parameters: isTruncated(boolean), orgContent(string). */ + callback: function (isTruncated, orgContent) { }, + + lastCharacter: { + + /* Remove these characters from the end of the truncated text. */ + remove: [' ', ',', ';', '.', '!', '?'], + + /* Don't add an ellipsis if this array contains + the last character of the truncated text. */ + noEllipsis: [] + } +}); diff --git a/dotdotdot/dotdotdot.d.ts b/dotdotdot/dotdotdot.d.ts new file mode 100644 index 0000000000..af682e94c9 --- /dev/null +++ b/dotdotdot/dotdotdot.d.ts @@ -0,0 +1,76 @@ +// Type definitions for dotdotdot v1.6.16 +// Project: http://dotdotdot.frebsite.nl/ +// Definitions by: Milan Jaros +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface JQuery { + /** + * jQuery.dotdotdot is an advanced cross-browser ellipsis for multiple line content plugin. + * @param options settings that could modify a behaviour. + */ + dotdotdot(options?: JQueryDotDotDot.IDotDotDotOptions): JQuery; +} + +declare module JQueryDotDotDot { + interface IDotDotDotOptions { + /** The text to add as ellipsis. + * Default: '... ' + */ + ellipsis?: string; + + /** How to cut off the text/html: 'word'/'letter'/'children' + * Default: 'word' + */ + wrap?: string; + + /** Wrap-option fallback to 'letter' for long words + * Default: true + */ + fallbackToLetter?: boolean; + + /** jQuery-selector for the element to keep and put after the ellipsis. + * Default: null + */ + after?: JQuery; + + /** Whether to update the ellipsis: true/'window' + * Default: false + */ + watch?: boolean; + + /** Optionally set a max-height, if null, the height will be measured. + * Default: null + */ + height?: number; + + /** Deviation for the height-option. + * Default: 0 + */ + tolerance?: number; // + + /** Callback function that is fired after the ellipsis is added, + * receives two parameters: + * @param isTruncated (boolean) + * @param orgContent (string) Documentation says it is string but it is object + * which has e.g. + * context: HTMLHtmlElement; + * length: number; // seems to be always 1 + * [index] // this contains the text: orgContent[0].data + */ + callback? (isTruncated: boolean, orgContent: any): void; + + lastCharacter?: IDotDotDotOptionsLastCharacter; + } + + interface IDotDotDotOptionsLastCharacter { + /** Remove these characters from the end of the truncated text. + * Default: [' ', ',', ';', '.', '!', '?'] + */ + remove?: string[]; + /** Don't add an ellipsis if this array contains + * the last character of the truncated text. + * Default: [] + */ + noEllipsis?: string[]; + } +} \ No newline at end of file