Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
6,345 additions
and
6,801 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,37 @@ | ||
import $ from 'jquery'; | ||
import PromiseImpl from 'promise-polyfill'; | ||
|
||
/** | ||
* @method readFileAsDataURL | ||
* | ||
* read contents of file as representing URL | ||
* | ||
* @param {File} file | ||
* @return {Promise} - then: dataUrl | ||
*/ | ||
export function readFileAsDataURL(file) { | ||
return $.Deferred((deferred) => { | ||
export function readFileAsDataURL(file: File): Promise<string> { | ||
return new PromiseImpl((resolve, reject) => { | ||
$.extend(new FileReader(), { | ||
onload: (e) => { | ||
const dataURL = e.target.result; | ||
deferred.resolve(dataURL); | ||
resolve(dataURL); | ||
}, | ||
onerror: (err) => { | ||
deferred.reject(err); | ||
reject(err); | ||
}, | ||
}).readAsDataURL(file); | ||
}).promise(); | ||
}); | ||
} | ||
|
||
/** | ||
* @method createImage | ||
* | ||
* create `<image>` from url string | ||
* | ||
* @param {String} url | ||
* @return {Promise} - then: $image | ||
*/ | ||
export function createImage(url) { | ||
return $.Deferred((deferred) => { | ||
export function createImage(url: string): Promise<any> { | ||
return new PromiseImpl((resolve, reject) => { | ||
const $img = $('<img>'); | ||
|
||
$img.one('load', () => { | ||
$img.off('error abort'); | ||
deferred.resolve($img); | ||
resolve($img); | ||
}).one('error abort', () => { | ||
$img.off('load').detach(); | ||
deferred.reject($img); | ||
reject($img); | ||
}).css({ | ||
display: 'none', | ||
}).appendTo(document.body).attr('src', url); | ||
}).promise(); | ||
}); | ||
} |
Oops, something went wrong.