From abf87f7c822b61d78c2496fe26011c4657c3765a Mon Sep 17 00:00:00 2001 From: arminbaljic Date: Tue, 27 Jun 2017 11:03:49 +0200 Subject: [PATCH] Added type definitions for iframe-resizer --- types/iframe-resizer/iframe-resizer-tests.ts | 1 + types/iframe-resizer/index.d.ts | 184 +++++++++++++++++++ types/iframe-resizer/tsconfig.json | 25 +++ types/iframe-resizer/tslint.json | 1 + 4 files changed, 211 insertions(+) create mode 100644 types/iframe-resizer/iframe-resizer-tests.ts create mode 100644 types/iframe-resizer/index.d.ts create mode 100644 types/iframe-resizer/tsconfig.json create mode 100644 types/iframe-resizer/tslint.json diff --git a/types/iframe-resizer/iframe-resizer-tests.ts b/types/iframe-resizer/iframe-resizer-tests.ts new file mode 100644 index 0000000000..1996490390 --- /dev/null +++ b/types/iframe-resizer/iframe-resizer-tests.ts @@ -0,0 +1 @@ +import resizer = require('iframe-resizer'); diff --git a/types/iframe-resizer/index.d.ts b/types/iframe-resizer/index.d.ts new file mode 100644 index 0000000000..04ff130667 --- /dev/null +++ b/types/iframe-resizer/index.d.ts @@ -0,0 +1,184 @@ +// Type definitions for iframe-resizer +// Project: https://github.com/davidjbradshaw/iframe-resizer +// Definitions by: Armin Baljic +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module 'iframe-resizer' { + export interface IFrameObject { + close(): void; + moveToAnchor(anchor): void; + resize(): void; + sendMessage(message: any): void; + } + + export interface IFrameComponent extends HTMLIFrameElement { + iFrameResizer: IFrameObject + } + + export interface IFrameOptions { + /** + * When enabled changes to the Window size or the DOM will cause the iFrame to resize to the new content size. + * Disable if using size method with custom dimensions. + */ + autoResize?: boolean; + /** + * Override the body background style in the iFrame. + */ + bodyBackground?: string; + /** + * Override the default body margin style in the iFrame. A string can be any valid value for the + * CSS margin attribute, for example '8px 3em'. A number value is converted into px. + */ + bodyMargin?: number; + /** + * When set to true, only allow incoming messages from the domain listed in the src property of the iFrame tag. + * If your iFrame navigates between different domains, ports or protocols; then you will need to + * provide an array of URLs or disable this option. + */ + checkOrigin?: boolean; + /** + * When enabled in page linking inside the iFrame and from the iFrame to the parent page will be enabled. + */ + inPageLinks?: boolean; + /** + * Height calculation method. + */ + heightCalculationMethod?: string; + /** + * Set iFrame Id + */ + id?: string; + /** + * In browsers that don't support mutationObserver, such as IE10, the library falls back to using + * setInterval, to check for changes to the page size. + */ + interval?: number; + /** + * Setting the log option to true will make the scripts in both the host page and the iFrame output + * everything they do to the JavaScript console so you can see the communication between the two scripts. + */ + log?: boolean; + /** + * Set maximum height of iFrame. + */ + maxHeight?: number; + /** + * Set maximum width of iFrame. + */ + maxWidth?: number; + /** + * Set minimum height of iFrame. + */ + minHeight?: number; + /** + * Set minimum width of iFrame. + */ + minWidth?: number; + /** + * Listen for resize events from the parent page, or the iFrame. Select the 'child' value if the iFrame + * can be resized independently of the browser window. Selecting this value can cause issues with some + * height calculation methods on mobile devices. + */ + resizeFrom?: string; + /** + * Enable scroll bars in iFrame. + */ + scrolling?: boolean; + /** + * Resize iFrame to content height. + */ + sizeHeight?: boolean; + /** + * Resize iFrame to content width. + */ + sizeWidth?: boolean; + /** + * Set the number of pixels the iFrame content size has to change by, before triggering a resize of the iFrame. + */ + tolerance?: number; + /** + * Width calculation method. + */ + widthCalculationMethod?: string; + /** + * Called when iFrame is closed via parentIFrame.close() or iframe.iframeResizer.close() methods. + */ + closedCallback?: (iframeId: string) => void; + /** + * Initial setup callback function. + */ + initCallback?: (iframe: IFrameComponent) => void; + /** + * Receive message posted from iFrame with the parentIFrame.sendMessage() method. + */ + messageCallback?: (data: IFrameMessageData) => void; + /** + * Function called after iFrame resized. Passes in messageData object containing the iFrame, height, width + * and the type of event that triggered the iFrame to resize. + */ + resizedCallback?: (data: IFrameResizedData) => void; + /** + * Called before the page is repositioned after a request from the iFrame, due to either an in page link, + * or a direct request from either parentIFrame.scrollTo() or parentIFrame.scrollToOffset(). + * If this callback function returns false, it will stop the library from repositioning the page, so that + * you can implement your own animated page scrolling instead. + */ + scrollCallback?: (data: IFrameScrollData) => boolean; + } + + export interface IFramePageOptions { + /** + * This option allows you to restrict the domain of the parent page, + * to prevent other sites mimicking your parent page. + */ + targetOrigin?: string; + /** + * Receive message posted from the parent page with the iframe.iFrameResizer.sendMessage() method. + */ + messageCallback?: (message: any) => void; + /** + * This function is called once iFrame-Resizer has been initialized after receiving a call from the parent page. + */ + readyCallback?: () => void; + /** + * These option can be used to override the option set in the parent page + */ + heightCalculationMethod?: string; + /** + * These option can be used to override the option set in the parent page + */ + widthCalculationMethod?: string; + } + + export interface IFramePage { + autoResize(resize?: boolean): boolean; + close(): void; + getId(): string; + getPageInfo(callback: (data: any) => void | false): void; + scrollTo(x: number, y: number); + scrollToOffset(x: number, y: number); + sendMessage(message: any): void; + setHeightCalculationMethod(method: string): void; + size(customHeight?, customWidth?): void + } + + + export interface IFrameResizedData { + iframe: IFrameComponent; + height: number; + width: number; + type: string; + } + + export interface IFrameMessageData { + iframe: IFrameComponent; + message: string; + } + + export interface IFrameScrollData { + x: number; + y: number; + } + + export function iframeResizer(options: IFrameOptions, target: HTMLElement): IFrameComponent; +} \ No newline at end of file diff --git a/types/iframe-resizer/tsconfig.json b/types/iframe-resizer/tsconfig.json new file mode 100644 index 0000000000..ef96a6d33a --- /dev/null +++ b/types/iframe-resizer/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "exclude": [ + "node_modules" + ], + "files": [ + "index.d.ts", + "iframe-resizer-tests.ts" + ] +} \ No newline at end of file diff --git a/types/iframe-resizer/tslint.json b/types/iframe-resizer/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/iframe-resizer/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }