Add definitions for svg-injector

This commit is contained in:
Patrick Westerhoff 2015-11-06 14:09:44 +01:00
parent 35989a3ab4
commit 899595db5d
2 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,22 @@
/// <reference path="svg-injector.d.ts" />
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) { }

43
svg-injector/svg-injector.d.ts vendored Normal file
View File

@ -0,0 +1,43 @@
// Type definitions for SVG Injector
// Project: https://github.com/iconic/SVGInjector
// Definitions by: Patrick Westerhoff <https://github.com/poke>
// 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<Node>, 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;
}