@@ -144,39 +144,53 @@ var ViewStack = module.exports = Backbone.View.extend({
144144 if ( ! poppedView )
145145 poppedView = currentView ;
146146
147- if ( ! options . animated ) {
148- if ( poppedView . onPop ) poppedView . onPop ( ) ;
149- poppedView . trigger ( 'pop' ) ;
150- return self . _popView ( poppedView ) ;
147+ if ( _ . isFunction ( poppedView . confirmPop ) ) {
148+ return poppedView . confirmPop ( function ( confirm ) { return pop ( confirm ) ; } ) ;
149+ } else {
150+ return pop ( ) ;
151151 }
152152
153- self . _popView ( poppedView , false ) ;
154-
155- if ( ! options . animatedName ) {
156- poppedView . $el . one ( 'webkitAnimationEnd mozAnimationEnd msAnimationEnd animationend' , function ( e ) {
157- if ( poppedView . onPop )
158- poppedView . onPop ( ) ;
153+
154+ function pop ( confirm ) {
155+ if ( confirm === false )
156+ throw new Error ( "The popView was interrupted" ) ;
157+
158+ if ( ! options . animated ) {
159+ if ( poppedView . onPop ) poppedView . onPop ( ) ;
159160 poppedView . trigger ( 'pop' ) ;
160- poppedView . destroy ( ) ;
161- poppedView . trigger ( "deactive" ) ;
162- } ) ;
163- } else {
164- // Viene usata nei casi di più animazioni nella view. Cos' mi assicuro di distruggerla solo dopo aver
165- // terminato l'animazione desiderata
166- poppedView . $el . on ( 'webkitAnimationEnd mozAnimationEnd msAnimationEnd animationend' , function ( e ) {
167- if ( e && e . originalEvent && e . originalEvent . animationName == options . animatedName ) {
168- poppedView . $el . off ( 'webkitAnimationEnd mozAnimationEnd msAnimationEnd animationend' ) ;
161+ return self . _popView ( poppedView ) ;
162+ }
163+
164+ self . _popView ( poppedView , false ) ;
165+
166+ if ( ! options . animatedName ) {
167+ poppedView . $el . one ( 'webkitAnimationEnd mozAnimationEnd msAnimationEnd animationend' , function ( e ) {
169168 if ( poppedView . onPop )
170169 poppedView . onPop ( ) ;
171170 poppedView . trigger ( 'pop' ) ;
172171 poppedView . destroy ( ) ;
173172 poppedView . trigger ( "deactive" ) ;
174- }
175- } ) ;
173+ } ) ;
174+ } else {
175+ // Viene usata nei casi di più animazioni nella view. Cos' mi assicuro di distruggerla solo dopo aver
176+ // terminato l'animazione desiderata
177+ poppedView . $el . on ( 'webkitAnimationEnd mozAnimationEnd msAnimationEnd animationend' , function ( e ) {
178+ if ( e && e . originalEvent && e . originalEvent . animationName == options . animatedName ) {
179+ poppedView . $el . off ( 'webkitAnimationEnd mozAnimationEnd msAnimationEnd animationend' ) ;
180+ if ( poppedView . onPop )
181+ poppedView . onPop ( ) ;
182+ poppedView . trigger ( 'pop' ) ;
183+ poppedView . destroy ( ) ;
184+ poppedView . trigger ( "deactive" ) ;
185+ }
186+ } ) ;
187+ }
188+ poppedView . $el . addClass ( 'pop' ) ;
189+
190+ return poppedView ;
176191 }
177- poppedView . $el . addClass ( 'pop' ) ;
178192
179- return poppedView ;
193+ return this ;
180194 } ,
181195
182196 // Update page URL
0 commit comments