import { Injectable } from '@angular/core' ; @ Injectable ( ) export class DomHandler { public addClass ( element , className ) { if ( element . classList ) element . classList . add ( className ) ; else element . className += ' ' + className ; } public removeClass ( element , className ) { if ( element . classList ) element . classList . remove ( className ) ; else element . className = element . className . replace ( new RegExp ( '(^|\\b)' + className . split ( ' ' ) . join ( '|' ) + '(\\b|$)' , 'gi' ) , ' ' ) ; } public hasClass ( element , className ) { if ( element . classList ) return element . classList . contains ( className ) ; else return new RegExp ( '(^| )' + className + '( |$)' , 'gi' ) . test ( element . className ) ; } public find ( element , selector ) { return element . querySelectorAll ( selector ) ; } public findSingle ( element , selector ) { return element . querySelector ( selector ) ; } public invokeElementMethod ( element , methodName , args ? ) { ( element as any ) [ methodName ] . apply ( element , args ) ; } }