diff --git a/types/plupload/index.d.ts b/types/plupload/index.d.ts index 614ba27261..a70423533d 100644 --- a/types/plupload/index.d.ts +++ b/types/plupload/index.d.ts @@ -18,7 +18,7 @@ interface plupload_settings { multipart_params?: any; /** Chunk */ - chunk_size?: number|string; + chunk_size?: number | string; /** Client-Side Image Resize */ resize?: plupload_resize; @@ -28,7 +28,7 @@ interface plupload_settings { /** Useful Options */ multi_selection?: boolean; - required_features?: string|any; + required_features?: string | any; unique_names?: boolean; /** Optional */ @@ -44,7 +44,7 @@ interface plupload_settings { interface plupload_filters { mime_types?: plupload_filters_mime_types[]; - max_file_size?: number|string; + max_file_size?: number | string; prevent_duplicates?: boolean; } @@ -138,7 +138,7 @@ interface plupload_error extends plupload_response { } declare class plupload { - static Uploader(settings: plupload_settings):void; + static Uploader(settings: plupload_settings): void; static VERSION: string; @@ -178,7 +178,7 @@ declare class plupload { /** Methods */ init(): any; - setOption(option: string|any, value?: any): any; + setOption(option: string | any, value?: any): any; getOption(option?: string): any; refresh(): any; start(): any; @@ -194,4 +194,263 @@ declare class plupload { unbind(name: string, func: any): any; unbindAll(): any; destroy(): any; + + /** Utility methods **/ + + /** + * Executes the callback function for each item in array/object. If you return false in the + * callback it will break the loop. + * + * @method each + * @static + * @param {Object} obj Object to iterate. + * @param {function} callback Callback function to execute for each item. + */ + static each(obj: Object, callback: Function): void; + + /** + * Returns the absolute x, y position of an Element. The position will be returned in a object with x, y fields. + * + * @method getPos + * @static + * @param {Element} node HTML element or element id to get x, y position from. + * @param {Element} root Optional root element to stop calculations at. + * @return {object} Absolute position of the specified element object with x, y fields. + */ + static getPos(node: Element, root: Element): Object; + + /** + * Returns the size of the specified node in pixels. + * + * @method getSize + * @static + * @param {Node} node Node to get the size of. + * @return {Object} Object with a w and h property. + */ + static getSize(node: Node): Object; + + /** + * Encodes the specified string. + * + * @method xmlEncode + * @static + * @param {String} s String to encode. + * @return {String} Encoded string. + */ + static xmlEncode(str: string): string; + + /** + * Forces anything into an array. + * + * @method toArray + * @static + * @param {Object} obj Object with length field. + * @return {Array} Array object containing all items. + */ + static toArray(obj: Object): Array; + + /** + * Find an element in array and return its index if present, otherwise return -1. + * + * @method inArray + * @static + * @param {mixed} needle Element to find + * @param {Array} array + * @return {Int} Index of the element, or -1 if not found + */ + static inArray(needle: any, array: Array): number; + + /** + Recieve an array of functions (usually async) to call in sequence, each function + receives a callback as first argument that it should call, when it completes. Finally, + after everything is complete, main callback is called. Passing truthy value to the + callback as a first argument will interrupt the sequence and invoke main callback + immediately. + @method inSeries + @static + @param {Array} queue Array of functions to call in sequence + @param {Function} cb Main callback that is called in the end, or in case of error + */ + static inSeries(queue: Array, callback: Function): void; + + /** + * Extends the language pack object with new items. + * + * @method addI18n + * @static + * @param {Object} pack Language pack items to add. + * @return {Object} Extended language pack object. + */ + static addI18n(pack: Object): Object; + + /** + * Translates the specified string by checking for the english string in the language pack lookup. + * + * @method translate + * @static + * @param {String} str String to look for. + * @return {String} Translated string or the input string if it wasn't found. + */ + static translate(str: string): string; + + /** + * Pseudo sprintf implementation - simple way to replace tokens with specified values. + * + * @param {String} str String with tokens + * @return {String} String with replaced tokens + */ + static sprintf(str: string): string; + + /** + * Checks if object is empty. + * + * @method isEmptyObj + * @static + * @param {Object} obj Object to check. + * @return {Boolean} + */ + static isEmptyObj(obj: Object): boolean; + + /** + * Checks if specified DOM element has specified class. + * + * @method hasClass + * @static + * @param {Object} obj DOM element like object to add handler to. + * @param {String} name Class name + */ + static hasClass(obj: Object, name: string): any; + + /** + * Adds specified className to specified DOM element. + * + * @method addClass + * @static + * @param {Object} obj DOM element like object to add handler to. + * @param {String} name Class name + */ + static addClass(obj: Object, name: string): any; + + /** + * Removes specified className from specified DOM element. + * + * @method removeClass + * @static + * @param {Object} obj DOM element like object to add handler to. + * @param {String} name Class name + */ + static removeClass(obj: Object, name: string): any; + + /** + * Returns a given computed style of a DOM element. + * + * @method getStyle + * @static + * @param {Object} obj DOM element like object. + * @param {String} name Style you want to get from the DOM element + */ + static getStyle(obj: Object, name: string): any; + + /** + * Adds an event handler to the specified object and store reference to the handler + * in objects internal Plupload registry (@see removeEvent). + * + * @method addEvent + * @static + * @param {Object} obj DOM element like object to add handler to. + * @param {String} name Name to add event listener to. + * @param {Function} callback Function to call when event occurs. + * @param {String} (optional) key that might be used to add specifity to the event record. + */ + static addEvent(obj: Object, name: string, callback: Function, key?: string); + + /** + * Remove event handler from the specified object. If third argument (callback) + * is not specified remove all events with the specified name. + * + * @method removeEvent + * @static + * @param {Object} obj DOM element to remove event listener(s) from. + * @param {String} name Name of event listener to remove. + * @param {Function|String} (optional) might be a callback or unique key to match. + */ + static removeEvent(obj: Object, name: string, optional?: Function | string); + + /** + * Remove all kind of events from the specified object + * + * @method removeAllEvents + * @static + * @param {Object} obj DOM element to remove event listeners from. + * @param {String} (optional) unique key to match, when removing events. + */ + static removeAllEvents(obj: Object, key?: string); + + /** + * Cleans the specified name from national characters (diacritics). The result will be a name with only a-z, 0-9 and _. + * + * @method cleanName + * @static + * @param {String} s String to clean up. + * @return {String} Cleaned string. + */ + static cleanName(name: string): string; + + /** + * Builds a full url out of a base URL and an object with items to append as query string items. + * + * @method buildUrl + * @static + * @param {String} url Base URL to append query string items to. + * @param {Object} items Name/value object to serialize as a querystring. + * @return {String} String with url + serialized query string items. + */ + static buildUrl(url, items): string; + + /** + * Formats the specified number as a size string for example 1024 becomes 1 KB. + * + * @method formatSize + * @static + * @param {Number} size Size to format as string. + * @return {String} Formatted size string. + */ + static formatSize(size: number): string; + + /** + * Parses the specified size string into a byte value. For example 10kb becomes 10240. + * + * @method parseSize + * @static + * @param {String|Number} size String to parse or number to just pass through. + * @return {Number} Size in bytes. + */ + static parseSize(size: number | string): number; + + + /** + * A way to predict what runtime will be choosen in the current environment with the + * specified settings. + * + * @method predictRuntime + * @static + * @param {Object|String} config Plupload settings to check + * @param {String} [runtimes] Comma-separated list of runtimes to check against + * @return {String} Type of compatible runtime + */ + static predictRuntime(config: Object | string, runtimes: string): string; + + /** + * Registers a filter that will be executed for each file added to the queue. + * If callback returns false, file will not be added. + * + * Callback receives two arguments: a value for the filter as it was specified in settings.filters + * and a file to be filtered. Callback is executed in the context of uploader instance. + * + * @method addFileFilter + * @static + * @param {String} name Name of the filter by which it can be referenced in settings.filters + * @param {String} cb Callback - the actual routine that every added file must pass + */ + static addFileFilter(name: string, cb: Function): void; }