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

View File

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

View File

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