Skip to content

Commit ee4eb19

Browse files
matchishChristophWurst
authored andcommitted
Generate legacy image placeholder text by taking first letters
#19335 Signed-off-by: Sergey Shliakhov <husband.sergey@gmail.com> Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
1 parent defcbd9 commit ee4eb19

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

core/js/dist/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/js/dist/main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright (c) 2019 Serhii Shliakhov <shlyakhov.up@gmail.com>
3+
*
4+
* This file is licensed under the Affero General Public License version 3
5+
* or later.
6+
*
7+
* See the COPYING-README file.
8+
*
9+
*/
10+
11+
describe('jquery.placeholder tests', function() {
12+
13+
var $div;
14+
15+
beforeEach(function() {
16+
$('#testArea').append($('<div id="placeholderdiv">'));
17+
$div = $('#placeholderdiv');
18+
});
19+
20+
afterEach(function() {
21+
$div.remove();
22+
});
23+
24+
describe('placeholder text', function() {
25+
it('shows one first letter if one word in a input text', function() {
26+
spyOn($div, 'html');
27+
$div.imageplaceholder('Seed', 'Name')
28+
expect($div.html).toHaveBeenCalledWith('N');
29+
});
30+
31+
it('shows two first letters if two words in a input text', function() {
32+
spyOn($div, 'html');
33+
$div.imageplaceholder('Seed', 'First Second')
34+
expect($div.html).toHaveBeenCalledWith('FS');
35+
});
36+
37+
it('shows two first letters if more then two words in a input text', function() {
38+
spyOn($div, 'html');
39+
$div.imageplaceholder('Seed', 'First Second Middle')
40+
expect($div.html).toHaveBeenCalledWith('FS');
41+
});
42+
});
43+
});

core/src/jquery/placeholder.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ $.fn.imageplaceholder = function(seed, text, size) {
158158
this.css('font-size', (height * 0.55) + 'px')
159159

160160
if (seed !== null && seed.length) {
161-
this.html(text[0].toUpperCase())
161+
var placeholderText = text.split(' ', 2).map((word) => word[0].toUpperCase()).join('')
162+
this.html(placeholderText);
162163
}
163164
}
164165

0 commit comments

Comments
 (0)