Comment out MetaService

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@51841 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
sofia.baltzi 2018-04-17 14:02:00 +00:00
parent 5c25acb63b
commit 9d2a28db41
3 changed files with 236 additions and 236 deletions

View File

@ -9,7 +9,7 @@ import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import {NavigationBarModule} from './sharedComponents/navigationBar.module'; import {NavigationBarModule} from './sharedComponents/navigationBar.module';
import { CookieLawModule } from './sharedComponents/cookie-law/cookie-law.module'; import { CookieLawModule } from './sharedComponents/cookie-law/cookie-law.module';
import {Meta} from './sharedComponents/metaService'; // import {Meta} from './sharedComponents/metaService';
// import { ErrorModule } from './error/error.module'; // import { ErrorModule } from './error/error.module';
import { ConfigurationService } from './utils/configuration/configuration.service'; import { ConfigurationService } from './utils/configuration/configuration.service';
import {MainSearchModule} from './searchPages/find/mainSearch.module'; import {MainSearchModule} from './searchPages/find/mainSearch.module';

View File

@ -1,15 +1,15 @@
import { NgModule} from '@angular/core'; // import { NgModule} from '@angular/core';
import { CommonModule } from '@angular/common'; // import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms'; // import { FormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router'; // import { RouterModule } from '@angular/router';
import {Meta} from './metaService'; // import {Meta} from './metaService';
//
//
@NgModule({ // @NgModule({
imports: [ // imports: [
CommonModule // CommonModule
//
], // ],
providers:[ Meta] // providers:[ Meta]
}) // })
export class MetaModule {} // export class MetaModule {}

View File

