Use css to truncate the page title

This commit is contained in:
Frederic Guillot
2015-06-15 20:30:30 -04:00
parent 100330c989
commit 57dd45839b
5 changed files with 13 additions and 5 deletions

View File

@@ -51,10 +51,10 @@ class Text extends \Core\Base
*/ */
public function truncate($value, $max_length = 85, $end = '[...]') public function truncate($value, $max_length = 85, $end = '[...]')
{ {
$length = strlen($value); $length = mb_strlen($value);
if ($length > $max_length) { if ($length > $max_length) {
return substr($value, 0, $max_length).' '.$end; return mb_substr($value, 0, $max_length).' '.$end;
} }
return $value; return $value;

View File

@@ -38,7 +38,7 @@
<?php else: ?> <?php else: ?>
<header> <header>
<nav> <nav>
<h1><?= $this->url->link('K<span>B</span>', 'app', 'index', array(), false, 'logo', t('Dashboard')).' '.$this->text->truncate($this->e($title)) ?> <h1><?= $this->url->link('K<span>B</span>', 'app', 'index', array(), false, 'logo', t('Dashboard')).' '.$this->e($title) ?>
<?php if (! empty($description)): ?> <?php if (! empty($description)): ?>
<span class="column-tooltip" title='<?= $this->e($this->text->markdown($description)) ?>'> <span class="column-tooltip" title='<?= $this->e($this->text->markdown($description)) ?>'>
<i class="fa fa-info-circle"></i> <i class="fa fa-info-circle"></i>

View File

@@ -653,13 +653,16 @@ div.ui-tooltip {
header { header {
margin-top: 10px; margin-top: 10px;
padding-bottom: 15px; padding-bottom: 15px;
clear: both;
border-bottom: 1px solid #dedede; border-bottom: 1px solid #dedede;
} }
header h1 { header h1 {
margin: 0; margin: 0;
padding: 0; padding: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 75%;
float: left; float: left;
} }

View File

@@ -2,13 +2,16 @@
header { header {
margin-top: 10px; margin-top: 10px;
padding-bottom: 15px; padding-bottom: 15px;
clear: both;
border-bottom: 1px solid #dedede; border-bottom: 1px solid #dedede;
} }
header h1 { header h1 {
margin: 0; margin: 0;
padding: 0; padding: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 75%;
float: left; float: left;
} }

View File

@@ -45,6 +45,8 @@ class TextHelperTest extends Base
$this->assertEquals('abc', $h->truncate('abc')); $this->assertEquals('abc', $h->truncate('abc'));
$this->assertEquals(str_repeat('a', 85).' [...]', $h->truncate(str_repeat('a', 200))); $this->assertEquals(str_repeat('a', 85).' [...]', $h->truncate(str_repeat('a', 200)));
$this->assertEquals('Настольная рекл [...]', $h->truncate('Настольная реклама в фудкорте ГЧ', 15));
} }
public function testContains() public function testContains()