namespace Views { export abstract class View < RootElement extends HTMLElement > { protected root : RootElement ; private _parent : HTMLElement ; private _activated : boolean ; constructor ( root ) { this . root = root ; } protected get parent ( ) : HTMLElement { return this . _parent ; } public attach ( parent , insertBefore ? ) { if ( parent == null ) throw "Parent element may not be null" ; if ( insertBefore ) { parent . insertBefore ( this . root , ( Utils . isElement ( insertBefore ) ) ? ( < Element > insertBefore ) : parent . firstElementChild ) ; } else { parent . appendChild ( this . root ) ; } this . _parent = parent ; } protected get activated ( ) : boolean { return this . _activated ; } public activate ( ) { this . _activated = true ; } public deactivate ( ) { this . _activated = false ; } public hide ( ) { this . root . classList . add ( 'hidden' ) ; } public show ( ) { this . root . classList . remove ( 'hidden' ) ; } public get hidden ( ) : boolean { return this . root . classList . contains ( 'hidden' ) ; } public set hidden ( hide ) { if ( hide ) this . hide ( ) ; else this . show ( ) ; } } }