fix: can't update title with translation result

fix: display h1 as block element
This commit is contained in:
Zhicheng Wang 2017-08-16 09:06:29 +08:00
parent f24553a6f8
commit e99af93a24
3 changed files with 7 additions and 12 deletions

View File

@ -1,7 +1,7 @@
<div *ngIf="type !== 'None'" class="toc-inner" [class.collapsed]="isCollapsed">
<div *ngIf="type === 'EmbeddedSimple'" class="toc-heading embedded">
Contents
目录
</div>
<button *ngIf="type === 'EmbeddedExpandable'" type="button" (click)="toggle(false)"
@ -9,7 +9,7 @@
title="Expand/collapse contents"
aria-label="Expand/collapse contents"
[attr.aria-pressed]="!isCollapsed">
Contents
目录
<md-icon class="rotating-icon" svgIcon="keyboard_arrow_right" [class.collapsed]="isCollapsed"></md-icon>
</button>

View File

@ -103,20 +103,16 @@ export class DocViewerComponent implements DoCheck, OnDestroy {
private addTitleAndToc(docId: string) {
this.tocService.reset();
let title = '';
const titleElements = this.hostElement.querySelectorAll('h1');
let titleEl;
if (titleElements.length > 1) {
titleEl = titleElements[1];
} else if (titleElements.length > 0) {
titleEl = titleElements[0];
}
const translatedTitleEl = this.hostElement.querySelector('h1[translation-result]');
const originalTitleEl = this.hostElement.querySelector('h1[translation-origin]');
const titleEl = translatedTitleEl || originalTitleEl;
// Only create TOC for docs with an <h1> title
// If you don't want a TOC, add "no-toc" class to <h1>
if (titleEl) {
title = (titleEl.innerText || titleEl.textContent).trim();
title = (titleEl.textContent).trim();
if (!/(no-toc|notoc)/i.test(titleEl.className)) {
this.tocService.genToc(this.hostElement, docId);
titleEl.insertAdjacentHTML('afterend', '<aio-toc class="embedded"></aio-toc>');
(originalTitleEl || translatedTitleEl).insertAdjacentHTML('afterend', '<aio-toc class="embedded"></aio-toc>');
}
}
this.titleService.setTitle(title ? `Angular - ${title}` : 'Angular');

View File

@ -8,7 +8,6 @@ body {
}
h1 {
display: inline-block;
font-size: 24px;
font-weight: 500;
margin: 8px 0px;