add truncation tests for lineclamp
This commit is contained in:
Родитель
7948433a0e
Коммит
6e315a1103
|
@ -32,6 +32,8 @@ function autofillPlatform(context) {
|
|||
$this.find('#id_platform').val(platform);
|
||||
}).trigger('autofill');
|
||||
}
|
||||
|
||||
|
||||
autofillPlatform();
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
module('Truncation', {
|
||||
setup: function() {
|
||||
this.sandbox = tests.createSandbox();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
test('lineclamp: none', function() {
|
||||
var $src = $('<p>ballin</p>').appendTo(this.sandbox);
|
||||
|
||||
// Check that we return the same thing.
|
||||
equal($src.lineclamp(), $src);
|
||||
|
||||
// Check that `max-height` was not set.
|
||||
equal($src.css('max-height'), 'none');
|
||||
});
|
||||
|
||||
|
||||
test('lineclamp: round', function() {
|
||||
var $src = $('<p>ballin</p>').appendTo(this.sandbox);
|
||||
|
||||
// Set some arbitrary `line-height`.
|
||||
$src.css('line-height', '14.2px');
|
||||
|
||||
// Check that we return the same thing.
|
||||
equal($src.lineclamp(1), $src);
|
||||
|
||||
// If we're clamping one line with a `line-height` of 14.2px, then the
|
||||
// `max-height` should be 15px.
|
||||
equal($src.css('max-height'), '15px');
|
||||
});
|
||||
|
||||
|
||||
test('lineclamp: normal', function() {
|
||||
var $src = $('<p>ballin</p>').appendTo(this.sandbox);
|
||||
|
||||
// Set some arbitrary `line-height`.
|
||||
$src.css('line-height', '15px');
|
||||
|
||||
// Check that we return the same thing.
|
||||
equal($src.lineclamp(2), $src);
|
||||
|
||||
// If we're clamping two lines whose `line-height` are 15px, then the
|
||||
// `max-height` should be 50px.
|
||||
equal($src.css('max-height'), '30px');
|
||||
});
|
|
@ -65,12 +65,12 @@ $.fn.untruncate = function() {
|
|||
return this;
|
||||
};
|
||||
$.fn.lineclamp = function(lines) {
|
||||
// This function limits the number of visible `lines` of text.
|
||||
// Overflown text is gracefully ellipsed.
|
||||
// This function limits the number of visible `lines` of text. Overflown
|
||||
// text is gracefully ellipsed: http://en.wiktionary.org/wiki/ellipse#Verb.
|
||||
if (!lines) {
|
||||
return this;
|
||||
}
|
||||
return this.each(function() {
|
||||
if (!lines) {
|
||||
return;
|
||||
}
|
||||
var $this = $(this),
|
||||
lh = $this.css('line-height');
|
||||
if (lh.substr(-2) == 'px') {
|
||||
|
|
Загрузка…
Ссылка в новой задаче