| 
									
										
										
										
											2016-03-26 12:18:13 -04:00
										 |  |  | // #docplaster
 | 
					
						
							|  |  |  | // #docregion
 | 
					
						
							| 
									
										
										
										
											2016-06-13 00:41:33 +02:00
										 |  |  | import { Directive, ElementRef, HostListener, Input } from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2016-03-26 12:18:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | @Directive({ | 
					
						
							| 
									
										
										
										
											2016-06-13 00:41:33 +02:00
										 |  |  |   selector: '[myHighlight]' | 
					
						
							| 
									
										
										
										
											2016-03-26 12:18:13 -04:00
										 |  |  | }) | 
					
						
							|  |  |  | export class HighlightDirective { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @Input('myHighlight') highlightColor: string; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  |   private el: HTMLElement; | 
					
						
							| 
									
										
										
										
											2016-03-26 12:18:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   constructor(el: ElementRef) { | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  |     this.el = el.nativeElement; | 
					
						
							| 
									
										
										
										
											2016-03-26 12:18:13 -04:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-13 00:41:33 +02:00
										 |  |  |   @HostListener('mouseenter') onMouseEnter() { | 
					
						
							|  |  |  |     this.highlight(this.highlightColor || 'cyan'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @HostListener('mouseleave') onMouseLeave() { | 
					
						
							|  |  |  |     this.highlight(null); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-03-26 12:18:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  |   private highlight(color: string) { | 
					
						
							|  |  |  |     this.el.style.backgroundColor = color; | 
					
						
							| 
									
										
										
										
											2016-03-26 12:18:13 -04:00
										 |  |  |   } | 
					
						
							|  |  |  | } |