Added typings for jquery cropbox plugin

This commit is contained in:
Per Kastman
2015-10-07 02:36:56 +09:00
committed by vvakame
parent a5f6b63f63
commit b6d12c4ec8
2 changed files with 154 additions and 0 deletions
+115
View File
@@ -0,0 +1,115 @@
// Type definitions for jQuery cropbox
// Project: https://github.com/acornejo/jquery-cropbox
// Definitions by: Per Kastman <https://github.com/PerKastman/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../jquery/jquery.d.ts"/>
declare module jQueryCropBox {
enum ShowControls {
never,
always,
hover,
auto
}
interface CropboxArea {
cropX: number;
cropY: number;
cropW: number;
cropH: number;
}
interface CropboxOptions {
/**
* Width in pixels of the cropping window
*/
width?: number;
/**
* Height in pixels of the cropping window
*/
height?: number;
/**
* Number of incremental zoom steps. With the default of 10, you have to click the zoom-in button 9 times to reach 100%.
*/
zoom?: number;
/**
* Maximum zoom value. With the default of 1.0 users can't zoom beyond the maximum image resolution.
*/
maxZoom?: number;
/**
* If not null, this is the entire html block that should appear on hover over the image for instructions and/or buttons (could include the zoom in/out buttons for example). If null, the default html block is used which has the text "Click to drag" and the zoom in/out buttons. Use false to disable controls.
*/
controls?: any;
/**
* Set the initial cropping area
*/
result?: CropboxArea;
/**
* This flag is used to determine when to display the controls. Never, always and hover do exactly what you would expect (never show them, always show them, show them on hover). The auto flag is the same as the hover flag, except that on mobile devices it always shows the controls (since there is no hover event).
*/
showControls?: ShowControls
}
interface CropboxDragOptions {
startX: number,
startY: number,
dx: number,
dy: number
}
interface CropboxSetCropOptions {
cropX: number,
cropY: number,
cropW: number,
cropH: number
}
interface Cropbox {
/**
* Increase image zoom level by one step
*/
zoomIn(): void;
/**
* Decrease image zoom level by one step
*/
zoomOut(): void;
/**
* Set zoom leevl to a value between 0 and 1. Need to call update to reflect the changes.
*/
zoom(percent: number): void;
/**
* Simulate image dragging, starting from (startX,startY) and moving a delta of (dx,dy). Need to call update to reflect the changes.
*/
drag(options: CropboxDragOptions): void;
/**
* Set crop window.
*/
setCrop(options: CropboxSetCropOptions): void;
/**
* Update the cropped result (must call after zoom and drag).
*/
update(): void;
/**
* Generate a URL for the cropped image on the client (requires HTML5 compliant browser).
*/
getDataURL(): string;
/**
* Generate a Blob with the cropped image (requires HTML5 compliant browser).
*/
getBlob(): any;
/**
* Remove the cropbox functionality from the image.
*/
remove(): void;
}
}
interface JQuery {
cropbox(params?: jQueryCropBox.CropboxOptions): jQueryCropBox.Cropbox
}
interface JQueryStatic {
cropbox(params?: jQueryCropBox.CropboxOptions): jQueryCropBox.Cropbox
}
+39
View File
@@ -0,0 +1,39 @@
/// <reference path="../jquery/jquery.d.ts"/>
/// <reference path="jquery.cropbox.d.ts"/>
var cropboxWithDefaultSettings = $("#element").cropbox();
var cropboxOptions: jQueryCropBox.CropboxOptions = {
height: 500,
zoom: 5,
width: 0.5,
};
var cropboxWithOptions = $("#element").cropbox(cropboxOptions);
cropboxWithOptions.zoomIn();
cropboxWithOptions.zoomOut();
cropboxWithOptions.zoom(50);
var cropDragOption: jQueryCropBox.CropboxDragOptions = {
startX: 10,
startY: 0,
dx: 100,
dy: 100
};
cropboxWithOptions.drag(cropDragOption);
var cropboxSetCropOption: jQueryCropBox.CropboxSetCropOptions = {
cropX: 10,
cropY: 10,
cropW: 50,
cropH: 50
};
cropboxWithOptions.setCrop(cropboxSetCropOption);
cropboxWithOptions.update();
cropboxWithOptions.getDataURL();
cropboxWithOptions.getBlob();
cropboxWithOptions.remove();