Showing with 36 additions and 308 deletions.
  1. +36 −173 js/widgets/popup.js
  2. +0 −6 tests/unit/popup/index.html
  3. +0 −48 tests/unit/popup/popup_interaction.js
  4. +0 −81 tests/unit/popup/popup_quick_succession.js
@@ -391,18 +391,12 @@ define( [ "jquery",
}
});

// Popup manager, whose policy is to ignore requests for opening popups when a popup is already in
// the process of opening, or already open
$.mobile.popup.popupManager = {
// array of: {
// open: true/false
// popup: popup
// args: args for _open
// }
_actionQueue: [],
_inProgress: false,
_haveNavHook: false,
_currentlyOpenPopup: null,
_myOwnHashChange: false,
_myUrl: "",
_waitingForPopup: false,
_abort: false,

// Call _onHashChange if the hash changes /after/ the popup is on the screen
// Note that placing the popup on the screen can itself cause a hashchange,
@@ -477,188 +471,57 @@ define( [ "jquery",
$.mobile.activePage.unbind( "pagebeforechange.popup" );
},

_inArray: function( action ) {
var self = this,
idx = -1;

$.each( self._actionQueue, function( arIdx, value ) {
if ( value.open === action.open && value.popup === action.popup ) {
idx = arIdx;
return false;
}
return true;
});

return idx;
},

_completeAction: function() {
var self = this,
current = self._actionQueue.shift();

self._currentlyOpenPopup = ( current.open ? current.popup : null );

if ( self._actionQueue.length === 0 && !current.open && self._haveNavHook ) {
self._haveNavHook = false;
self._myOwnHashChange = true;
self._navUnhook( current.abort );
} else {
self._inProgress = false;
}

if ( self._actionQueue.length > 0 ) {
self._runSingleAction();
}
},

_continueWithAction: function() {
var self = this,
signal, fn, args,
actionComplete = false;

if ( self._actionQueue[0].open ) {
if ( self._currentlyOpenPopup ) {
self._actionQueue.unshift( { open: false, popup: self._currentlyOpenPopup } );
self._inProgress = false;
self._runSingleAction();
return;
}
signal = "opened";
fn = "_open";
args = self._actionQueue[0].args;
} else {
signal = "closed";
fn = "_close";
args = [];
}

if ( self._yScroll !== undefined && self._actionQueue[0].open ) {
if ( self._yScroll !== $( window ).scrollTop() ) {
window.scrollTo( 0, self._yScroll );
}
}
self._yScroll = $( window ).scrollTop();

self._actionQueue[0].waitingForPopup = true;
self._actionQueue[0].popup.element.one( signal, function() {
self._completeAction();
actionComplete = true;
});
self._actionQueue[0].popup[fn].apply( self._actionQueue[0].popup, args );
if ( !actionComplete && self._actionQueue[0].abort ) {
self._actionQueue[0].popup._immediate();
}
},

_runSingleAction: function() {
push: function( popup, args ) {
var self = this;

if ( !self._inProgress ) {
self._inProgress = true;
if ( self._haveNavHook || !self._actionQueue[0].open ) {
self._continueWithAction();
} else {
self._navHook( function() {
self._haveNavHook = true;
self._continueWithAction();
});
}
}
},
if ( !self._currentlyOpenPopup ) {
self._currentlyOpenPopup = popup;

push: function( popup, args ) {
var self = this,
newAction = { open: true, popup: popup, args: args },
idx = self._inArray( newAction );

if ( -1 === idx ) {
if ( self._currentlyOpenPopup === popup ) {
var closeAction = { open: false, popup: popup },
cIdx = self._inArray( closeAction );

if ( cIdx !== -1 ) {
if ( 0 === cIdx && self._inProgress ) {
self._actionQueue.push( newAction );
} else {
self._actionQueue.splice( cIdx, 1 );
}
self._runSingleAction();
self._navHook( function() {
self._waitingForPopup = true;
self._currentlyOpenPopup.element.one( "opened", function() {
self._waitingForPopup = false;
});
self._currentlyOpenPopup._open.apply( self._currentlyOpenPopup, args );
if ( !self._waitingForPopup && self._abort ) {
self._currentlyOpenPopup._immediate();
}
} else {
self._actionQueue.push( newAction );
self._runSingleAction();
}
});
}
},

pop: function( popup ) {
var self = this,
newAction = { open: false, popup: popup },
idx = self._inArray( newAction );

if ( -1 === idx ) {
var openAction = { open: true, popup: popup },
oIdx = self._inArray( openAction );

if ( oIdx !== -1 ) {
if ( 0 === oIdx ) {
self._actionQueue.splice( 1, 0, newAction );
self._runSingleAction();
} else {
self._actionQueue.splice( oIdx, 1 );
}
}
else
if ( self._currentlyOpenPopup === popup ) {
if ( self._actionQueue.length === 0 ) {
self._actionQueue.push( newAction );
self._runSingleAction();
} else {
self._actionQueue.splice( ( self._inProgress ? 1 : 0 ), 0, newAction );
self._runSingleAction();
}
var self = this;

if ( popup === self._currentlyOpenPopup ) {
if ( self._waitingForPopup ) {
self._currentlyOpenPopup.element.one( "opened", $.proxy( self, "_navUnhook" ) );
} else {
self._navUnhook();
}
}
},

_onHashChange: function( immediate ) {
this._haveNavHook = false;
this._yScroll = undefined;
$( this ).trigger( "done" );
var self = this;

if ( this._myOwnHashChange ) {
this._myOwnHashChange = false;
this._inProgress = false;
} else {
var dst = this._currentlyOpenPopup;

if ( this._inProgress ) {
this._actionQueue = [ this._actionQueue[ 0 ] ];
if ( this._actionQueue[ 0 ].open ) {
dst = this._actionQueue[ 0 ].popup;
if ( immediate && this._actionQueue[ 0 ].waitingForPopup ) {
this._actionQueue[ 0 ].popup._immediate();
}
} else {
dst = null;
}
} else {
this._actionQueue = [];
}
self._abort = immediate;

if ( dst ) {
this._actionQueue.push( { open: false, popup: dst } );
if ( self._currentlyOpenPopup ) {
if ( immediate && self._waitingForPopup ) {
self._currentlyOpenPopup._immediate();
}
}

if ( this._actionQueue.length > 0 ) {
$.each( this._actionQueue, function( idx, val ) {
val.abort = immediate;
self._currentlyOpenPopup.element.one( "closed", function() {
self._currentlyOpenPopup = null;
$( self ).trigger( "done" );
});
this._runSingleAction() ;
self._currentlyOpenPopup._close();
if ( immediate && self._currentlyOpenPopup ) {
self._currentlyOpenPopup._immediate();
}
}
}
};
}

$.mobile.popup.handleLink = function( $link ) {
var closestPage = $link.closest( ":jqmData(role='page')" ),
@@ -22,12 +22,6 @@
[ "jquery.mobile.init" ],
[
"popup_core.js"
],
[
"popup_quick_succession.js"
],
[
"popup_interaction.js"
]
]);
</script>

This file was deleted.

This file was deleted.