File

app/dxa/dxa-entity/views/highlighted-content-views/highlighted-content-main/highlighted-content-main.component.ts

Implements

OnInit OnDestroy

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector div[highlighted-content-main]
styleUrls ./highlighted-content-main.component.scss
templateUrl ./highlighted-content-main.component.html

Index

Properties
Methods
Inputs
HostBindings

Constructor

constructor(idGenerator: IdGeneratorService, highlightedContentService: HighlightedContentService, resizeContentService: ResizeContentService, constantsService: ConstantsService, document)
Parameters :
Name Type Optional
idGenerator IdGeneratorService No
highlightedContentService HighlightedContentService No
resizeContentService ResizeContentService No
constantsService ConstantsService No
document No

Inputs

entity

HostBindings

class

Methods

ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
Private playVideo
playVideo()
Returns : void
Private textTruncation
textTruncation()
Returns : void

Properties

componentId
Default value : this.idGenerator.getId()
data
Type : HighlightedContentData
descTextLength
Type : number
Default value : 150
videoId
Type : string
import { Component, OnInit, Input, HostBinding, Inject, OnDestroy, ChangeDetectionStrategy } from '@angular/core';
import { IdGeneratorService } from 'src/app/core/services/id-generator.service';
import { HighlightedContentData } from 'src/app/core/interfaces/interfaces.component';
import { HighlightedContentService } from '../highlighted-content.service';
import { ResizeContentService } from 'src/app/core/services/resize-service/resize-content.service';
import { ConstantsService } from 'src/app/shared/constants/constants.service';
import { DOCUMENT } from '@angular/common';

type linkType = 'button' | 'text' | 'missing';

@Component({
	selector: 'div[highlighted-content-main]',
	templateUrl: './highlighted-content-main.component.html',
	styleUrls: ['./highlighted-content-main.component.scss'],
	changeDetection: ChangeDetectionStrategy.OnPush
})
export class HighlightedContentMainComponent implements OnInit, OnDestroy {

	@Input() entity;

	data: HighlightedContentData;
	videoId: string;
	descTextLength = 150;
	componentId = this.idGenerator.getId();

	@HostBinding('class') get class() { return 'col-md-12 space-between'; }

	constructor(
		private idGenerator: IdGeneratorService,
		private highlightedContentService: HighlightedContentService,
		private resizeContentService: ResizeContentService,
		private constantsService: ConstantsService,
		@Inject(DOCUMENT) private document
	) { }

	ngOnInit() {
		if (this.entity) {
			this.data = this.highlightedContentService.parseJson(this.entity);
			this.videoId = this.idGenerator.getId();
		}

		this.textTruncation();
		this.resizeContentService.registerCallback(this.componentId, () => this.textTruncation());
	}

	ngOnDestroy(): void {
		this.resizeContentService.destroyCallback(this.componentId);
	}

	private textTruncation(): void {
		const currentWidth = window.innerWidth || this.document.documentElement.clientWidth;

		if (currentWidth >= this.constantsService.BOOTSTRAP_BREAKPOINTS.LG && currentWidth < this.constantsService.BOOTSTRAP_BREAKPOINTS.XL) {
			this.descTextLength = 120;
		} else if (currentWidth >= this.constantsService.BOOTSTRAP_BREAKPOINTS.XL) {
			this.descTextLength = 400;
		} else {
			this.descTextLength = 9999;
		}
	}

	private playVideo() {
		const video = <any>document.getElementById(this.videoId);
		if (video.paused) {
			video.play();
			this.highlightedContentService.videoPlayPauseText = 'PAUSE';
		} else {
			video.pause();
			this.highlightedContentService.videoPlayPauseText = 'PLAY';
		}
	}
}
<ng-container *ngIf="data">

  <h2 class="overview-title" *ngIf="data.title">{{data.title}}</h2>

  <div class="highlighted-content row">
    <div class="col-md-12"
      [ngClass]="[data.fiftyFiftyTemplate ? 'col-lg-6' : 'col-lg-8', data.rightImage ? 'order-lg-2' : '']">
      <div class="box-image">
        <div video-player [videoJSON]="data.videojson" *ngIf="data.mediaType === 'video'" ></div>
        <img [src]="data.imgURL" [alt]="data.imgAlt" *ngIf="data.mediaType === 'image'">
      </div>
    </div>

    <div class="col-md-12" [ngClass]="[data.fiftyFiftyTemplate ? 'col-lg-6' : 'col-lg-4']">
      <div class="box-text" [ngClass]="data.colorScheme">
        <div class="deck" *ngIf="data.deck">
          {{data.deck}}
        </div>
        <div class="description-title">
          {{data.descriptionTitle}}
        </div>
        <div class="description">
          {{data.description | truncatetext:descTextLength}}
        </div>
        <div class="highlighted-content-link" *ngIf="data.link?.linkObject">
          <a component-link [linkObject]="data.link.linkObject" [ngClass]="{'btn btn-green button': data.isButtonLink}"
            [showChevron]="!data.isButtonLink">
            {{data.link.title | uppercase }}
          </a>
        </div>
      </div>
    </div>
  </div>

</ng-container>

./highlighted-content-main.component.scss

@import "../highlighted-content.component.scss";

.overview-title {
    @include font-scale(32, light);
    margin-bottom: calc-rem(40);
}

video {
    width: 100%;
}

.highlighted-content {

    .box-image {
        @include aspect-ratio(16 9);

        @include media-breakpoint-up(lg) {
            min-height: 100%;
            max-height: 520px;
        }

        img {
            object-fit: cover;
        }
    }

    .box-text {
        padding: calc-rem(60);
        height: 100%;
        color: $white;

        @include media-breakpoint-up(lg) {
            max-height: 520px;
        }

        .deck {
            @include font-scale(14, uppercase);
            text-transform: uppercase;
            margin-bottom: calc-rem(20);
        }

        .description-title {
            margin-bottom: calc-rem(30);
            @include font-scale(32, light);
        }

        .description {
            margin-bottom: calc-rem(40);
            @include font-scale(16, light);
            word-wrap: break-word;
        }
    }
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""