From 899595db5d143145ec7965829260b1edbc80cc4b Mon Sep 17 00:00:00 2001 From: Patrick Westerhoff Date: Fri, 6 Nov 2015 14:09:44 +0100 Subject: [PATCH] Add definitions for svg-injector --- svg-injector/svg-injector-tests.ts | 22 +++++++++++++++ svg-injector/svg-injector.d.ts | 43 ++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 svg-injector/svg-injector-tests.ts create mode 100644 svg-injector/svg-injector.d.ts diff --git a/svg-injector/svg-injector-tests.ts b/svg-injector/svg-injector-tests.ts new file mode 100644 index 0000000000..e90bf8e2a8 --- /dev/null +++ b/svg-injector/svg-injector-tests.ts @@ -0,0 +1,22 @@ +/// + +var SVGInjector: SVGInjector; + +// Simple example +var mySVGsToInject = document.querySelectorAll('img.inject-me'); +SVGInjector(mySVGsToInject); + +// Single DOM element +SVGInjector(document.querySelector('.inject-me')); + +// Configuration +SVGInjector(mySVGsToInject, { + evalScripts: 'always', + pngFallback: './path/to/images/', + each: eachCallback +}); +function eachCallback(element: SVGElement) { } + +// Callback +SVGInjector(mySVGsToInject, null, callback); +function callback(count: number) { } diff --git a/svg-injector/svg-injector.d.ts b/svg-injector/svg-injector.d.ts new file mode 100644 index 0000000000..2fd41caa86 --- /dev/null +++ b/svg-injector/svg-injector.d.ts @@ -0,0 +1,43 @@ +// Type definitions for SVG Injector +// Project: https://github.com/iconic/SVGInjector +// Definitions by: Patrick Westerhoff +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare interface SVGInjector { + /** + * Replace the given elements with their full inline SVG DOM elements. + * + * @param elements Array of or single DOM element. + * @param options Injector options. + * @param done Callback that receives the injected element count as parameter. + */ + (elements: Node | NodeList | Array, options?: SVGInjectorOptions, done?: (elementCount: number) => void): void; +} + +declare interface SVGInjectorOptions { + /** + * Whether to run scripts blocks found in the SVG. + * + * Possible values: + * 'always' — Run scripts every time. + * 'once' — Only run scripts once for each SVG. + * 'never' — Ignore scripts (default) + */ + evalScripts?: string; + + /** + * Location of fallback pngs, if desired. + */ + pngFallback?: string; + + /** + * Callback to run during each SVG injection. The SVG element is passed if + * the injection was successful. + */ + each?: (svg: SVGElement | string) => void; +} + +declare module "svg-injector" { + var SVGInjector: SVGInjector; + export = SVGInjector; +}