From 04df5805f2fa23abf8c6296290102f90f4157d09 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Sun, 21 Jun 2015 20:50:25 -0500 Subject: [PATCH] get highest modal instance --- ionic/components/action-menu/action-menu.js | 8 +++++++- ionic/components/alert/alert.scss | 1 - ionic/components/app/z-index.scss | 3 +-- ionic/components/modal/modal.js | 8 +++++++- ionic/components/modal/test/basic/index.js | 5 ++--- ionic/components/overlay/overlay.js | 22 +++++++++++++++------ 6 files changed, 33 insertions(+), 14 deletions(-) diff --git a/ionic/components/action-menu/action-menu.js b/ionic/components/action-menu/action-menu.js index 0a12853b6d..71b5f4e384 100644 --- a/ionic/components/action-menu/action-menu.js +++ b/ionic/components/action-menu/action-menu.js @@ -86,11 +86,17 @@ export class ActionMenu extends Overlay { * @return Promise that resolves when the action menu is open. */ static open(opts) { - return this.create(ActionMenu, opts); + return this.create(overlayType, ActionMenu, opts); + } + + static get() { + return Modal.getByType(overlayType); } } +const overlayType = 'actionmenu'; + /** * Animations for action sheet diff --git a/ionic/components/alert/alert.scss b/ionic/components/alert/alert.scss index cbdb89ce3f..b2007cea6b 100644 --- a/ionic/components/alert/alert.scss +++ b/ionic/components/alert/alert.scss @@ -15,7 +15,6 @@ $alert-content-margin: 24px !default; } .alert-container { - z-index: $z-index-alert; display: block; width: $alert-width; diff --git a/ionic/components/app/z-index.scss b/ionic/components/app/z-index.scss index 3f0238a945..d0ba2b24d1 100644 --- a/ionic/components/app/z-index.scss +++ b/ionic/components/app/z-index.scss @@ -8,6 +8,5 @@ $z-index-swipe-handle: 5 !default; $z-index-toolbar-border: 20 !default; $z-index-list-border: 50 !default; $z-index-aside-overlay: 80 !default; -$z-index-overlay: 100 !default; -$z-index-alert: 110 !default; +$z-index-overlay: 1000 !default; $z-index-click-block: 9999 !default; diff --git a/ionic/components/modal/modal.js b/ionic/components/modal/modal.js index d286d233e2..9bf5d041aa 100644 --- a/ionic/components/modal/modal.js +++ b/ionic/components/modal/modal.js @@ -23,11 +23,17 @@ export class Modal extends Overlay { /* Static Methods */ static open(ComponentType: Type, opts) { - return this.create(ComponentType, opts); + return this.create(overlayType, ComponentType, opts); + } + + static get() { + return Modal.getByType(overlayType); } } +const overlayType = 'modal'; + /** * Animations for modals diff --git a/ionic/components/modal/test/basic/index.js b/ionic/components/modal/test/basic/index.js index da1445b725..de7c92afa5 100644 --- a/ionic/components/modal/test/basic/index.js +++ b/ionic/components/modal/test/basic/index.js @@ -90,9 +90,8 @@ export class ModalFirstPage { } closeModal() { - // TODO(maxlynch): Figure out a much better way to get the parent ContactModal - var m = this.nav._nav.elementRef.parentView._view.context; - m.close(); + let modal = Modal.get(); + modal.close(); } openActionMenu() { diff --git a/ionic/components/overlay/overlay.js b/ionic/components/overlay/overlay.js index 9a38e20053..d8a2d2bc7a 100644 --- a/ionic/components/overlay/overlay.js +++ b/ionic/components/overlay/overlay.js @@ -7,7 +7,7 @@ import * as util from 'ionic/util'; export class Overlay { constructor() { - this.zIndex = rootIndex; + this.zIndex = Root_ZIndex; for (let i = 0; i < overlayStack.length; i++) { this.zIndex = overlayStack[i].zIndex + 1; } @@ -17,7 +17,7 @@ export class Overlay { /* Instance Methods */ open(opts) { let animationName = (opts && opts.animation) || this.options.enterAnimation; - let enterAnimation = Animation.create(this.domElement, animationName); + let enterAnimation = Animation.create(this._domElement, animationName); enterAnimation.before.addClass('show-overlay'); ClickBlock(true, enterAnimation.duration() + 200); @@ -33,7 +33,7 @@ export class Overlay { close(opts) { return new Promise(resolve => { let animationName = (opts && opts.animation) || this.options.leaveAnimation; - let leavingAnimation = Animation.create(this.domElement, animationName); + let leavingAnimation = Animation.create(this._domElement, animationName); leavingAnimation.after.removeClass('show-overlay'); ClickBlock(true, leavingAnimation.duration() + 200); @@ -58,12 +58,13 @@ export class Overlay { /* Static Methods */ - static create(ComponentType: Type, opts) { + static create(overlayType, ComponentType: Type, opts) { return new Promise((resolve, reject) => { IonicRoot.append(ComponentType).then(ref => { let overlay = ref.instance; + overlay._type = overlayType; overlay._dispose = ref.dispose; - overlay.domElement = ref.elementRef.domElement; + overlay._domElement = ref.elementRef.domElement; overlay.extendOptions(opts); overlay.open(opts); resolve(overlay); @@ -75,7 +76,16 @@ export class Overlay { }); } + static getByType(overlayType) { + for (let i = overlayStack.length - 1; i >= 0; i--) { + if (overlayType == overlayStack[i]._type) { + return overlayStack[i]; + } + } + return null; + } + } let overlayStack = []; -const rootIndex = 100; +const Root_ZIndex = 1000;