Skip to content

Commit 534fb2a

Browse files
Merge pull request #301 from AuthenticEshkinKot/master
Text shortening function improvement
2 parents d2a30bd + 303815b commit 534fb2a

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

Changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## 2.1.4 - 2020-02-11
8+
### Changed
9+
- Text shortening function improvement
10+
711
## 2.1.3 - 2020-02-10
812
### Changed
913
- Text shortening function became even better

Taskodrome/Taskodrome.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function register()
1111
$this->description = plugin_lang_get("description");
1212
$this->page = 'config_page';
1313

14-
$this->version = "2.1.3";
14+
$this->version = "2.1.4";
1515
$this->requires = array(
1616
"MantisCore" => "2.0.0",
1717
);

Taskodrome/files/scripts/utils.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,24 @@ function createShortenedText(text, maxWidth, maxHeight, isSingleLine) {
141141
break;
142142
}
143143
}
144-
} else if (resWidth > maxWidth && textGr.textLines.length > 1) {
145-
var longestLineIndex = textGr.textLines.length - 1;
146-
for (var i = textGr.textLines.length - 2; i != -1; --i)
147-
{
148-
if (textGr.textLines[i].length > textGr.textLines[longestLineIndex].length) {
149-
longestLineIndex = i;
144+
} else if (resWidth > maxWidth) {
145+
var longestLineLength = 0;
146+
for (var i = 0; i != textGr.textLines.length; ++i) {
147+
if (textGr.textLines[i].length > longestLineLength) {
148+
longestLineLength = textGr.textLines[i].length;
150149
}
151150
}
152151

153-
for (var i = textGr.textLines.length - 1; i > longestLineIndex; --i) {
154-
removeChars += textGr.textLines[i].length;
152+
var avgCharWidth = resWidth / longestLineLength;
153+
154+
for (var i = 0; i != textGr.textLines.length; ++i) {
155+
if (removeChars != 0) {
156+
removeChars += textGr.textLines[i].length;
157+
} else if (textGr.textLines[i].length * avgCharWidth > maxWidth) {
158+
removeChars = Math.max(Math.round((textGr.textLines[i].length * avgCharWidth - maxWidth) / avgCharWidth), subtract);
159+
} else if (textGr.textLines[i].length == longestLineLength) {
160+
removeChars = Math.max(Math.round((resWidth - maxWidth) / avgCharWidth), subtract);
161+
}
155162
}
156163
}
157164

0 commit comments

Comments
 (0)