2017-03-12 15:20:55 +00:00
|
|
|
import { Component, ElementRef, HostListener, OnInit, QueryList, ViewChild, ViewChildren } from '@angular/core';
|
2017-03-01 14:30:25 +00:00
|
|
|
import { Observable } from 'rxjs/Observable';
|
2017-03-13 18:08:23 -07:00
|
|
|
|
|
|
|
import { GaService } from 'app/shared/ga.service';
|
|
|
|
import { LocationService } from 'app/shared/location.service';
|
2017-03-01 14:30:25 +00:00
|
|
|
import { DocumentService, DocumentContents } from 'app/documents/document.service';
|
2017-03-05 21:25:41 +00:00
|
|
|
import { NavigationService, NavigationViews, NavigationNode } from 'app/navigation/navigation.service';
|
2017-03-13 19:58:31 +00:00
|
|
|
import { SearchService } from 'app/search/search.service';
|
2017-03-12 15:20:55 +00:00
|
|
|
import { SearchResultsComponent } from 'app/search/search-results/search-results.component';
|
2017-02-02 23:02:23 -08:00
|
|
|
|
2017-01-27 00:20:51 -08:00
|
|
|
@Component({
|
2017-02-02 12:10:47 -08:00
|
|
|
selector: 'aio-shell',
|
2017-03-06 15:08:34 +00:00
|
|
|
templateUrl: './app.component.html',
|
2017-01-27 00:20:51 -08:00
|
|
|
})
|
2017-03-01 14:30:25 +00:00
|
|
|
export class AppComponent implements OnInit {
|
2017-03-02 13:28:28 +00:00
|
|
|
readonly sideBySideWidth = 600;
|
2017-03-15 08:19:19 +11:00
|
|
|
readonly homeImageUrl = 'assets/images/logos/standard/logo-nav.png';
|
2017-03-02 13:28:28 +00:00
|
|
|
|
2017-02-15 11:22:37 -08:00
|
|
|
isHamburgerVisible = true; // always ... for now
|
2017-03-01 14:30:25 +00:00
|
|
|
isSideBySide = false;
|
|
|
|
|
|
|
|
currentDocument: Observable<DocumentContents>;
|
|
|
|
navigationViews: Observable<NavigationViews>;
|
2017-03-05 21:25:41 +00:00
|
|
|
selectedNodes: Observable<NavigationNode[]>;
|
2017-03-01 14:30:25 +00:00
|
|
|
|
2017-03-12 15:20:55 +00:00
|
|
|
@ViewChildren('searchBox, searchResults', { read: ElementRef })
|
|
|
|
searchElements: QueryList<ElementRef>;
|
|
|
|
|
|
|
|
@ViewChild(SearchResultsComponent)
|
|
|
|
searchResults: SearchResultsComponent;
|
2017-03-13 18:08:23 -07:00
|
|
|
|
2017-03-12 15:20:55 +00:00
|
|
|
constructor(
|
|
|
|
documentService: DocumentService,
|
|
|
|
gaService: GaService,
|
|
|
|
private locationService: LocationService,
|
|
|
|
navigationService: NavigationService,
|
|
|
|
private searchService: SearchService) {
|
2017-03-01 14:30:25 +00:00
|
|
|
this.currentDocument = documentService.currentDocument;
|
2017-03-13 18:08:23 -07:00
|
|
|
locationService.currentUrl.subscribe(url => gaService.locationChanged(url));
|
2017-03-01 14:30:25 +00:00
|
|
|
this.navigationViews = navigationService.navigationViews;
|
2017-03-06 10:13:49 +00:00
|
|
|
this.selectedNodes = navigationService.selectedNodes;
|
2017-03-01 14:30:25 +00:00
|
|
|
}
|
2017-02-15 11:22:37 -08:00
|
|
|
|
2017-03-01 14:30:25 +00:00
|
|
|
ngOnInit() {
|
2017-03-02 12:20:26 +00:00
|
|
|
this.searchService.initWorker('app/search/search-worker.js');
|
|
|
|
this.searchService.loadIndex();
|
|
|
|
|
2017-03-01 14:30:25 +00:00
|
|
|
this.onResize(window.innerWidth);
|
|
|
|
}
|
2017-02-15 11:22:37 -08:00
|
|
|
|
2017-03-12 14:07:49 +00:00
|
|
|
@HostListener('window:resize', ['$event.target.innerWidth'])
|
2017-03-01 14:30:25 +00:00
|
|
|
onResize(width) {
|
|
|
|
this.isSideBySide = width > this.sideBySideWidth;
|
|
|
|
}
|
2017-03-13 21:06:15 +00:00
|
|
|
|
|
|
|
@HostListener('click', ['$event.target', '$event.button', '$event.ctrlKey', '$event.metaKey'])
|
|
|
|
onClick(eventTarget: HTMLElement, button: number, ctrlKey: boolean, metaKey: boolean): boolean {
|
2017-03-12 15:20:55 +00:00
|
|
|
|
|
|
|
// Hide the search results if we clicked outside both the search box and the search results
|
|
|
|
if (this.searchResults) {
|
|
|
|
const hits = this.searchElements.filter(element => element.nativeElement.contains(eventTarget));
|
|
|
|
if (hits.length === 0) {
|
|
|
|
this.searchResults.hideResults();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deal with anchor clicks
|
2017-03-13 21:06:15 +00:00
|
|
|
if (eventTarget instanceof HTMLAnchorElement) {
|
|
|
|
return this.locationService.handleAnchorClick(eventTarget, button, ctrlKey, metaKey);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2017-01-27 00:20:51 -08:00
|
|
|
}
|