import { Component, NgModule, ElementRef, ViewChild, ViewEncapsulation } from '@angular/core'; import { IonicModule, NavParams, PopoverController } from 'ionic-angular'; @Component({ template: ` Athelas Charter Iowan Palatino San Francisco Seravek Times New Roman `, }) export class PopoverRadioPage { background: string; contentEle: any; textEle: any; fontFamily: string; colors: any = { 'white': { 'bg': 'rgb(255, 255, 255)', 'fg': 'rgb(0, 0, 0)' }, 'tan': { 'bg': 'rgb(249, 241, 228)', 'fg': 'rgb(0, 0, 0)' }, 'grey': { 'bg': 'rgb(76, 75, 80)', 'fg': 'rgb(255, 255, 255)' }, 'black': { 'bg': 'rgb(0, 0, 0)', 'fg': 'rgb(255, 255, 255)' }, }; constructor(private navParams: NavParams) { } ngOnInit() { if (this.navParams.data) { this.contentEle = this.navParams.data.contentEle; this.textEle = this.navParams.data.textEle; this.background = this.getColorName(this.contentEle.style.backgroundColor); this.setFontFamily(); } } getColorName(background: any) { let colorName = 'white'; if (!background) return 'white'; for(var key in this.colors) { if (this.colors[key].bg == background) { colorName = key; } } return colorName; } setFontFamily() { if (this.textEle.style.fontFamily) { this.fontFamily = this.textEle.style.fontFamily.replace(/'/g, ""); } } changeBackground(color: any) { this.background = color; this.contentEle.style.backgroundColor = this.colors[color].bg; this.textEle.style.color = this.colors[color].fg; } changeFontSize(direction: string) { this.textEle.style.fontSize = direction; } changeFontFamily() { if (this.fontFamily) this.textEle.style.fontFamily = this.fontFamily; } } @Component({ templateUrl: 'main.html' }) export class ApiDemoPage { @ViewChild('popoverContent', {read: ElementRef}) content: ElementRef; @ViewChild('popoverText', {read: ElementRef}) text: ElementRef; constructor(private popoverCtrl: PopoverController) {} presentRadioPopover(ev: UIEvent) { let popover = this.popoverCtrl.create(PopoverRadioPage, { contentEle: this.content.nativeElement, textEle: this.text.nativeElement }); popover.present({ ev: ev }); } } @Component({ template: '', styleUrls: ['style.css'], encapsulation: ViewEncapsulation.None }) export class ApiDemoApp { root = ApiDemoPage; } @NgModule({ declarations: [ PopoverRadioPage, ApiDemoApp, ApiDemoPage ], imports: [ IonicModule.forRoot(ApiDemoApp) ], bootstrap: [IonicApp], entryComponents: [ ApiDemoPage ] }) export class AppModule {}