Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 4c922d7

Browse files
committed
move duplcate event triggering to one method, transition degredation to _getTransitionHandler
1 parent 67779af commit 4c922d7

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

js/jquery.mobile.navigation.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -686,35 +686,42 @@ define( [
686686
},
687687

688688
_getTransitionHandler: function( transition ) {
689+
transition = $.mobile._maybeDegradeTransition( transition );
690+
691+
//find the transition handler for the specified transition. If there
692+
//isn't one in our transitionHandlers dictionary, use the default one.
693+
//call the handler immediately to kick-off the transition.
689694
return $.mobile.transitionHandlers[ transition ] || $.mobile.defaultTransitionHandler;
690695
},
691696

692-
// TODO make private once change has been defined in the widget1
693-
transition: function( toPage, fromPage, options ) {
694-
var transition = options.transition,
695-
reverse = options.reverse,
696-
deferred = options.deferred,
697-
TransitionHandler,
698-
promise;
697+
// TODO move into transition handlers?
698+
_triggerTransitionEvents: function( to, from, prefix ) {
699+
prefix = prefix || "";
699700

700701
// TODO decide if these events should in fact be triggered on the container
701-
if ( fromPage ) {
702+
if ( from ) {
702703
//trigger before show/hide events
703704
// TODO deprecate nextPage in favor of next
704-
this._triggerWithDeprecated( "beforehide", {nextPage: toPage}, fromPage );
705+
this._triggerWithDeprecated( prefix + "hide", {nextPage: to}, from );
705706
}
706707

707708
// TODO deprecate prevPage in favor of previous
708-
this._triggerWithDeprecated( "beforeshow", {prevPage: fromPage || $( "" )}, toPage );
709+
this._triggerWithDeprecated( prefix + "show", {prevPage: from || $( "" )}, to );
710+
},
711+
712+
// TODO make private once change has been defined in the widget
713+
transition: function( toPage, fromPage, options ) {
714+
var transition = options.transition,
715+
reverse = options.reverse,
716+
deferred = options.deferred,
717+
TransitionHandler,
718+
promise;
719+
720+
this._triggerTransitionEvents( toPage, fromPage, "before" );
709721

710722
// TODO maybe put this in a binding to events above *outside* the widget
711723
this._hideLoading();
712724

713-
transition = $.mobile._maybeDegradeTransition( transition );
714-
715-
//find the transition handler for the specified transition. If there
716-
//isn't one in our transitionHandlers dictionary, use the default one.
717-
//call the handler immediately to kick-off the transition.
718725
TransitionHandler = this._getTransitionHandler( transition );
719726

720727
promise = (new TransitionHandler( transition, reverse, toPage, fromPage ))
@@ -726,15 +733,7 @@ define( [
726733
});
727734

728735
promise.done($.proxy(function() {
729-
//trigger show/hide events
730-
if ( fromPage ) {
731-
// TODO deprecate nextPage in favor of next
732-
this._triggerWithDeprecated( "hide", {nextPage: toPage}, fromPage );
733-
}
734-
735-
// TODO deprecate prevPage in favor of previous
736-
//trigger pageshow, define prevPage as either fromPage or empty jQuery obj
737-
this._triggerWithDeprecated( "show", {prevPage: fromPage || $( "" )}, toPage );
736+
this._triggerTransitionEvents( toPage, fromPage );
738737
}, this));
739738
}
740739

0 commit comments

Comments
 (0)