import { Component , ViewContainerRef , Inject } from '@angular/core' ; import { DOCUMENT } from '@angular/platform-browser' ; import { Slideritem } from "./Slideritem" ; class @ Component ( { selector : 'Sliderpanel' , template : `<ng-content></ng-content>` } ) export class Sliderpanel { private el : any ; private viewContainer : ViewContainerRef ; private dom : HTMLBodyElement ; private sliders : Array < any > = [ ] ; constructor ( viewContainer , @ Inject ( DOCUMENT ) private doc ) { this . dom = doc . body ; this . viewContainer = viewContainer ; this . el = viewContainer . element . nativeElement ; } private getElementByClass ( element ) { var jq = jQuery ; return jq ( this . dom ) . find ( '.' + element , this . el ) [ 0 ] ; } private removeAllClassesFrom ( elementClass , selected ? ) { var element = this . getElementByClass ( elementClass ) ; if ( selected ) { jQuery ( element ) . removeClass ( 'selected' ) ; return ; } jQuery ( element ) . removeClass ( 'left' ) ; jQuery ( element ) . removeClass ( 'right' ) ; jQuery ( element ) . removeClass ( 'center' ) ; jQuery ( element ) . removeClass ( 'transition' ) ; } private addClassesTo ( elementClass , classesToAdd ) { var element = this . getElementByClass ( elementClass ) ; for ( var i = 0 ; i < classesToAdd . length ; i ++ ) { jQuery ( element ) . addClass ( classesToAdd [ i ] ) ; } } public slideToPage ( toClassName , i_direction ) { if ( toClassName == 'selected' ) return ; this . removeAllClassesFrom ( toClassName ) ; this . addClassesTo ( toClassName , [ "page" , i_direction ] ) ; var parent = jQuery ( this . getElementByClass ( toClassName ) ) . parent ( ) ; var grandparent = jQuery ( parent ) . parent ( ) ; var offsetWidth = jQuery ( grandparent ) . prop ( 'offsetWidth' ) ; this . removeAllClassesFrom ( toClassName ) ; this . addClassesTo ( toClassName , [ 'page' , 'transition' , 'center' ] ) ; this . removeAllClassesFrom ( 'selected' ) ; this . addClassesTo ( 'selected' , [ 'page' , 'transition' , i_direction === 'left' ? 'right' : 'left' ] ) ; this . removeAllClassesFrom ( 'selected' , true ) ; this . addClassesTo ( toClassName , [ 'selected' ] ) ; } public addSlider ( i_slider ) { this . sliders . push ( i_slider ) ; } }