From 1e26d4855170e319db0db0c70612c3fe1f357ff6 Mon Sep 17 00:00:00 2001 From: Kaur Kuut Date: Thu, 17 Sep 2015 17:56:38 +0300 Subject: [PATCH] Added definitions for Featherlight v1.3.4. --- featherlight/featherlight-tests.ts | 169 +++++++++++++++++++++++++++++ featherlight/featherlight.d.ts | 114 +++++++++++++++++++ 2 files changed, 283 insertions(+) create mode 100644 featherlight/featherlight-tests.ts create mode 100644 featherlight/featherlight.d.ts diff --git a/featherlight/featherlight-tests.ts b/featherlight/featherlight-tests.ts new file mode 100644 index 000000000..ed74a201e --- /dev/null +++ b/featherlight/featherlight-tests.ts @@ -0,0 +1,169 @@ +// Tests by: Kaur Kuut + +/// +/// + +// Every option as default +var defaultOptions = { + namespace: 'featherlight', + targetAttr: 'data-featherlight', + variant: null as string, + resetCss: false, + background: null as string, + openTrigger: 'click', + closeTrigger: 'click', + filter: null as string, + root: 'body', + openSpeed: 250, + closeSpeed: 250, + closeOnClick: 'background', + closeOnEsc: true, + closeIcon: '✕', + loading: '', + persist: false, + otherClose: null as string, + beforeOpen: $.noop, + beforeContent: $.noop, + beforeClose: $.noop, + afterOpen: $.noop, + afterContent: $.noop, + afterClose: $.noop, + onKeyUp: $.noop, + onResize: $.noop, + type: null as string, + contentFilters: ['jquery', 'image', 'html', 'ajax', 'iframe', 'text'] +}; + +// Every option changed +var changedOptions = { + namespace: 'foo', + targetAttr: 'foo', + variant: 'foo', + resetCss: true, + background: '
', + openTrigger: 'focus', + closeTrigger: 'blur', + filter: 'foo', + root: 'foo', + openSpeed: 'fast', + closeSpeed: 'fast', + closeOnClick: false, + closeOnEsc: false, + closeIcon: 'foo', + loading: 'foo', + persist: 'shared', + otherClose: 'foo', + beforeOpen: (e: JQueryEventObject) => false, + beforeContent: (e: JQueryEventObject) => false, + beforeClose: (e: JQueryEventObject) => false, + afterOpen: (e: JQueryEventObject) => false, + afterContent: (e: JQueryEventObject) => false, + afterClose: (e: JQueryEventObject) => false, + onKeyUp: (e: JQueryEventObject) => false, + onResize: (e: JQueryEventObject) => false, + type: 'text' +}; + +// Turn off auto bind +$.featherlight.autoBind = false; + +// Change some defaults +$.featherlight.defaults.namespace = 'foo'; +$.featherlight.defaults.openSpeed = 500; +$.featherlight.defaults.persist = true; +$.featherlight.defaults.text = 'foo'; + +// Do the simplest manual bind +$('#id').featherlight(); + +// Bind #id to open #fl +$('#id').featherlight('#fl'); + +// Bind #id to open #fl with persistance +$('#id').featherlight('#fl', {persist: true}); + +// Bind #id to open jQuery object +$('#id').featherlight($('Foo!')); + +// Bind #id to open jQuery object with persistance +$('#id').featherlight($('Foo!'), {persist: true}); + +// Bind #id to open #fl with every option set to default +$('#id').featherlight('#fl', defaultOptions); + +// Bind #id to open jQuery object with every option set to default +$('#id').featherlight($('Foo!'), defaultOptions); + +// Bind #id to open #fl with every option changed +$('#id').featherlight('#fl', changedOptions); + +// Bind #id to open jQuery object with every option changed +$('#id').featherlight($('Foo!'), changedOptions); + +// Open the default +$.featherlight(); +new $.featherlight; + +// Open just text +$.featherlight({text: 'Foo!'}).open(); +new $.featherlight({text: 'Foo!'}).open(); + +// Open #fl, and close it +$.featherlight('#fl').close(); +new $.featherlight('#fl').close(); + +// Open #fl with persistance, and close it +$.featherlight('#fl', {persist: true}).close(); +new $.featherlight('#fl', {persist: true}).close(); + +// Open jQuery object, and close it +$.featherlight($('Foo!')).close(); +new $.featherlight($('Foo!')).close(); + +// Open jQuery object with persistance, and close it +$.featherlight($('Foo!'), {persist: true}).close(); +new $.featherlight($('Foo!'), {persist: true}).close(); + +// Open #fl with every option set to default, and close it +$.featherlight('#fl', defaultOptions).close(); +new $.featherlight('#fl', defaultOptions).close(); + +// Open jQuery object with every option set to default, and close it +$.featherlight($('Foo!'), defaultOptions).close(); +new $.featherlight($('Foo!'), defaultOptions).close(); + +// Open #fl with every option changed, and close it +$.featherlight('#fl', changedOptions).close(); +new $.featherlight('#fl', changedOptions).close(); + +// Open jQuery object with every option changed, and close it +$.featherlight($('Foo!'), changedOptions).close(); +new $.featherlight($('Foo!'), changedOptions).close(); + +// Define a custom content filter +// Note: Unfortunately $.featherlight.contentFilters.feed = .. doesn't seem to work +$.featherlight.contentFilters['feed'] = { + regex: /^feed:/, + process: function(url: string) { return $('Loading...'); } +}; + +// Close the currently open fl +$.featherlight.close(); + +// Get all the opened fls and close the first +$.featherlight.opened()[0].close(); + +// Get the currently opened fl +var fl = $.featherlight.current(); + +// .. and close it +fl.close(); + +// .. and open it once more +fl.open(); + +// .. and edit its namespace +fl.namespace = 'foo'; + +// .. and add a special event handler +fl.afterClose = (e: JQueryEventObject) => false; diff --git a/featherlight/featherlight.d.ts b/featherlight/featherlight.d.ts new file mode 100644 index 000000000..ad4c1d1c2 --- /dev/null +++ b/featherlight/featherlight.d.ts @@ -0,0 +1,114 @@ +// Type definitions for Featherlight v1.3.4 +// Project: https://noelboss.github.io/featherlight/ +// Definitions by: Kaur Kuut +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module Featherlight { + interface Config { + namespace?: string; + targetAttr?: string; + variant?: string; + resetCss?: boolean; + background?: string; + openTrigger?: string; + closeTrigger?: string; + filter?: string; + root?: string; + openSpeed?: number | string; + closeSpeed?: number | string; + closeOnClick?: boolean | string; + closeOnEsc?: boolean; + closeIcon?: string; + loading?: string; + persist?: boolean | string; + otherClose?: string; + beforeOpen?: (event: JQueryEventObject) => any; + beforeContent?: (event: JQueryEventObject) => any; + beforeClose?: (event: JQueryEventObject) => any; + afterOpen?: (event: JQueryEventObject) => any; + afterContent?: (event: JQueryEventObject) => any; + afterClose?: (event: JQueryEventObject) => any; + onKeyUp?: (event: JQueryEventObject) => any; + onResize?: (event: JQueryEventObject) => any; + type?: string; + contentFilters?: any; + jquery?: JQuery; + image?: string; + html?: string; + ajax?: string; + text?: string; + } + + interface ContentFilter { + regex?: RegExp; + test?(data: JQuery | string): boolean; + process?(data: JQuery | string): JQuery | JQueryPromise; + } + + interface ContentFilters { + [name: string]: ContentFilter; + } + + interface Featherlight extends Config { + target: JQuery | string; + $instance: JQuery; + $content: JQuery; + + setup(target: JQuery, config?: Config): Featherlight; + setup(target: string, config?: Config): Featherlight; + setup(config: Config): Featherlight; + setup(): Featherlight; + + getContent(): JQuery | JQueryPromise; + setContent($content: JQuery): Featherlight; + setContent($content: JQueryPromise): Featherlight; + open(event?: JQueryEventObject): JQueryPromise; + close(event?: JQueryEventObject): JQueryPromise; + } + + interface FeatherlightStatic { + ($content: JQuery, config?: Config): Featherlight; + ($content: string, config?: Config): Featherlight; + (config: Config): Featherlight; + (): Featherlight; + + new($content: JQuery, config?: Config): Featherlight; + new($content: string, config?: Config): Featherlight; + new(config: Config): Featherlight; + new(): Featherlight; + + attach($source: JQuery, $content: JQuery, config?: Config): JQuery; + attach($source: JQuery, $content: string, config?: Config): JQuery; + attach($source: JQuery, config: Config): JQuery; + attach($source: JQuery): JQuery; + + id: number; + autoBind: boolean | string; + defaults: Config; + contentFilters: ContentFilters; + functionAttributes: string[]; + + readElementConfig(element: HTMLElement, namespace: string): any; + extend(child: any, defaults: any): any; + current(): Featherlight; + opened(): Featherlight[]; + close(): JQueryPromise; + } + + interface JQueryExtension { + ($content: JQuery, config?: Config): JQuery; + ($content: string, config?: Config): JQuery; + (config: Config): JQuery; + (): JQuery; + } +} + +interface JQueryStatic { + featherlight: Featherlight.FeatherlightStatic; +} + +interface JQuery { + featherlight: Featherlight.JQueryExtension; +}