all files / controls/vg-scrub-bar/vg-scrub-bar-current-time/ vg-scrub-bar-current-time.ts

76% Statements 19/25
25% Branches 1/4
50% Functions 4/8
80.95% Lines 17/21
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99                                                                                                                                                                    
import { Component, Input, ElementRef, OnInit, ViewEncapsulation, OnDestroy } from '@angular/core';
import { VgAPI } from '../../../core/services/vg-api';
import { Subscription } from 'rxjs/Subscription';
 
 
export class VgScrubBarCurrentTime implements OnInit, OnDestroy {
     vgFor: string;
     vgSlider: boolean = false;
 
    elem: HTMLElement;
    target: any;
 
    subscriptions: Subscription[] = [];
 
    constructor(ref: ElementRef, public API: VgAPI) {
        this.elem = ref.nativeElement;
    }
 
    ngOnInit() {
        if (this.API.isPlayerReady) {
            this.onPlayerReady();
        }
        else {
            this.subscriptions.push(this.API.playerReadyEvent.subscribe(() => this.onPlayerReady()));
        }
    }
 
    onPlayerReady() {
        this.target = this.API.getMediaById(this.vgFor);
    }
 
    getPercentage() {
        return this.target ? ((this.target.time.current * 100) / this.target.time.total) + '%' : '0%';
    }
 
    ngOnDestroy() {
        this.subscriptions.forEach(s => s.unsubscribe());
    }
static decorators: DecoratorInvocation[] = [
{ type: Component, args: [{
    selector: 'vg-scrub-bar-current-time',
    encapsulation: ViewEncapsulation.None,
    template: `<div class="background" [style.width]="getPercentage()"></div><span class="slider" *ngIf="vgSlider"></span>`,
    styles: [ `
        vg-scrub-bar-current-time {
            display: flex;
            width: 100%;
            height: 5px;
            pointer-events: none;
            position: absolute;
        }
 
        vg-scrub-bar-current-time .background {
            background-color: white;
        }
 
        vg-controls vg-scrub-bar-current-time {
            position: absolute;
            top: calc(50% - 3px);
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            border-radius: 2px;
        }
 
        vg-controls vg-scrub-bar-current-time .background {
            border: 1px solid white;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            border-radius: 2px;
        }
        
        vg-scrub-bar-current-time .slider{
            background: white;
            height: 15px;
            width: 15px;
            border-radius: 50%;
            box-shadow: 0px 0px 10px black;
            margin-top: -5px;
            margin-left: -10px;
        }
    ` ]
}, ] },
];
/** @nocollapse */
static ctorParameters: ({type: any, decorators?: DecoratorInvocation[]}|null)[] = [
{type: ElementRef, },
{type: VgAPI, },
];
static propDecorators: {[key: string]: DecoratorInvocation[]} = {
'vgFor': [{ type: Input },],
'vgSlider': [{ type: Input },],
};
}
 
interface DecoratorInvocation {
  type: Function;
  args?: any[];
}