Skip to content

Commit

Permalink
Merge pull request #20634 from nextcloud/legacy-avatar-placeholder
Browse files Browse the repository at this point in the history
Generate legacy image placeholder text by taking first letters
  • Loading branch information
rullzer authored Apr 30, 2020
2 parents 7b923b8 + 09ecf4b commit 2139b29
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/js/dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/js/dist/main.js.map

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions core/js/tests/specs/jquery.placeholderSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright (c) 2019 Serhii Shliakhov <[email protected]>
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/

describe('jquery.placeholder tests', function() {

var $div;

beforeEach(function() {
$('#testArea').append($('<div id="placeholderdiv">'));
$div = $('#placeholderdiv');
});

afterEach(function() {
$div.remove();
});

describe('placeholder text', function() {
it('shows one first letter if one word in a input text', function() {
spyOn($div, 'html');
$div.imageplaceholder('Seed', 'Name')
expect($div.html).toHaveBeenCalledWith('N');
});

it('shows two first letters if two words in a input text', function() {
spyOn($div, 'html');
$div.imageplaceholder('Seed', 'First Second')
expect($div.html).toHaveBeenCalledWith('FS');
});

it('shows two first letters if more then two words in a input text', function() {
spyOn($div, 'html');
$div.imageplaceholder('Seed', 'First Second Middle')
expect($div.html).toHaveBeenCalledWith('FS');
});
});
});
3 changes: 2 additions & 1 deletion core/src/jquery/placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ $.fn.imageplaceholder = function(seed, text, size) {
this.css('font-size', (height * 0.55) + 'px')

if (seed !== null && seed.length) {
this.html(text[0].toUpperCase())
var placeholderText = text.split(' ', 2).map((word) => word[0].toUpperCase()).join('')
this.html(placeholderText);
}
}

Expand Down

0 comments on commit 2139b29

Please sign in to comment.