Skip to content

Commit

Permalink
chore(alert): add keyup to body via HostListener
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Mar 5, 2016
1 parent a2f858b commit 70efe7d
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions ionic/components/alert/alert.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, ElementRef, Renderer} from 'angular2/core';
import {Component, ElementRef, Renderer, HostListener} from 'angular2/core';
import {NgClass, NgSwitch, NgIf, NgFor} from 'angular2/common';

import {Animation} from '../../animations/animation';
Expand Down Expand Up @@ -271,7 +271,6 @@ class AlertCmp {
subHdrId: string;
msgId: string;
inputType: string;
keyUp: any;

constructor(
private _viewCtrl: ViewController,
Expand Down Expand Up @@ -342,26 +341,24 @@ class AlertCmp {
if (checkedInput) {
this.activeId = checkedInput.id;
}
}

let self = this;
self.keyUp = function(ev) {
if (ev.keyCode === 13) {
console.debug('alert, enter button');
let button = self.d.buttons[self.d.buttons.length - 1];
self.btnClick(button);

} else if (ev.keyCode === 27) {
console.debug('alert, escape button');
self.bdClick();
}
};
@HostListener('body:keyup', ['$event'])
private _keyUp(ev: KeyboardEvent) {
if (ev.keyCode === 13) {
console.debug('alert, enter button');
let button = this.d.buttons[this.d.buttons.length - 1];
this.btnClick(button);

document.addEventListener('keyup', this.keyUp);
} else if (ev.keyCode === 27) {
console.debug('alert, escape button');
this.bdClick();
}
}

onPageDidEnter() {
let activeElement: any = document.activeElement;
if (activeElement) {
if (document.activeElement) {
activeElement.blur();
}

Expand Down Expand Up @@ -441,14 +438,6 @@ class AlertCmp {
});
return values;
}

onPageWillLeave() {
document.removeEventListener('keyup', this.keyUp);
}

ngOnDestroy() {
document.removeEventListener('keyup', this.keyUp);
}
}

export interface AlertOptions {
Expand Down

0 comments on commit 70efe7d

Please sign in to comment.