File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -47,13 +47,24 @@ $(function () {
4747 }
4848
4949 function updateResults ( img , data ) {
50+ var fileName = currentFile . name
51+ var href = img . src
52+ var dataURLStart
5053 var content
5154 if ( ! ( img . src || img instanceof HTMLCanvasElement ) ) {
5255 content = $ ( '<span>Loading image file failed</span>' )
5356 } else {
57+ if ( ! href ) {
58+ href = img . toDataURL ( currentFile . type + 'REMOVEME' )
59+ // Check if file type is supported for the dataURL export:
60+ dataURLStart = 'data:' + currentFile . type
61+ if ( href . slice ( 0 , dataURLStart . length ) !== dataURLStart ) {
62+ fileName = fileName . replace ( / \. \w + $ / , '.png' )
63+ }
64+ }
5465 content = $ ( '<a target="_blank">' ) . append ( img )
55- . attr ( 'download' , currentFile . name )
56- . attr ( 'href' , img . src || img . toDataURL ( ) )
66+ . attr ( 'download' , fileName )
67+ . attr ( 'href' , href )
5768 }
5869 result . children ( ) . replaceWith ( content )
5970 if ( img . getContext ) {
You can’t perform that action at this time.
0 commit comments