diff --git a/Changelog.md b/Changelog.md index b5caa5f..13e38bb 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## 2.1.4 - 2020-02-11 +### Changed +- Text shortening function improvement + ## 2.1.3 - 2020-02-10 ### Changed - Text shortening function became even better diff --git a/Taskodrome/Taskodrome.php b/Taskodrome/Taskodrome.php index 8a33581..4f50b28 100644 --- a/Taskodrome/Taskodrome.php +++ b/Taskodrome/Taskodrome.php @@ -11,7 +11,7 @@ public function register() $this->description = plugin_lang_get("description"); $this->page = 'config_page'; - $this->version = "2.1.3"; + $this->version = "2.1.4"; $this->requires = array( "MantisCore" => "2.0.0", ); diff --git a/Taskodrome/files/scripts/utils.js b/Taskodrome/files/scripts/utils.js index c2554e2..620ce83 100644 --- a/Taskodrome/files/scripts/utils.js +++ b/Taskodrome/files/scripts/utils.js @@ -141,17 +141,24 @@ function createShortenedText(text, maxWidth, maxHeight, isSingleLine) { break; } } - } else if (resWidth > maxWidth && textGr.textLines.length > 1) { - var longestLineIndex = textGr.textLines.length - 1; - for (var i = textGr.textLines.length - 2; i != -1; --i) - { - if (textGr.textLines[i].length > textGr.textLines[longestLineIndex].length) { - longestLineIndex = i; + } else if (resWidth > maxWidth) { + var longestLineLength = 0; + for (var i = 0; i != textGr.textLines.length; ++i) { + if (textGr.textLines[i].length > longestLineLength) { + longestLineLength = textGr.textLines[i].length; } } - for (var i = textGr.textLines.length - 1; i > longestLineIndex; --i) { - removeChars += textGr.textLines[i].length; + var avgCharWidth = resWidth / longestLineLength; + + for (var i = 0; i != textGr.textLines.length; ++i) { + if (removeChars != 0) { + removeChars += textGr.textLines[i].length; + } else if (textGr.textLines[i].length * avgCharWidth > maxWidth) { + removeChars = Math.max(Math.round((textGr.textLines[i].length * avgCharWidth - maxWidth) / avgCharWidth), subtract); + } else if (textGr.textLines[i].length == longestLineLength) { + removeChars = Math.max(Math.round((resWidth - maxWidth) / avgCharWidth), subtract); + } } }