# All files / src/lib/services/document document.service.ts

36.95% Statements 17/46
22.58% Branches 14/62
44.44% Functions 4/9
30% Lines 12/40

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    741x
    1x
    1x
    1x
    1x

    1x

    1x
    3x
    1x

    2x

     import { Injectable } from '@angular/core';
    import { LayoutClass } from '../../models/layout.model';
    I
    @Injectable({
    	providedIn: 'root'
    })
    export class DocumentService {
    	constructor() {}

    	getHTMLElementByClassName(element: HTMLElement, className: string): HTMLElement {
    		while (!!element && element !== document.body) {
    			if (element.className.includes(className)) {
    				return element;
    			}
    			element = element.parentElement;
    		}
    		return null;
    	}

    	toggleFullscreen(elementId: string) {
    		const document: any = window.document;
    		const fs = document.getElementById(elementId);
    		if (
    			!document.fullscreenElement &&
    			!document.mozFullScreenElement &&
    			!document.webkitFullscreenElement &&
    			!document.msFullscreenElement
    		) {
    			if (fs.requestFullscreen) {
    				fs.requestFullscreen();
    			} else if (fs.msRequestFullscreen) {
    				fs.msRequestFullscreen();
    			} else if (fs.mozRequestFullScreen) {
    				fs.mozRequestFullScreen();
    			} else if (fs.webkitRequestFullscreen) {
    				fs.webkitRequestFullscreen();
    			}
    		} else {
    			if (document.exitFullscreen) {
    				document.exitFullscreen();
    			} else if (document.msExitFullscreen) {
    				document.msExitFullscreen();
    			} else if (document.mozCancelFullScreen) {
    				document.mozCancelFullScreen();
    			} else if (document.webkitExitFullscreen) {
    				document.webkitExitFullscreen();
    			}
    		}
    	}

    	removeAllBigElementClass() {
    		const elements: HTMLCollectionOf<Element> = document.getElementsByClassName(LayoutClass.BIG_ELEMENT);
    		while (elements.length > 0) {
    			this.removeBigElementClass(elements[0]);
    		}
    	}

    	removeBigElementClass(element: HTMLElement | Element) {
    		element?.classList.remove(LayoutClass.BIG_ELEMENT);
    	}

    	toggleBigElementClass(element: HTMLElement | Element) {
    		if (element?.className.includes(LayoutClass.BIG_ELEMENT)) {
    			this.removeBigElementClass(element);
    		} else {
    			element.classList.add(LayoutClass.BIG_ELEMENT);
    		}
    	}

    	isSmallElement(element: HTMLElement | Element): boolean {
    		return element?.className.includes(LayoutClass.SMALL_ELEMENT);
    	}
    }