@lxlib/theme
Version:
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.1.
260 lines • 17.5 kB
JavaScript
/**
* @fileoverview added by tsickle
* Generated from: src/services/title/title.service.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
import { DOCUMENT } from '@angular/common';
import { Inject, Injectable, Injector, Optional } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { ActivatedRoute, Router } from '@angular/router';
import { filter } from 'rxjs/operators';
import { LXLIB_I18N_TOKEN } from '../i18n/i18n';
import { MenuService } from '../menu/menu.service';
import * as i0 from "@angular/core";
import * as i1 from "@angular/platform-browser";
import * as i2 from "../menu/menu.service";
import * as i3 from "../i18n/i18n";
import * as i4 from "@angular/common";
export class TitleService {
/**
* @param {?} injector
* @param {?} title
* @param {?} menuSrv
* @param {?} i18nSrv
* @param {?} doc
*/
constructor(injector, title, menuSrv, i18nSrv, doc) {
this.injector = injector;
this.title = title;
this.menuSrv = menuSrv;
this.i18nSrv = i18nSrv;
this.doc = doc;
this._prefix = '';
this._suffix = '';
this._separator = ' - ';
this._reverse = false;
this.DELAY_TIME = 25;
/**
* 设置默认标题名
*/
this.default = `Not Page Name`;
this.i18n$ = this.i18nSrv.change.pipe(filter((/**
* @return {?}
*/
() => !!this.i18n$))).subscribe((/**
* @return {?}
*/
() => this.setTitle()));
}
/**
* 设置分隔符
* @param {?} value
* @return {?}
*/
set separator(value) {
this._separator = value;
}
/**
* 设置前缀
* @param {?} value
* @return {?}
*/
set prefix(value) {
this._prefix = value;
}
/**
* 设置后缀
* @param {?} value
* @return {?}
*/
set suffix(value) {
this._suffix = value;
}
/**
* 设置是否反转
* @param {?} value
* @return {?}
*/
set reverse(value) {
this._reverse = value;
}
/**
* @private
* @return {?}
*/
getByElement() {
/** @type {?} */
const el = (/** @type {?} */ ((this.doc.querySelector('.lxlib-default__content-title h1') || this.doc.querySelector('.page-header__title'))));
if (el) {
/** @type {?} */
let text = '';
el.childNodes.forEach((/**
* @param {?} val
* @return {?}
*/
val => {
if (!text && val.nodeType === 3) {
text = (/** @type {?} */ (val.textContent)).trim();
}
}));
return text || (/** @type {?} */ ((/** @type {?} */ (el.firstChild)).textContent)).trim();
}
return '';
}
/**
* @private
* @return {?}
*/
getByRoute() {
/** @type {?} */
let next = this.injector.get(ActivatedRoute);
while (next.firstChild)
next = next.firstChild;
/** @type {?} */
const data = (next.snapshot && next.snapshot.data) || {};
if (data.titleI18n && this.i18nSrv)
data.title = this.i18nSrv.fanyi(data.titleI18n);
return data.title;
}
/**
* @private
* @return {?}
*/
getByMenu() {
/** @type {?} */
const menus = this.menuSrv.getPathByUrl(this.injector.get(Router).url);
if (!menus || menus.length <= 0)
return '';
/** @type {?} */
const item = menus[menus.length - 1];
/** @type {?} */
let title;
if (item.i18n && this.i18nSrv)
title = this.i18nSrv.fanyi(item.i18n);
return title || (/** @type {?} */ (item.text));
}
/**
* @private
* @param {?=} title
* @return {?}
*/
_setTitle(title) {
if (!title) {
title = this.getByRoute() || this.getByMenu() || this.getByElement() || this.default;
}
if (title && !Array.isArray(title)) {
title = [title];
}
/** @type {?} */
let newTitles = [];
if (this._prefix) {
newTitles.push(this._prefix);
}
newTitles.push(...((/** @type {?} */ (title))));
if (this._suffix) {
newTitles.push(this._suffix);
}
if (this._reverse) {
newTitles = newTitles.reverse();
}
this.title.setTitle(newTitles.join(this._separator));
}
/**
* Set the document title, will be delay `25ms`, pls refer to [#1261](https://github.com/ng-alain/ng-alain/issues/1261)
* @param {?=} title
* @return {?}
*/
setTitle(title) {
setTimeout((/**
* @return {?}
*/
() => this._setTitle(title)), this.DELAY_TIME);
}
/**
* Set i18n key of the document title
* @param {?} key
* @param {?=} params
* @return {?}
*/
setTitleByI18n(key, params) {
this.setTitle(this.i18nSrv.fanyi(key, params));
}
/**
* @return {?}
*/
ngOnDestroy() {
this.i18n$.unsubscribe();
}
}
TitleService.decorators = [
{ type: Injectable, args: [{ providedIn: 'root' },] }
];
/** @nocollapse */
TitleService.ctorParameters = () => [
{ type: Injector },
{ type: Title },
{ type: MenuService },
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [LXLIB_I18N_TOKEN,] }] },
{ type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] }
];
/** @nocollapse */ TitleService.ɵprov = i0.ɵɵdefineInjectable({ factory: function TitleService_Factory() { return new TitleService(i0.ɵɵinject(i0.INJECTOR), i0.ɵɵinject(i1.Title), i0.ɵɵinject(i2.MenuService), i0.ɵɵinject(i3.LXLIB_I18N_TOKEN, 8), i0.ɵɵinject(i4.DOCUMENT)); }, token: TitleService, providedIn: "root" });
if (false) {
/**
* @type {?}
* @private
*/
TitleService.prototype._prefix;
/**
* @type {?}
* @private
*/
TitleService.prototype._suffix;
/**
* @type {?}
* @private
*/
TitleService.prototype._separator;
/**
* @type {?}
* @private
*/
TitleService.prototype._reverse;
/**
* @type {?}
* @private
*/
TitleService.prototype.i18n$;
/** @type {?} */
TitleService.prototype.DELAY_TIME;
/**
* 设置默认标题名
* @type {?}
*/
TitleService.prototype.default;
/**
* @type {?}
* @private
*/
TitleService.prototype.injector;
/**
* @type {?}
* @private
*/
TitleService.prototype.title;
/**
* @type {?}
* @private
*/
TitleService.prototype.menuSrv;
/**
* @type {?}
* @private
*/
TitleService.prototype.i18nSrv;
/**
* @type {?}
* @private
*/
TitleService.prototype.doc;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGl0bGUuc2VydmljZS5qcyIsInNvdXJjZVJvb3QiOiJuZzovL0BseGxpYi90aGVtZS8iLCJzb3VyY2VzIjpbInNyYy9zZXJ2aWNlcy90aXRsZS90aXRsZS5zZXJ2aWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsT0FBTyxFQUFFLFFBQVEsRUFBRSxNQUFNLGlCQUFpQixDQUFDO0FBQzNDLE9BQU8sRUFBRSxNQUFNLEV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