@@ -46,8 +46,9 @@ var ViewStack = module.exports = Backbone.View.extend({
4646 // pushView
4747 // Aggiunge una view all'applicazione con z-Index più alto
4848 pushView : function pushView ( newView , options ) {
49- if ( ! options )
50- options = { } ;
49+ options = _ . defaults ( options || {
50+ deactivateCurrentView : true
51+ } ) ;
5152
5253 // Controllo se è la stessa view che sto cercando di pushare
5354 if ( this . _current === newView ) return this ;
@@ -76,7 +77,7 @@ var ViewStack = module.exports = Backbone.View.extend({
7677 this . $el . append ( newView . el ) ;
7778
7879 // Lancio l'evento onDeactivate se è impostato
79- if ( this . _current && this . _current . onDeactivate )
80+ if ( this . _current && this . _current . onDeactivate && options . deactivateCurrentView === true )
8081 this . _current . onDeactivate ( ) ;
8182
8283 // setto la view Corrente
@@ -102,7 +103,7 @@ var ViewStack = module.exports = Backbone.View.extend({
102103 this . $el . append ( newView . el ) ;
103104
104105 // Lancio l'evento onDeactivate se è impostato
105- if ( this . _current && this . _current . onDeactivate )
106+ if ( this . _current && this . _current . onDeactivate && options . deactivateCurrentView === true )
106107 this . _current . onDeactivate ( ) ;
107108
108109 // setto la view Corrente
@@ -111,13 +112,14 @@ var ViewStack = module.exports = Backbone.View.extend({
111112 newView . render ( ) ;
112113
113114 if ( this . _current && this . _current . onActivate )
114- this . _current . onActivate ( ) ;
115+ this . _current . onActivate ( true ) ;
115116
116117 }
117118
118119 // Scateno l'evento active per dire alla view che è attiva
119- if ( this . _current )
120+ if ( this . _current ) {
120121 this . _current . trigger ( "active" ) ;
122+ }
121123
122124 this
123125 . refreshUrl ( options . url )
@@ -151,6 +153,8 @@ var ViewStack = module.exports = Backbone.View.extend({
151153
152154 if ( ! options . animatedName ) {
153155 poppedView . $el . one ( 'webkitAnimationEnd mozAnimationEnd msAnimationEnd animationend' , function ( e ) {
156+ if ( poppedView . onPop )
157+ poppedView . onPop ( ) ;
154158 poppedView . trigger ( 'pop' ) ;
155159 poppedView . destroy ( ) ;
156160 poppedView . trigger ( "deactive" ) ;
@@ -161,6 +165,8 @@ var ViewStack = module.exports = Backbone.View.extend({
161165 poppedView . $el . on ( 'webkitAnimationEnd mozAnimationEnd msAnimationEnd animationend' , function ( e ) {
162166 if ( e && e . originalEvent && e . originalEvent . animationName == options . animatedName ) {
163167 poppedView . $el . off ( 'webkitAnimationEnd mozAnimationEnd msAnimationEnd animationend' ) ;
168+ if ( poppedView . onPop )
169+ poppedView . onPop ( ) ;
164170 poppedView . trigger ( 'pop' ) ;
165171 poppedView . destroy ( ) ;
166172 poppedView . trigger ( "deactive" ) ;
@@ -239,14 +245,21 @@ var ViewStack = module.exports = Backbone.View.extend({
239245 // Assegno la nuova view corrente
240246 this . _current = this . _stack [ this . _stack . length - 1 ] ;
241247 if ( this . _current && this . _current . onActivate )
242- this . _current . onActivate ( ) ;
248+ this . _current . onActivate ( false ) ;
243249 }
244250
245251 this
246252 . refreshUrl ( )
247253 . trigger ( 'popped' , poppedView ) ;
248254
249255 return poppedView ;
256+ } ,
257+
258+ exists : function exists ( classType ) {
259+ var result = _ . find ( this . _stack , function ( aView ) {
260+ return aView instanceof classType ;
261+ } ) ;
262+ return ! ! result ;
250263 }
251264
252265} ) ;
@@ -265,4 +278,4 @@ ViewStack.middleware = function middleware(options){
265278 next ( ) ;
266279 }
267280
268- } ;
281+ }
0 commit comments