From 418116c1cc14d7c2108fdaa893c41fda54fd677e Mon Sep 17 00:00:00 2001 From: Boris Dalstein Date: Mon, 14 Sep 2020 17:12:34 +0200 Subject: [PATCH] Change default size units from 'b,Kb,Mb' to ' B, kB, MB' (#239) --- CHANGELOG.md | 6 +++++- README.md | 2 +- src/js/easymde.js | 14 ++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8275195..fda26dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,10 @@ All notable changes to easymde will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - +## [Unreleased] +### Fixed +- Corrected default size units from `b,Kb,Mb` to ` B, KB, MB` ([#239]). + ## [2.11.0] - 2020-07-16 ### Added - Support for Node.js 14. @@ -155,6 +158,7 @@ Project forked from [SimpleMDE](https://github.com/sparksuite/simplemde-markdown - Cursor not always showing in "text" mode over the edit field +[#239]: https://github.com/Ionaru/easy-markdown-editor/issues/239 [#178]: https://github.com/Ionaru/easy-markdown-editor/issues/178 [#136]: https://github.com/Ionaru/easy-markdown-editor/issues/136 [#126]: https://github.com/Ionaru/easy-markdown-editor/issues/126 diff --git a/README.md b/README.md index 4af2687..2aa1b7e 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ easyMDE.value('New input for **EasyMDE**'); - **sbOnDrop**: Status message displayed when the user drops a file in the text area. Defaults to `Uploading images #images_names#`. - **sbProgress**: Status message displayed to show uploading progress. Defaults to `Uploading #file_name#: #progress#%`. - **sbOnUploaded**: Status message displayed when the image has been uploaded. Defaults to `Uploaded #image_name#`. - - **sizeUnits**: A comma-separated list of units used to display messages with human-readable file sizes. Defaults to `b,Kb,Mb`. + - **sizeUnits**: A comma-separated list of units used to display messages with human-readable file sizes. Defaults to ` B, KB, MB` (example: `218 KB`). You can use `B,KB,MB` instead if you prefer without whitespaces (`218KB`). - **errorMessages**: Errors displayed to the user, using the `errorCallback` option, where `#image_name#`, `#image_size#` and `#image_max_size#` will replaced by their respective values, that can be used for customization or internationalization: - **noFileGiven**: The server did not receive any file from the user. Defaults to `You must select a file.`. - **typeNotAllowed**: The user send a file type which doesn't match the `imageAccept` list, or the server returned this error code. Defaults to `This image type is not allowed.`. diff --git a/src/js/easymde.js b/src/js/easymde.js index f04076a..6a62914 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -1296,10 +1296,12 @@ function _cleanBlock(cm) { } /** - * Convert a number of bytes to a human-readable file size. + * Convert a number of bytes to a human-readable file size. If you desire + * to add a space between the value and the unit, you need to add this space + * to the given units. * @param bytes {integer} A number of bytes, as integer. Ex: 421137 - * @param units {number[]} An array of human-readable units, ie. ['b', 'Kb', 'Mb'] - * @returns string A human-readable file size. Ex: '412Kb' + * @param units {number[]} An array of human-readable units, ie. [' B', ' K', ' MB'] + * @returns string A human-readable file size. Ex: '412 KB' */ function humanFileSize(bytes, units) { if (Math.abs(bytes) < 1024) { @@ -1585,7 +1587,7 @@ var imageTexts = { sbOnDrop: 'Uploading image #images_names#...', sbProgress: 'Uploading #file_name#: #progress#%', sbOnUploaded: 'Uploaded #image_name#', - sizeUnits: 'b,Kb,Mb', + sizeUnits: ' B, KB, MB', }; /** @@ -2058,7 +2060,7 @@ EasyMDE.prototype.render = function (el) { }, self.options.autosave.submit_delay || self.options.autosave.delay || 1000); }); } - + function handleImages() { if (options.previewImagesInEditor === false) { @@ -2101,7 +2103,7 @@ EasyMDE.prototype.render = function (el) { handleImages(); }); - + this.onWindowResize = function() { handleImages();