// Type definitions for FineUploader 5.x.x // Project: http://fineuploader.com/ // Definitions by: Sukhdeep Singh declare module "phine-uploader/lib/core" { export class FineUploaderBasic { /** * The FineUploader Core only constructor */ constructor(fineuploaderOptions?: CoreOptions); /** * FineUploader's Promise implementation */ Promise(): void; /** * Submit one or more files to the uploader * * @param any[] files : An array of `File`s, ``s, `Blob`s, `BlobWrapper` objects, ``es, or `CanvasWrapper` objects. You may also pass in a `FileList`. * @param any params : A set of parameters to send with the file to be added * @param string endpoint : The endpoint to send this file to */ addFiles(files: File[] | HTMLInputElement[] | Blob[] | BlobWrapper | HTMLCanvasElement[] | CanvasWrapper | FileList, params?: any, endpoint?: string): void; /** * Submit one or more canned/initial files to the uploader * * @param any[] initialFiles : An array of objects that describe files already on the server */ addInitialFiles(initialFiles: any[]): void; /** * Cancel the queued or currently uploading item which corresponds to the id * * @param number id : The file's id */ cancel(id: number): void; /** * Cancels all queued or currently uploading items */ cancelAll(): void; /** * Clears the internal list of stored items. Only applies when autoUpload is false */ clearStoredFiles(): void; /** * Attempts to continue a paused upload * * @param number id : A file id * @returns boolean : `true` if attempt was successful. */ continueUpload(id: number): boolean; /** * Send a delete request to the server for the corresponding file id * * @param number id : The file's id */ deleteFile(id: number): void; /** * Draws a thumbnail * * @param number id : The id of the image file * @param HTMLElement targetContainer : The element where the image preview will be drawn. Must be either an or element * @param number maxSize : The maximum dimensions (for width and height) you will allow this image to scale to * @param boolean fromServer : true if the image data will come as a response from the server rather than be generated client-side * @param CustomResizerCallBack customResizer : Ignored if the current browser does not support image previews. * If you want to use an alternate library to resize the image, you must contribute a function for this option that returns a `Promise`. * Once the resize is complete, your promise must be fulfilled. * You may, of course, reject your returned `Promise` is the resize fails in some way. * @returns Promise: Fulfilled by passing the container back into the success callback after the thumbnail has been rendered. * If the thumbnail cannot be rendered, failure callbacks will be invoked instead, passing an object with `container` and `error` properties. */ drawThumbnail(id: number, targetContainer: HTMLElement, maxSize?: number, fromServer?: boolean, customResizer?: CustomResizerCallBack): PromiseOptions; /** * Returns the button container element associated with a file * * @param number id : The file id * @returns HTMLElement : The button container element associated with a file, or `undefined` if the file was not submitted via a Fine Uploader controlled upload button. */ getButton(id: number): HTMLElement; /** * Returns the file identified by the id. File API browsers only * * @param number id : The file id * @returns File | Blob : A `File` or `Blob` object */ getFile(id: number): File | Blob; /** * Returns the endpoint associated with a particular file, or the current catch-all endpoint for all files (if no ID is specified). * * @param number id : The ID of the associated file * @return string | string[] : endpoint associated with a particular file, or the current catch-all endpoint for all files (if no ID is specified). */ getEndpoint(id?: number): string | string[]; /** * Returns the number of items that are either currently uploading or waiting for an available connection (`qq.status.QUEUED`). * * If called inside of a cancel event handler, then this method will return a value that includes the upload associated with the cancel event handler. * This is because the upload will not be canceled until the event handler returns. * * @returns number : The number of items that are currently uploading or queued */ getInProgress(): number; /** * Returns the name of the file with the associated id * * @param number id : The file id * @returns string : Returns the name of the file identified by the id. */ getName(id: number): string; /** * Get the number of items that have been successfully uploaded and have not been deleted * * @returns number : The number of items that have been successfully uploaded and not deleted */ getNetUploads(): number; /** * Get the ID of the parent file for this scaled file * * @param number scaledFileId : The ID of a scaled image file * @returns number : Returns the ID of the scaled image's parent file. `null` if this is not a scaled image or a parent cannot be located */ getParentId(scaledFileId: number): number; /** * Returns the number of remaining allowed items that may be submitted for upload based on `validation.itemLimit`. */ getRemainingAllowedItems(): number; /** * Returns an array of potentially resumable items * * @returns ResumableFileObject[] : An array of resumable items */ getResumableFilesData(): ResumableFileObject[] | ResumableFileObject; /** * Returns the size of the item with the associated id * * @param number id : The file id * @returns number : The size of the file with the corresponding id */ getSize(id: number): number; /** * Return information about all the items that have been submitted to the uploader * * @param UploadFilter filter : An object which indicates which keys and values must be present in an upload to be returned * @return FoundUploadItems | FoundUploadItems [] : A list of items or a single item that has been filtered/found. * This returns an array only when there is a potential for the operation to return more than one file in the result set. * This excludes queries for a specific, single ID or UUID. All other queries will return an array */ getUploads(filter?: UploadFilter): FoundUploadItems | FoundUploadItems[]; /** * Returns the UUID of the item with the associated id * * @param number id : The file id * @returns string : A level 4 UUID which identifies the corresponding file */ getUuid(id: number): string; /** * Output a message to the console, if possible * * @param string message : The message to print * @param string level : The level to output the message at */ log(message: string, level?: string): void; /** * Attempts to pause an in-progress upload * * @param number id : The file id * @returns boolean : `true` if the attempt was successful. `false` otherwise */ pauseUpload(id: number): boolean; /** * Remove internal reference to the associated Blob/File object. * * For Blobs that are created via JavaScript in the browser, this will free up all consumed memory. */ removeFileRef(id: number): void; /** * Reset Fine Uploader */ reset(): void; /** * Attempt to upload a specific item again * * @param number id : The file id */ retry(id: number): void; /** * Generates a scaled version of a submitted image file * * @param number id : The id of the image file * @param ScaleImageOptions option : Information about the scaled image to generate * @returns PromiseOptions : Fulfilled by passing the scaled image as a `Blob` back into the success callback after the original image has been scaled. * If the scaled image cannot be generated, the failure callback will be invoked instead */ scaleImage(id: number, options: ScaleImageOptions): PromiseOptions; /** * Set custom headers for an upload request. Pass in a file id to make the headers specific to that file * * @param any customHeaders : The custom headers to include in the upload request. Fine Uploader may also send some other required headers * @param number id : The file id */ setCustomHeaders(customHeaders: any, id?: number): void; /** * Modify the location where upload requests should be directed. Pass in a file id to change the endpoint for that specific item * * @param string path : A valid URI where upload requests will be sent * @param number | HTMLElement identifier : An integer or HTMLElement corresponding to a file */ setEndpoint(path: string, identifier?: number | HTMLElement): void; /** * Set custom headers for a delete file request. Pass in a file id to make the headers specific to that file * * @param any customHeaders : The custom headers to include in the upload request. Fine Uploader may also send some other required headers * @param number id : The file id */ setDeleteFileCustomHeaders(customHeaders: any, id?: number): void; /** * Modify the location where delete requests should be directed. Pass in a file id to change the endpoint for that specific item * * @param string path : A valid URI where delete requests will be sent * @param number | HTMLElement identifier : An integer or HTMLElement corresponding to a file */ setDeleteFileEndpoint(path: string, identifier?: number | HTMLElement): void; /** * Set the parameters for a delete request. Pass in a file id to make the parameters specific to that file * * @param any params : The parameters to include in the delete request * @param number id : The file id */ setDeleteFileParams(params: any, id?: number): void; /** * Change the `validation.itemLimit` option set during construction/initialization * * @param number newItemLimit : The new file count limit */ setItemLimit(newItemLimit: number): void; /** * Bind a `
` to Fine Uploader dynamically * * @param HTMLFormElement | string formElementOrId : A form element or a form element's ID */ setForm(formElementOrId: HTMLFormElement | string): void; /** * Change the name of a file * * @param number id: The file id * @param string name : The new file name */ setName(id: number, name: string): void; /** * Set the parameters for an upload request. Pass in a file id to make the parameters specific to that file * * @param any params : The parameters to include in the upload request * @param number id : The file id */ setParams(params: any, id?: number): void; /** * Modify the status of an file. * The status values correspond to those found in the qq.status object. * Currently, the following status values may be set via this method: * - qq.status.DELETED * - qq.status.DELETE_FAILED * * @param number id : The file id * @param string newStatus : The new qq.status value. */ setStatus(id: number, newStatus: string): void; /** * Change the UUID of a file * * @param number id : The file id * @param string uuid : The new file UUID */ setUuid(id: number, uuid: string): void; /** * Begin uploading all queued items. Throws a `NoFilesError` if there are no items to upload */ uploadStoredFiles(): void; /* ====================================== UTILITY METHODS ======================================= */ /** * Returns an array of all immediate children of this element. * * @param HTMLElement element : An HTMLElement or an already wrapped qq object * @returns HTMLElement[] : An array of HTMLElements who are children of the `element` parameter */ children(element: HTMLElement): HTMLElement[]; /** * Returns true if the element contains the passed element. * * @param HTMLElement element : An HTMLElement or an already wrapped qq object * @returns boolean : The result of the contains test */ contains(element: HTMLElement): boolean; /** * Returns `true` if the attribute exists on the element and the value of the attribute is not 'false' case-insensitive. * * @param string attributeName : An attribute to test for * @returns boolean : The result of the `hasAttribute` test */ hasAttribute(attributeName: string): boolean; /** * Clears all text for this element */ clearText(): void; /** * Inserts the element directly before the passed element in the DOM. * * @param HTMLElement element : the `element` before which an element has to be inserted */ insertBefore(element: HTMLElement): void; /** * Removes the element from the DOM. */ remove(): void; /** * Sets the inner text for this element. * * @param string text : The text to set */ setText(text: string): void; /** * Add a class to this element. * * @param string className : The name of the class to add to the element */ addClass(className: string): void; /** * Add CSS style(s) to this element. * * @param Object styles : An object with styles to apply to this element * @returns Object : Returns the current context to allow method chaining */ css(styles: any): this; /** * Returns an array of all descendants of this element that contain a specific class name. * * @param string className : The name of the class to look for in each element * @returns HTMLElement[] : An array of `HTMLElements */ getByClass(className: string): HTMLElement[]; /** * Returns `true` if the element has the class name * * @param string className : The name of the class to look for in each element * @returns boolean : Result of the `hasClass` test */ hasClass(className: string): boolean; /** * Hide this element. * * @returns Object : Returns the current context to allow method chaining */ hide(): this; /** * Remove the provided class from the element. * * @param string className : The name of the class to look for in each element * @returns Object : Returns the current context to allow method chaining */ removeClass(className: string): this; /** * Attach an event handler to this element for a specific DOM event. * * @param string event : A valid `DOM Event` * @param function handler : A function that will be invoked whenever the respective event occurs * @returns function : Call this function to detach the event */ attach(event: string, handler: () => any | void): () => any | void; /** * Detach an already attached event handler from this element for a specific DOM event * * @param string event : A valid `DOM Event` * @param function originalHandler : A function that will be detached from this event * @returns Object : Call this function to detach the event */ detach(event: string, originalHandler: () => any | void): this; /** * Shim for `Function.prototype.bind` * * Creates a new function that, when called, has its `this` keyword set to the provided context. * Pass comma-separated values after the `context` parameter for all arguments to be passed into the new function (when invoked). * You can still pass in additional arguments during invocation. * * @param function oldFunc : The function that will be bound to * @param Object context : The context the function will assume * @returns function : A new function, same as the old one, but bound to the passed in `context` */ bind(oldFunc: () => any | void, context: any): () => any; /** * Iterates through a collection, passing the key and value into the provided callback. `return false;` to stop iteration. * * @param Array or Object : * @param function callback : A function that will be called for each item returned by looping through the iterable. This function takes an index and an item. */ each(iterable: any[] | any, callback: (index: number, item: any) => any | void): () => any | void; /** * Shallowly copies the parameters of secondobj to firstobj. if extendnested is true then a deep-copy is performed. * * @param Object firstObj : The object to copy parameters to * @param Object secondObj : The object to copy parameters from * @param boolean extendNested : If `true` then a deep-copy is performed, else a shallow copy * @returns Object : The new object created by the extension */ extend(firstObj: any, secondObj: any, extendNested?: boolean): any; /** * Returns a string, swapping argument values with the associated occurrence of `{}` in the passed string * * @param string message : the string to be formatted * @returns string : the formatted string */ format(message: string): string; /** * Return the extension for the filename, if any * * @param string filename : The file's name to rip the extension off of * @returns string : The extension name */ getExtension(filename: string): string; /** * Returns a version4 uuid * * @returns string : A version 4 unique identifier */ getUniqueId(): string; /** * Returns the index of `item` in the `Array` starting the search from `startingindex` * * @param any[] array : the array to search in * @param Object item : the item to search for * @param number startingIndex : the index to search from * @returns number : The index of `item` in the array */ indexOf(array: any[], item: any, startingIndex?: number): number; /** * Check if the parameter is function * * @param Object func : The object to test * @returns boolean : Whether the parameter is a function or not */ isFunction(func: any): boolean; /** * Check if the parameter is object * * @param Object obj : The thing to test * @returns boolean : Whether the parameter is a object or not */ isObject(obj: any): boolean; /** * Check if the parameter is string * * @param Object str : The object to test * @returns boolean : Whether the parameter is a string or not */ isString(str: any): boolean; /** * Log a message to the console. no-op if console logging is not supported. shim for `console.log` * * @param string logMessage : The message to log * @param string logLevel : The logging level, such as 'warn' and 'info'. If `null`, then 'info' is assumed */ log(logMessage: string, logLevel?: string): void; /** * Prevent the browser's default action on an event * * @param string event : The name of the default event to prevent */ preventDefault(event: string): void; /** * Creates and returns a new
element * * @param string str : Valid HTML that can be parsed by a browser. * @returns HTMLElement : An newly created `HTMLElement` from the input */ toElement(str: string): HTMLElement; /** * Removes whitespace from the ends of a string. Shim for `String.prototype.trim` * * @param string str : The string to remove whitespace from * @returns string : The new string sans whitespace */ trimstr(str: string): string; /* ====================================== END - UTILITY METHODS ================================= */ } /* ====================================== Misc Options and Wrappers ==================================== */ /** * Callback type for `customResizer` parameter */ export interface CustomResizerCallBack { /** * Contribute this function to manually resize images using alternate 3rd party libraries * * @param ResizeInfo resizeInfo : the ResizeInfo object containing all the resize values/options * @returns Promise : Once the resize is complete, the function must return a promise */ (resizeInfo: ResizeInfo): PromiseOptions; } /** * The FineUploader namespace contains all the methods, options, events and types /* ========================================================== CORE & UI ===================================================================== */ /** * type for `resizeInfo` object */ export interface ResizeInfo { /** * The original `File` or `Blob` object, if available. */ blob?: File | Blob; /** * Desired height of the image after the resize operation. */ height?: number; /** * The original HTMLImageElement object, if available. */ image?: HTMLImageElement; /** * `HTMLCanvasElement` element containing the original image data (not resized). */ sourceCanvas?: HTMLCanvasElement; /** * `HTMLCanvasElement` element containing the `HTMLCanvasElement` that should contain the resized image. */ targetCanvas?: HTMLCanvasElement; /** * Desired width of the image after the resize operation. */ width?: number; } /** * type for getUploads method's filter parameter */ export interface UploadFilter { /** * the id of the file */ id?: number | number[]; /** * the uuid of the file */ uuid?: number | number[]; /** * status of the file */ status?: string | string[]; } /** * type for getUploads method's return object */ export interface FoundUploadItems extends UploadFilter { /** * the name of the file */ name?: string; /** * the size of the file */ size?: string; } /** * ScaleImageOptions */ export interface ScaleImageOptions { /** * required */ maxSize: number; /** * @default `true` */ orient?: boolean; /** * defaults to the type of the reference image */ type?: string; /** * number between `0` and `100` * * @default `80` */ quality?: number; /** * @default `false` */ includeExif?: boolean; /** * Ignored if the current browser does not support image previews. * * If you want to use an alternate library to resize the image, you must contribute a function for this option that returns a `Promise`. * * Once the resize is complete, your promise must be fulfilled. * You may, of course, reject your returned `Promise` is the resize fails in some way. */ customResizer?: CustomResizerCallBack; } export interface PromiseOptions { /** * Register callbacks from success and failure. * * The promise instance that then is called on will pass any values into the provided callbacks. * If success or failure have already occurred before these callbacks have been registered, then they will be called immediately after this call has been executed. * Each subsequent call to then registers an additional set of callbacks. * * @param Function successCallback : The function to call when the promise is successfully fulfilled * @param Function failureCallback : The function to call when the promise is unsuccessfully fulfilled * @return PromiseOptions : An instance of a promise */ then(successCallback: Function, failureCallback: Function): PromiseOptions; /** * Register callbacks for success or failure. * * Invoked when the promise is fulfilled regardless of the result. * The promise instance that done is called on will pass any values into the provided callback. * Each call to done registers an additional set of callbacks * * @param Function callback : The function to call when the promise is fulfilled, successful or not. * @return PromiseOptions : An instance of a promise */ done(callback: Function): PromiseOptions; /** * Call this on a promise to indicate success. * The parameter values will depend on the situation. * * @param Object param : The value to pass to the promise's success handler. * @return PromiseOptions : An instance of a promise */ success(param: any): PromiseOptions; /** * Call this on a promise to indicate failure. * The parameter values will depend on the situation. * * @param Object param : The value to pass to the promise's failure handler. * @return PromiseOptions : An instance of a promise */ failure(param: any): PromiseOptions; } /** * A BlobWrapper object type */ export interface BlobWrapper { /** * the bytes of the `Blob` object being uploaded */ blob?: Blob; /** * the name of the `Blob` */ name?: string; } /** * A CanvasWrapper Object type */ export interface CanvasWrapper { /** * the `` to be converted to a file & then uploaded */ canvas?: HTMLCanvasElement; /** * the name to assign to the created file */ name?: string; /** * `1`-`100` value indicating the desired quality of the converted file (only for `image/jpeg`) */ quality?: number; /** * MIME type of the file to create from this `` */ type?: MimeType; } /** * Resumable file object type */ export interface ResumableFileObject { /** * filename */ name?: string; /** * the unique id */ uuid?: number; /** * the index of the part where the resume will start from */ partIdx?: number; } /* ====================================== Core Options ==================================== */ /** * Contains Core options */ export interface CoreOptions { /** * Set to false if you want to be able to upload queued items later by calling the `uploadStoredFiles()` method * * @default `true` */ autoUpload?: boolean; /** * Specify an element to use as the 'select files' button. Cannot be a `