Skip to content

Commit

Permalink
* refactor(overlays): overlays now are enabled via ionViewDidEnter (#…
Browse files Browse the repository at this point in the history
…6811) closes #6753



overalys now are enabled via ionViewDidEnter

* style(overlays): fixed tslint error

fixed tslint error

* style(overlays): formatting

formatting

* refactor(overlays): minor refactor to match style

minor refactor to match style
  • Loading branch information
danbucholtz authored Jun 9, 2016
1 parent 7a3477b commit 2be96f2
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 64 deletions.
18 changes: 7 additions & 11 deletions src/components/action-sheet/action-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Transition, TransitionOptions} from '../../transitions/transition';
import {Config} from '../../config/config';
import {Icon} from '../icon/icon';
import {isPresent} from '../../util/util';
import {Key} from '../../util/key';
import {NavParams} from '../nav/nav-params';
import {ViewController} from '../nav/view-controller';

Expand Down Expand Up @@ -244,9 +245,9 @@ export class ActionSheet extends ViewController {
class ActionSheetCmp {
private d: any;
private descId: string;
private enabled: boolean;
private hdrId: string;
private id: number;
private created: number;

constructor(
private _viewCtrl: ViewController,
Expand All @@ -256,7 +257,6 @@ class ActionSheetCmp {
renderer: Renderer
) {
this.d = params.data;
this.created = Date.now();

if (this.d.cssClass) {
renderer.setElementClass(_elementRef.nativeElement, this.d.cssClass, true);
Expand Down Expand Up @@ -315,20 +315,21 @@ class ActionSheetCmp {
if (focusableEle) {
focusableEle.focus();
}
this.enabled = true;
}

@HostListener('body:keyup', ['$event'])
private _keyUp(ev: KeyboardEvent) {
if (this.isEnabled() && this._viewCtrl.isLast()) {
if (ev.keyCode === 27) {
if (this.enabled && this._viewCtrl.isLast()) {
if (ev.keyCode === Key.ESCAPE) {
console.debug('actionsheet, escape button');
this.bdClick();
}
}
}

click(button: any, dismissDelay?: number) {
if (!this.isEnabled()) {
if (! this.enabled ) {
return;
}

Expand All @@ -350,7 +351,7 @@ class ActionSheetCmp {
}

bdClick() {
if (this.isEnabled() && this.d.enableBackdropDismiss) {
if (this.enabled && this.d.enableBackdropDismiss) {
if (this.d.cancelButton) {
this.click(this.d.cancelButton, 1);

Expand All @@ -363,11 +364,6 @@ class ActionSheetCmp {
dismiss(role: any): Promise<any> {
return this._viewCtrl.dismiss(null, role);
}

isEnabled() {
let tm = this._config.getNumber('overlayCreatedDiff', 750);
return (this.created + tm < Date.now());
}
}

export interface ActionSheetOptions {
Expand Down
28 changes: 12 additions & 16 deletions src/components/alert/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Animation} from '../../animations/animation';
import {Transition, TransitionOptions} from '../../transitions/transition';
import {Config} from '../../config/config';
import {isPresent} from '../../util/util';
import {Key} from '../../util/key';
import {NavParams} from '../nav/nav-params';
import {ViewController} from '../nav/view-controller';

Expand Down Expand Up @@ -375,13 +376,13 @@ class AlertCmp {
inputs?: any[];
enableBackdropDismiss?: boolean;
};
private enabled: boolean;
private hdrId: string;
private id: number;
private subHdrId: string;
private msgId: string;
private inputType: string;
private created: number;
private lastClick: number;
private msgId: string;
private subHdrId: string;

constructor(
private _viewCtrl: ViewController,
Expand All @@ -404,7 +405,6 @@ class AlertCmp {
this.subHdrId = 'alert-subhdr-' + this.id;
this.msgId = 'alert-msg-' + this.id;
this.activeId = '';
this.created = Date.now();
this.lastClick = 0;

if (this.d.message) {
Expand Down Expand Up @@ -466,8 +466,8 @@ class AlertCmp {

@HostListener('body:keyup', ['$event'])
private _keyUp(ev: KeyboardEvent) {
if (this.isEnabled() && this._viewCtrl.isLast()) {
if (ev.keyCode === 13) {
if (this.enabled && this._viewCtrl.isLast()) {
if (ev.keyCode === Key.ENTER) {
if (this.lastClick + 1000 < Date.now()) {
// do not fire this click if there recently was already a click
// this can happen when the button has focus and used the enter
Expand All @@ -478,7 +478,7 @@ class AlertCmp {
this.btnClick(button);
}

} else if (ev.keyCode === 27) {
} else if (ev.keyCode === Key.ESCAPE) {
console.debug('alert, escape button');
this.bdClick();
}
Expand All @@ -495,10 +495,11 @@ class AlertCmp {
if (focusableEle) {
focusableEle.focus();
}
this.enabled = true;
}

btnClick(button: any, dismissDelay?: number) {
if (!this.isEnabled()) {
if (!this.enabled) {
return;
}

Expand All @@ -524,7 +525,7 @@ class AlertCmp {
}

rbClick(checkedInput: any) {
if (this.isEnabled()) {
if (this.enabled) {
this.d.inputs.forEach(input => {
input.checked = (checkedInput === input);
});
Expand All @@ -533,13 +534,13 @@ class AlertCmp {
}

cbClick(checkedInput: any) {
if (this.isEnabled()) {
if (this.enabled) {
checkedInput.checked = !checkedInput.checked;
}
}

bdClick() {
if (this.isEnabled() && this.d.enableBackdropDismiss) {
if (this.enabled && this.d.enableBackdropDismiss) {
let cancelBtn = this.d.buttons.find(b => b.role === 'cancel');
if (cancelBtn) {
this.btnClick(cancelBtn, 1);
Expand Down Expand Up @@ -576,11 +577,6 @@ class AlertCmp {
});
return values;
}

isEnabled() {
let tm = this._config.getNumber('overlayCreatedDiff', 750);
return (this.created + tm < Date.now());
}
}

export interface AlertOptions {
Expand Down
7 changes: 0 additions & 7 deletions src/components/loading/loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ export class Loading extends ViewController {
class LoadingCmp {
private d: any;
private id: number;
private created: number;
private showSpinner: boolean;

constructor(
Expand All @@ -182,7 +181,6 @@ class LoadingCmp {
renderer: Renderer
) {
this.d = params.data;
this.created = Date.now();

if (this.d.cssClass) {
renderer.setElementClass(_elementRef.nativeElement, this.d.cssClass, true);
Expand Down Expand Up @@ -215,11 +213,6 @@ class LoadingCmp {
dismiss(role: any): Promise<any> {
return this._viewCtrl.dismiss(null, role);
}

isEnabled() {
let tm = this._config.getNumber('overlayCreatedDiff', 750);
return (this.created + tm < Date.now());
}
}

export interface LoadingOptions {
Expand Down
20 changes: 8 additions & 12 deletions src/components/picker/picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Animation} from '../../animations/animation';
import {Transition, TransitionOptions} from '../../transitions/transition';
import {Config} from '../../config/config';
import {isPresent, isString, isNumber, clamp} from '../../util/util';
import {Key} from '../../util/key';
import {NavParams} from '../nav/nav-params';
import {ViewController} from '../nav/view-controller';
import {raf, cancelRaf, CSS, pointerCoord} from '../../util/dom';
Expand Down Expand Up @@ -459,7 +460,7 @@ class PickerColumnCmp {
class PickerDisplayCmp {
@ViewChildren(PickerColumnCmp) private _cols: QueryList<PickerColumnCmp>;
private d: PickerOptions;
private created: number;
private enabled: boolean;
private lastClick: number;
private id: number;

Expand All @@ -479,7 +480,6 @@ class PickerDisplayCmp {
}

this.id = (++pickerIds);
this.created = Date.now();
this.lastClick = 0;
}

Expand Down Expand Up @@ -544,8 +544,8 @@ class PickerDisplayCmp {

@HostListener('body:keyup', ['$event'])
private _keyUp(ev: KeyboardEvent) {
if (this.isEnabled() && this._viewCtrl.isLast()) {
if (ev.keyCode === 13) {
if (this.enabled && this._viewCtrl.isLast()) {
if (ev.keyCode === Key.ENTER) {
if (this.lastClick + 1000 < Date.now()) {
// do not fire this click if there recently was already a click
// this can happen when the button has focus and used the enter
Expand All @@ -556,7 +556,7 @@ class PickerDisplayCmp {
this.btnClick(button);
}

} else if (ev.keyCode === 27) {
} else if (ev.keyCode === Key.ESCAPE) {
console.debug('picker, escape button');
this.bdClick();
}
Expand All @@ -573,10 +573,11 @@ class PickerDisplayCmp {
if (focusableEle) {
focusableEle.focus();
}
this.enabled = true;
}

btnClick(button: any, dismissDelay?: number) {
if (!this.isEnabled()) {
if (!this.enabled) {
return;
}

Expand All @@ -602,7 +603,7 @@ class PickerDisplayCmp {
}

bdClick() {
if (this.isEnabled() && this.d.enableBackdropDismiss) {
if (this.enabled && this.d.enableBackdropDismiss) {
this.dismiss('backdrop');
}
}
Expand All @@ -623,11 +624,6 @@ class PickerDisplayCmp {
});
return selected;
}

isEnabled() {
let tm = this._config.getNumber('overlayCreatedDiff', 750);
return (this.created + tm < Date.now());
}
}

export interface PickerOptions {
Expand Down
11 changes: 3 additions & 8 deletions src/components/popover/popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ class PopoverCmp {
@ViewChild('viewport', {read: ViewContainerRef}) viewport: ViewContainerRef;

private d: any;
private enabled: boolean;
private id: number;
private created: number;
private showSpinner: boolean;

constructor(
Expand All @@ -183,7 +183,6 @@ class PopoverCmp {
private _viewCtrl: ViewController
) {
this.d = _navParams.data.opts;
this.created = Date.now();

if (this.d.cssClass) {
_renderer.setElementClass(_elementRef.nativeElement, this.d.cssClass, true);
Expand All @@ -210,6 +209,7 @@ class PopoverCmp {
if (document.activeElement) {
activeElement.blur();
}
this.enabled = true;
}

dismiss(role: any): Promise<any> {
Expand All @@ -222,15 +222,10 @@ class PopoverCmp {
}

bdClick() {
if (this.isEnabled() && this.d.enableBackdropDismiss) {
if (this.enabled && this.d.enableBackdropDismiss) {
this.dismiss('backdrop');
}
}

isEnabled() {
let tm = this._config.getNumber('overlayCreatedDiff', 750);
return (this.created + tm < Date.now());
}
}

export interface PopoverOptions {
Expand Down
13 changes: 4 additions & 9 deletions src/components/toast/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ const TOAST_POSITION_BOTTOM: string = 'bottom';
class ToastCmp implements AfterViewInit {
private d: any;
private descId: string;
private dismissTimeout: number = undefined;
private enabled: boolean;
private hdrId: string;
private created: number;
private id: number;
private dismissTimeout: number = undefined;

constructor(
private _nav: NavController,
Expand All @@ -176,7 +176,6 @@ class ToastCmp implements AfterViewInit {
) {

this.d = params.data;
this.created = Date.now();

if (this.d.cssClass) {
renderer.setElementClass(_elementRef.nativeElement, this.d.cssClass, true);
Expand Down Expand Up @@ -209,10 +208,11 @@ class ToastCmp implements AfterViewInit {
if (focusableEle) {
focusableEle.focus();
}
this.enabled = true;
}

cbClick() {
if (this.isEnabled()) {
if (this.enabled) {
this.dismiss('close');
}
}
Expand All @@ -223,11 +223,6 @@ class ToastCmp implements AfterViewInit {
return this._viewCtrl.dismiss(null, role);
}

isEnabled() {
let tm = this._config.getNumber('overlayCreatedDiff', 750);
return (this.created + tm < Date.now());
}

}

export interface ToastOptions {
Expand Down
5 changes: 5 additions & 0 deletions src/util/key.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum Key {
ENTER = <any> 13,
ESCAPE = <any> 27,
TAB = <any> 9
};
3 changes: 2 additions & 1 deletion src/util/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Injectable, NgZone} from '@angular/core';
import {Config} from '../config/config';
import {Form} from './form';
import {hasFocusedTextInput, nativeRaf, rafFrames, nativeTimeout} from './dom';
import {Key} from './key';

/**
* @name Keyboard
Expand Down Expand Up @@ -152,7 +153,7 @@ export class Keyboard {

// default is to add the focus-outline when the tab key is used
function keyDown(ev: KeyboardEvent) {
if (!isKeyInputEnabled && ev.keyCode === 9) {
if (!isKeyInputEnabled && ev.keyCode === Key.TAB) {
isKeyInputEnabled = true;
enableKeyInput();
}
Expand Down

0 comments on commit 2be96f2

Please sign in to comment.