11import Utils from '../../utils'
2+ import Platform from '../../platform'
23import { Vue } from '../../install'
34import { current as theme } from '../../theme'
45
@@ -111,6 +112,7 @@ class Modal {
111112
112113 this . __popstate = ( ) => {
113114 if (
115+ ! Platform . within . iframe &&
114116 window . history . state &&
115117 window . history . state . modalId &&
116118 window . history . state . modalId >= this . __modalId
@@ -129,8 +131,11 @@ class Modal {
129131 if ( this . selfDestroy ) {
130132 this . destroy ( )
131133 }
134+ if ( this . __closedByBackButton && this . onBackButton ) {
135+ this . onBackButton ( )
136+ }
132137 this . __onCloseHandlers . forEach (
133- handler => { console . log ( 'onCloseHandler' ) ; handler ( ) }
138+ handler => { handler ( ) }
134139 )
135140 if ( typeof this . __onClose === 'function' ) {
136141 this . __onClose ( )
@@ -153,12 +158,17 @@ class Modal {
153158 if ( this . __customElement ) {
154159 this . $backdrop . removeEventListener ( 'click' , this . close )
155160 }
156- window . removeEventListener ( 'popstate' , this . __popstate )
161+ if ( ! Platform . within . iframe ) {
162+ window . removeEventListener ( 'popstate' , this . __popstate )
163+ }
157164 Velocity ( this . $content , effect , options )
158165 }
159166 this . __modalId = ++ openedModalNumber
160- window . history . pushState ( { modalId : this . __modalId } , '' )
161- window . addEventListener ( 'popstate' , this . __popstate )
167+ this . __closedByBackButton = true
168+ if ( ! Platform . within . iframe ) {
169+ window . history . pushState ( { modalId : this . __modalId } , '' )
170+ window . addEventListener ( 'popstate' , this . __popstate )
171+ }
162172
163173 // finally show it
164174 Velocity ( this . $content , effect , options )
@@ -168,21 +178,27 @@ class Modal {
168178
169179 close ( onClose ) {
170180 this . __onClose = onClose
171- window . history . go ( - 1 )
181+ this . __closedByBackButton = false
182+ if ( Platform . within . iframe ) {
183+ this . __popstate ( )
184+ }
185+ else {
186+ window . history . go ( - 1 )
187+ }
172188 return this
173189 }
174190
175191 onShow ( handler ) {
176- this . __trigger ( 'onShow' , handler )
192+ this . __registerTrigger ( 'onShow' , handler )
177193 return this
178194 }
179195
180196 onClose ( handler ) {
181- this . __trigger ( 'onClose' , handler )
197+ this . __registerTrigger ( 'onClose' , handler )
182198 return this
183199 }
184200
185- __trigger ( event , handler ) {
201+ __registerTrigger ( event , handler ) {
186202 if ( typeof handler !== 'function' ) {
187203 throw new Error ( 'Modal ' + event + ' handler must be a function.' )
188204 }
0 commit comments