Showing with 62 additions and 99 deletions.
  1. +62 −99 js/jquery.mobile.popup.js
@@ -22,17 +22,15 @@ define( [ "jquery",

_create: function() {
var ui = {
screen: "#ui-popup-screen",
placeholder: "#placeholder",
container: "#ui-popup-container"
screen: $("<div class='ui-screen-hidden ui-popup-screen fade'></div>"),
placeholder: $("<div id='placeholder' style='display: none;'><!-- placeholder --></div>"),
container: $("<div id='ui-popup-container' class='ui-popup-container ui-selectmenu-hidden'></div>")
},
eatEventAndClose = function( e ) {
e.preventDefault();
e.stopImmediatePropagation();
self.close();
},
proto = $(
"<div>" +
" <div id='ui-popup-screen' class='ui-screen-hidden ui-popup-screen fade'></div>" +
" <div id='ui-popup-container' class='ui-popup-container ui-selectmenu-hidden'></div>" +
" <div id='placeholder' style='display: none;'><!-- placeholder --></div>" +
"</div>"
),
thisPage = this.element.closest( ":jqmData(role='page')" ),
myId = this.element.attr( "id" ),
self = this;
@@ -41,11 +39,6 @@ define( [ "jquery",
thisPage = $( "body" );
}

// Assign the relevant parts of the proto
for ( var key in ui ) {
ui[ key ] = proto.find( ui[ key ] ).removeAttr( "id" );
}

// Apply the proto
thisPage.append( ui.screen );
ui.container.insertAfter( ui.screen );
@@ -65,27 +58,17 @@ define( [ "jquery",
_isOpen: false
});

$.each( this.options, function( key ) {
$.each( this.options, function( key, value ) {
// Cause initial options to be applied by their handler by temporarily setting the option to undefined
// - the handler then sets it to the initial value
var value = self.options[ key ];

self.options[ key ] = undefined;
self._setOption( key, value, true );
});

ui.screen.bind( "vclick", function( e ) {
e.preventDefault();
e.stopImmediatePropagation();
self.close();
});
ui.screen.bind( "vclick", function( e ) { eatEventAndClose( e ); });
$( window ).bind( "keyup", function( e ) {
if ( self._isOpen ) {
if ( e.keyCode === $.mobile.keyCode.ESCAPE ) {
e.preventDefault();
e.stopImmediatePropagation();
self.close();
}
if ( self._isOpen && e.keyCode === $.mobile.keyCode.ESCAPE ) {
eatEventAndClose( e );
}
});
},
@@ -103,7 +86,8 @@ define( [ "jquery",
if ( matches && matches.length > 1 ) {
currentTheme = matches[ 1 ];
break;
} else {
}
else {
currentTheme = null;
}
}
@@ -118,26 +102,18 @@ define( [ "jquery",

_setTheme: function( value ) {
this._realSetTheme( this._ui.container, value );
this.options.theme = value;
this.element.attr( "data-" + ( $.mobile.ns || "" ) + "theme", value );
},

_setOverlayTheme: function( value ) {
this._realSetTheme( this._ui.screen, value );
this.options.overlayTheme = value;
this.element.attr( "data-" + ( $.mobile.ns || "" ) + "overlay-theme", value );
},

_setShadow: function( value ) {
this._ui.container[value ? "addClass" : "removeClass"]( "ui-overlay-shadow" );
this.options.shadow = value;
this.element.attr( "data-" + ( $.mobile.ns || "" ) + "shadow", value );
this._ui.container.toggleClass( "ui-overlay-shadow", value );
},

_setCorners: function( value ) {
this._ui.container[value ? "addClass" : "removeClass"]( "ui-corner-all" );
this.options.corners = value;
this.element.attr( "data-" + ( $.mobile.ns || "" ) + "corners", value );
this._ui.container.toggleClass( "ui-corner-all", value );
},

_applyTransition: function( value ) {
@@ -152,18 +128,18 @@ define( [ "jquery",
if ( !this._currentTransition ) {
this._applyTransition( value );
}
this.options.transition = value;
this.element.attr( "data-" + ( $.mobile.ns || "" ) + "transition", value );
},

_setOption: function( key, value ) {
var setter = "_set" + key.replace( /^[a-z]/, function(c) {
return c.toUpperCase();
});
var setter = "_set" + key.replace( /^[a-z]/, function( c ) { return c.toUpperCase(); } );

if ( this[setter] !== undefined ) {
this[setter]( value );
} else {
if ( this[ setter ] !== undefined ) {
this[ setter ]( value );
// Record the option change in the options and in the DOM data-* attributes
this.options[ key ] = value;
this.element.attr( "data-" + ( $.mobile.ns || "" ) + ( key.replace( /([A-Z])/, "-$1" ).toLowerCase() ), value );
}
else {
$.mobile.widget.prototype._setOption.apply( this, arguments );
}
},
@@ -189,22 +165,26 @@ define( [ "jquery",

if ( roomtop > menuHeight / 2 && roombot > menuHeight / 2 ) {
newtop = y - halfheight;
} else {
}
else {
// 30px tolerance off the edges
newtop = roomtop > roombot ? scrollTop + screenHeight - menuHeight - 30 : scrollTop + 30;
}

// If the menuwidth is greater or equal to the max-width, center it on screen
if ( menuWidth >= maxwidth ) {
newleft = ( screenWidth - menuWidth ) / 2;
} else {
}
else {
//otherwise insure a >= 30px offset from the left
newleft = x - menuWidth / 2;

// 10px tolerance off the edges
if ( newleft < 10 ) {
newleft = 10;
} else if ( ( newleft + menuWidth ) > screenWidth ) {
}
else
if ( ( newleft + menuWidth ) > screenWidth ) {
newleft = screenWidth - menuWidth - 10;
}
}
@@ -230,9 +210,6 @@ define( [ "jquery",
self._ui.screen.height( $( document ).height() );
maybeTriggerOpened();
},
showScreen = function() {
maybeTriggerOpened();
},
coords = self._placementCoords(
( undefined === x ? window.innerWidth / 2 : x ),
( undefined === y ? window.innerHeight / 2 : y ) );
@@ -256,10 +233,10 @@ define( [ "jquery",
if ( self.options.overlayTheme ) {
self._ui.screen
.addClass("in")
.animationComplete( showScreen );
.animationComplete( maybeTriggerOpened );
}
else {
showScreen();
maybeTriggerOpened();
}

self._ui.container
@@ -306,8 +283,9 @@ define( [ "jquery",
maybeTriggerClosed();
},
hideScreen = function() {
self._ui.screen.addClass( "ui-screen-hidden" );
self._ui.screen.removeClass( "out" );
self._ui.screen
.removeClass( "out" )
.addClass( "ui-screen-hidden" );
maybeTriggerClosed();
};

@@ -316,7 +294,8 @@ define( [ "jquery",
.removeClass( "in" )
.addClass( "reverse out" )
.animationComplete( onAnimationComplete );
} else {
}
else {
onAnimationComplete();
}

@@ -325,7 +304,8 @@ define( [ "jquery",
.removeClass( "in" )
.addClass( "out" )
.animationComplete( hideScreen );
} else {
}
else {
hideScreen();
}
},
@@ -422,22 +402,16 @@ define( [ "jquery",

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

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

if ( self._actionQueue.length > 0 ) {
self._runSingleAction();
}
},
@@ -463,9 +437,7 @@ define( [ "jquery",
args = [];
}

self._actionQueue[0].popup.element.one( signal, function() {
self._completeAction();
});
self._actionQueue[0].popup.element.one( signal, function() { self._completeAction(); });
self._actionQueue[0].popup[fn].apply( self._actionQueue[0].popup, args );
},

@@ -546,35 +518,28 @@ define( [ "jquery",
},

_onHashChange: function() {
var self = this;

self._haveNavHook = false;
this._haveNavHook = false;

if ( self._myOwnHashChange ) {
self._myOwnHashChange = false;
self._inProgress = false;
if ( self._actionQueue.length > 0 ) {
self._runSingleAction() ;
}
if ( this._myOwnHashChange ) {
this._myOwnHashChange = false;
this._inProgress = false;
}
else {
var popupToClose = null;
if ( self._inProgress ) {
self._actionQueue = [ self._actionQueue[0] ];
if ( self._actionQueue[0].open ) {
popupToClose = self._actionQueue[0].popup;
}
var offset, ac;

if ( this._inProgress ) {
offset = 1;
ac = ( this._actionQueue[0].open ? { open: false, popup: this._actionQueue[0].popup } : undefined );
}
else {
self._actionQueue = [];
if ( self._currentlyOpenPopup ) {
popupToClose = self._currentlyOpenPopup;
}
}
if ( popupToClose ) {
self._actionQueue.push( { open: false, popup: popupToClose } );
self._runSingleAction();
offset = 0,
ac = ( this._currentlyOpenPopup ? { open: false, popup: this._currentlyOpenPopup } : undefined );
}
this._actionQueue.splice( offset, this._actionQueue.length - offset, ac );
}

if ( this._actionQueue.length > 0 ) {
this._runSingleAction() ;
}
}
}
@@ -607,9 +572,7 @@ define( [ "jquery",
};

$( document ).bind( "pagecreate create", function( e ) {
$( $.mobile.popup.prototype.options.initSelector, e.target )
.not( ":jqmData(role='none'), :jqmData(role='nojs')" )
.popup();
$.mobile.popup.prototype.enhanceWithin( e.target, true );

$( "a[href^='#']:jqmData(rel='popup')", e.target ).each( function() {
$.mobile.popup.bindPopupToButton( $( this ), $( $( this ).attr( "href" ) ) );