mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-29 01:45:49 +08:00
Added definitions for Featherlight v1.3.4.
This commit is contained in:
169
featherlight/featherlight-tests.ts
Normal file
169
featherlight/featherlight-tests.ts
Normal file
@@ -0,0 +1,169 @@
|
||||
// Tests by: Kaur Kuut <https://github.com/xStrom>
|
||||
|
||||
///<reference path="../jquery/jquery.d.ts" />
|
||||
///<reference path="featherlight.d.ts" />
|
||||
|
||||
// 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: '<div/>',
|
||||
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($('<span>Foo!</span>'));
|
||||
|
||||
// Bind #id to open jQuery object with persistance
|
||||
$('#id').featherlight($('<span>Foo!</span>'), {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($('<span>Foo!</span>'), 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($('<span>Foo!</span>'), 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($('<span>Foo!</span>')).close();
|
||||
new $.featherlight($('<span>Foo!</span>')).close();
|
||||
|
||||
// Open jQuery object with persistance, and close it
|
||||
$.featherlight($('<span>Foo!</span>'), {persist: true}).close();
|
||||
new $.featherlight($('<span>Foo!</span>'), {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($('<span>Foo!</span>'), defaultOptions).close();
|
||||
new $.featherlight($('<span>Foo!</span>'), 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($('<span>Foo!</span>'), changedOptions).close();
|
||||
new $.featherlight($('<span>Foo!</span>'), 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;
|
||||
114
featherlight/featherlight.d.ts
vendored
Normal file
114
featherlight/featherlight.d.ts
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
// Type definitions for Featherlight v1.3.4
|
||||
// Project: https://noelboss.github.io/featherlight/
|
||||
// Definitions by: Kaur Kuut <https://github.com/xStrom>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
///<reference path="../jquery/jquery.d.ts" />
|
||||
|
||||
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<JQuery>;
|
||||
}
|
||||
|
||||
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<JQuery>;
|
||||
setContent($content: JQuery): Featherlight;
|
||||
setContent($content: JQueryPromise<JQuery>): Featherlight;
|
||||
open(event?: JQueryEventObject): JQueryPromise<JQuery>;
|
||||
close(event?: JQueryEventObject): JQueryPromise<JQuery>;
|
||||
}
|
||||
|
||||
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<JQuery>;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user