@ -1,220 +1,220 @@
/** // /**
* @license // * @license
* Copyright Google Inc. All Rights Reserved. // * Copyright Google Inc. All Rights Reserved.
* // *
* Use of this source code is governed by an MIT-style license that can be // * Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license // * found in the LICENSE file at https://angular.io/license
*/ // */
//
import {Injectable, Inject} from '@angular/core'; // import {Injectable, Inject} from '@angular/core';
// es6-modules are used here // // es6-modules are used here
import { ɵgetDOM as getDOM} from '@angular/platform-browser'; // import { ɵgetDOM as getDOM} from '@angular/platform-browser';
import {DOCUMENT} from '@angular/platform-browser'; // import {DOCUMENT} from '@angular/platform-browser';
/** // /**
* Represent meta element. // * Represent meta element.
* // *
* ### Example // * ### Example
* // *
* ```ts // * ```ts
* { name: 'application-name', content: 'Name of my application' }, // * { name: 'application-name', content: 'Name of my application' },
* { name: 'description', content: 'A description of the page', id: 'desc' } // * { name: 'description', content: 'A description of the page', id: 'desc' }
* // ... // * // ...
* // Twitter // * // Twitter
* { name: 'twitter:title', content: 'Content Title' } // * { name: 'twitter:title', content: 'Content Title' }
* // ... // * // ...
* // Google+ // * // Google+
* { itemprop: 'name', content: 'Content Title' }, // * { itemprop: 'name', content: 'Content Title' },
* { itemprop: 'description', content: 'Content Title' } // * { itemprop: 'description', content: 'Content Title' }
* // ... // * // ...
* // Facebook / Open Graph // * // Facebook / Open Graph
* { property: 'fb:app_id', content: '123456789' }, // * { property: 'fb:app_id', content: '123456789' },
* { property: 'og:title', content: 'Content Title' } // * { property: 'og:title', content: 'Content Title' }
* ``` // * ```
* // *
* @experimental // * @experimental
*/ // */
export interface MetaDefinition { // export interface MetaDefinition {
charset?: string; // charset?: string;
content?: string; // content?: string;
httpEquiv?: string; // httpEquiv?: string;
id?: string; // id?: string;
itemprop?: string; // itemprop?: string;
name?: string; // name?: string;
property?: string; // property?: string;
scheme?: string; // scheme?: string;
url?: string; // url?: string;
[prop: string]: string; // [prop: string]: string;
} // }
//
/** // /**
* A service that can be used to get and add meta tags. // * A service that can be used to get and add meta tags.
* // *
* @experimental // * @experimental
*/ // */
@Injectable() // @Injectable()
export class Meta { // export class Meta {
private _dom: any = getDOM(); // private _dom: any = getDOM();
constructor( @Inject(DOCUMENT) private _document: any) { } // constructor( @Inject(DOCUMENT) private _document: any) { }
/** // /**
* Sets the title of the page // * Sets the title of the page
*/ // */
setTitle(title: string) { // setTitle(title: string) {
this._document.title = title // this._document.title = title
} // }
/** // /**
* Adds a new meta tag to the dom. // * Adds a new meta tag to the dom.
* // *
* ### Example // * ### Example
* // *
* ```ts // * ```ts
* const name: MetaDefinition = {name: 'application-name', content: 'Name of my application'}; // * const name: MetaDefinition = {name: 'application-name', content: 'Name of my application'};
* const desc: MetaDefinition = {name: 'description', content: 'A description of the page'}; // * const desc: MetaDefinition = {name: 'description', content: 'A description of the page'};
* const tags: HTMLMetaElement[] = this.meta.addTags([name, desc]); // * const tags: HTMLMetaElement[] = this.meta.addTags([name, desc]);
* ``` // * ```
* // *
* @param tags // * @param tags
* @returns {HTMLMetaElement[]} // * @returns {HTMLMetaElement[]}
*/ // */
addTags(...tags: Array<MetaDefinition|MetaDefinition[]>): HTMLMetaElement[] { // addTags(...tags: Array<MetaDefinition|MetaDefinition[]>): HTMLMetaElement[] {
const presentTags = this._flattenArray(tags); // const presentTags = this._flattenArray(tags);
if (presentTags.length === 0) return []; // if (presentTags.length === 0) return [];
return presentTags.map((tag: MetaDefinition) => this._addInternal(tag)); // return presentTags.map((tag: MetaDefinition) => this._addInternal(tag));
} // }
//
/** // /**
* Gets the meta tag by the given selector. Returns element or null // * Gets the meta tag by the given selector. Returns element or null
* if there's no such meta element. // * if there's no such meta element.
* // *
* ### Example // * ### Example
* // *
* ```ts // * ```ts
* const meta: HTMLMetaElement = this.meta.getTag('name=description'); // * const meta: HTMLMetaElement = this.meta.getTag('name=description');
* const twitterMeta: HTMLMetaElement = this.meta.getTag('name="twitter:title"'); // * const twitterMeta: HTMLMetaElement = this.meta.getTag('name="twitter:title"');
* const fbMeta: HTMLMetaElement = this.meta.getTag('property="fb:app_id"'); // * const fbMeta: HTMLMetaElement = this.meta.getTag('property="fb:app_id"');
* ``` // * ```
* // *
* @param selector // * @param selector
* @returns {HTMLMetaElement} // * @returns {HTMLMetaElement}
*/ // */
// getTag(selector: string): HTMLMetaElement { // // getTag(selector: string): HTMLMetaElement {
// if (!selector) return null; // // if (!selector) return null;
// return this._dom.query(`meta[${selector}]`); // // return this._dom.query(`meta[${selector}]`);
// } // // }
getTag(attrSelector: string): HTMLMetaElement|null { // getTag(attrSelector: string): HTMLMetaElement|null {
if (!attrSelector) return null; // if (!attrSelector) return null;
return this._dom.querySelector(this._document, `meta[${attrSelector}]`); // return this._dom.querySelector(this._document, `meta[${attrSelector}]`);
} // }
//
/** // /**
* Updates the meta tag with the given selector. // * Updates the meta tag with the given selector.
* // *
* * ### Example // * * ### Example
* // *
* ```ts // * ```ts
* const meta: HTMLMetaElement = this.meta.updateTag('name=description', {name: 'description', // * const meta: HTMLMetaElement = this.meta.updateTag('name=description', {name: 'description',
* content: 'New description'}); // * content: 'New description'});
* console.log(meta.content); // 'New description' // * console.log(meta.content); // 'New description'
* ``` // * ```
* // *
* @param selector // * @param selector
* @param tag updated tag definition // * @param tag updated tag definition
* @returns {HTMLMetaElement} // * @returns {HTMLMetaElement}
*/ // */
updateTag(selector: string, tag: MetaDefinition): HTMLMetaElement { // updateTag(selector: string, tag: MetaDefinition): HTMLMetaElement {
const meta: HTMLMetaElement = this.getTag(selector); // const meta: HTMLMetaElement = this.getTag(selector);
if (!meta) { // if (!meta) {
// create element if it doesn't exist // // create element if it doesn't exist
return this._addInternal(tag); // return this._addInternal(tag);
} // }
return this._prepareMetaElement(tag, meta); // return this._prepareMetaElement(tag, meta);
} // }
//
updateMeta(name, content) { // updateMeta(name, content) {
const head = this._document.head; // const head = this._document.head;
let childNodesAsList = this._dom.childNodesAsList(head); // let childNodesAsList = this._dom.childNodesAsList(head);
let metaEl = childNodesAsList.find(el => el['attribs'] ? el['attribs'].name == name : false); // let metaEl = childNodesAsList.find(el => el['attribs'] ? el['attribs'].name == name : false);
if (metaEl) metaEl['attribs'].content = content; // if (metaEl) metaEl['attribs'].content = content;
} // }
updateProperty(property, content) { // updateProperty(property, content) {
const head = this._document.head; // const head = this._document.head;
let childNodesAsList = this._dom.childNodesAsList(head); // let childNodesAsList = this._dom.childNodesAsList(head);
let metaEl = childNodesAsList.find(el => el['attribs'] ? el['attribs'].property == property : false); // let metaEl = childNodesAsList.find(el => el['attribs'] ? el['attribs'].property == property : false);
if (metaEl) metaEl['attribs'].content = content; // if (metaEl) metaEl['attribs'].content = content;
} // }
//
/** // /**
* Removes meta tag with the given selector from the dom. // * Removes meta tag with the given selector from the dom.
* // *
* ### Example // * ### Example
* // *
* ```ts // * ```ts
* this.meta.removeTagBySelector('name=description'); // * this.meta.removeTagBySelector('name=description');
* ``` // * ```
* // *
* @param selector // * @param selector
*/ // */
removeTagBySelector(selector: string): void { // removeTagBySelector(selector: string): void {
const meta: HTMLMetaElement = this.getTag(selector); // const meta: HTMLMetaElement = this.getTag(selector);
this.removeTagElement(meta); // this.removeTagElement(meta);
} // }
//
/** // /**
* Removes given meta element from the dom. // * Removes given meta element from the dom.
* // *
* ### Example // * ### Example
* ```ts // * ```ts
* const elem: HTMLMetaElement = this.meta.getTag('name=description'); // * const elem: HTMLMetaElement = this.meta.getTag('name=description');
* this.meta.removeTagElement(elem); // * this.meta.removeTagElement(elem);
* ``` // * ```
* // *
* @param meta meta element // * @param meta meta element
*/ // */
removeTagElement(meta: HTMLMetaElement): void { // removeTagElement(meta: HTMLMetaElement): void {
if (meta) { // if (meta) {
this._removeMetaElement(meta); // this._removeMetaElement(meta);
} // }
} // }
//
private _addInternal(tag: MetaDefinition): HTMLMetaElement { // private _addInternal(tag: MetaDefinition): HTMLMetaElement {
const meta: HTMLMetaElement = this._createMetaElement(); // const meta: HTMLMetaElement = this._createMetaElement();
this._prepareMetaElement(tag, meta); // this._prepareMetaElement(tag, meta);
this._appendMetaElement(meta); // this._appendMetaElement(meta);
return meta; // return meta;
} // }
//
private _createMetaElement(): HTMLMetaElement { // private _createMetaElement(): HTMLMetaElement {
return this._dom.createElement('meta') as HTMLMetaElement; // return this._dom.createElement('meta') as HTMLMetaElement;
} // }
//
private _prepareMetaElement(tag: MetaDefinition, el: HTMLMetaElement): HTMLMetaElement { // private _prepareMetaElement(tag: MetaDefinition, el: HTMLMetaElement): HTMLMetaElement {
Object.keys(tag).forEach((prop: string) => this._dom.setAttribute(el, prop, tag[prop])); // Object.keys(tag).forEach((prop: string) => this._dom.setAttribute(el, prop, tag[prop]));
return el; // return el;
} // }
//
// private _appendMetaElement(meta: HTMLMetaElement): void { // // private _appendMetaElement(meta: HTMLMetaElement): void {
// const head = this._dom.getElementsByTagName(this._dom.defaultDoc(), 'head')[0]; // // const head = this._dom.getElementsByTagName(this._dom.defaultDoc(), 'head')[0];
// this._dom.appendChild(head, meta); // // this._dom.appendChild(head, meta);
// } // // }
private _appendMetaElement(meta: HTMLMetaElement): void { // private _appendMetaElement(meta: HTMLMetaElement): void {
const head = this._document.head; // const head = this._document.head;
this._dom.appendChild(head, meta); // this._dom.appendChild(head, meta);
} // }
private _removeMetaElement(meta: HTMLMetaElement): void { // private _removeMetaElement(meta: HTMLMetaElement): void {
const head = this._dom.parentElement(meta); // const head = this._dom.parentElement(meta);
this._dom.removeChild(head, meta); // this._dom.removeChild(head, meta);
} // }
//
private _flattenArray(input: any[], out: any[] = []): any[] { // private _flattenArray(input: any[], out: any[] = []): any[] {
if (input) { // if (input) {
for (let i = 0; i < input.length; i++) { // for (let i = 0; i < input.length; i++) {
const item: any = input[i]; // const item: any = input[i];
if (Array.isArray(item)) { // if (Array.isArray(item)) {
this._flattenArray(item, out); // this._flattenArray(item, out);
} else if (item) { // } else if (item) {
out.push(item); // out.push(item);
} // }
} // }
} // }
return out; // return out;
} // }
} // }