Skip to content

Commit

Permalink
Text shortening function improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
AuthenticEshkinKot committed Feb 11, 2020
1 parent c3ec79f commit 303815b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Taskodrome/Taskodrome.php
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
Expand Down
23 changes: 15 additions & 8 deletions Taskodrome/files/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit 303815b

Please sign in to comment.