From c3742cdad31b90fd29c23ac9f33a6377deaa76d5 Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Mon, 30 Oct 2017 01:27:25 -0400 Subject: [PATCH] Fix unspecified file extension when saving File was saved without an extension in Firefox, and Edge even added a txt extension by default! Also make some other extension handling hopefully more robust or at least consistent. --- TODO.md | 1 - src/functions.js | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/TODO.md b/TODO.md index af71a2b..db3676d 100644 --- a/TODO.md +++ b/TODO.md @@ -47,7 +47,6 @@ ### Issues -* Image is saved without `.png` file extension in Firefox, and Edge actually gives it a `.txt` extension! * [Stretch/skew and rotate don't update the canvas size](https://github.com/1j01/jspaint/issues/8) * ["Quick Undo" stopped working in Chrome](https://github.com/1j01/jspaint/issues/9) * If you open an image it resets the zoom but if you're on the magnification tool it doesn't update the options diff --git a/src/functions.js b/src/functions.js index 66413b7..63a9d56 100644 --- a/src/functions.js +++ b/src/functions.js @@ -185,7 +185,7 @@ function file_open(){ function file_save(){ if(file_name.match(/\.svg$/)){ - file_name += ".png"; + file_name = file_name.replace(/\.svg$/, "") + ".png"; //update_title()? return file_save_as(); } @@ -213,7 +213,7 @@ function file_save_as(){ }); }else{ canvas.toBlob(function(blob){ - var file_saver = saveAs(blob, file_name); + var file_saver = saveAs(blob, file_name.replace(/\.(bmp|png|gif|jpe?g|tiff|webp)$/, "") + ".png"); file_saver.onwriteend = function(){ // this won't fire in chrome saved = true; @@ -390,7 +390,7 @@ function render_history_as_gif(){ ); $win.$Button("Save", function(){ $win.close(); - saveAs(blob, file_name + " history.gif"); + saveAs(blob, file_name.replace(/\.(bmp|png|gif|jpe?g|tiff|webp)$/, "") + " history.gif"); }); $cancel.appendTo($win.$buttons); $win.center(); @@ -959,7 +959,7 @@ function set_as_wallpaper_centered(c){ }); }else{ c.toBlob(function(blob){ - saveAs(blob, file_name.replace(/\.(bmp|png|gif|jpe?g|tiff|webp)/, "") + " wallpaper.png"); + saveAs(blob, file_name.replace(/\.(bmp|png|gif|jpe?g|tiff|webp)$/, "") + " wallpaper.png"); }); } }