@@ -68,6 +68,7 @@ $.widget( "mobile.popup", $.mobile.widget, {
6868 navigateEvents : "navigate.popup" ,
6969 closeEvents : "navigate.popup pagebeforechange.popup" ,
7070 dismissible : true ,
71+ enhanced : false ,
7172
7273 // NOTE Windows Phone 7 has a scroll position caching issue that
7374 // requires us to disable popup history management by default
@@ -202,45 +203,21 @@ $.widget( "mobile.popup", $.mobile.widget, {
202203 } ,
203204
204205 _create : function ( ) {
205- var ui = {
206- screen : $ ( "<div class='ui-screen-hidden ui-popup-screen'></div>" ) ,
207- placeholder : $ ( "<div style='display: none;'><!-- placeholder --></div>" ) ,
208- container : $ ( "<div class='ui-popup-container ui-popup-hidden'></div>" )
209- } ,
210- thisPage = this . element . closest ( ".ui-page" ) ,
211- myId = this . element . attr ( "id" ) ,
206+ var e = this . element ,
207+ myId = e . attr ( "id" ) ,
212208 o = this . options ;
213209
214210 // We need to adjust the history option to be false if there's no AJAX nav.
215211 // We can't do it in the option declarations because those are run before
216212 // it is determined whether there shall be AJAX nav.
217213 o . history = o . history && $ . mobile . ajaxEnabled && $ . mobile . hashListeningEnabled ;
218214
219- if ( thisPage . length === 0 ) {
220- thisPage = $ ( "body" ) ;
221- }
222-
223- // Apply the proto
224- thisPage . append ( ui . screen ) ;
225- ui . container . insertAfter ( ui . screen ) ;
226- // Leave a placeholder where the element used to be
227- ui . placeholder . insertAfter ( this . element ) ;
228- if ( myId ) {
229- ui . screen . attr ( "id" , myId + "-screen" ) ;
230- ui . container . attr ( "id" , myId + "-popup" ) ;
231- ui . placeholder . html ( "<!-- placeholder for " + myId + " -->" ) ;
232- }
233- this . element
234- . addClass ( "ui-popup" )
235- . appendTo ( ui . container ) ;
236- ui . focusElement = ui . container ;
237-
238215 // Define instance variables
239216 $ . extend ( this , {
240217 _containerClasses : "" ,
241218 _scrollTop : 0 ,
242- _page : thisPage ,
243- _ui : ui ,
219+ _page : e . closest ( ".ui-page" ) ,
220+ _ui : null ,
244221 _fallbackTransition : "" ,
245222 _currentTransition : false ,
246223 _prereqs : null ,
@@ -251,10 +228,23 @@ $.widget( "mobile.popup", $.mobile.widget, {
251228 _orientationchangeInProgress : false
252229 } ) ;
253230
254- this . _setOptions ( this . options ) ;
231+ if ( this . _page . length === 0 ) {
232+ this . _page = $ ( "body" ) ;
233+ }
234+
235+ if ( o . enhanced ) {
236+ this . _ui = {
237+ container : e . parent ( ) ,
238+ screen : e . parent ( ) . prev ( ) ,
239+ placeholder : $ ( document . getElementById ( myId + "-placeholder" ) )
240+ } ;
241+ } else {
242+ this . _ui = this . _enhance ( e , myId ) ;
243+ this . _setOptions ( o ) ;
244+ }
255245
256246 // Event handlers
257- ui . screen . bind ( "vclick" , $ . proxy ( this , "_eatEventAndClose" ) ) ;
247+ this . _ui . screen . bind ( "vclick" , $ . proxy ( this , "_eatEventAndClose" ) ) ;
258248 this . _on ( $ . mobile . window , {
259249 orientationchange : $ . proxy ( this , "_handleWindowOrientationchange" ) ,
260250 resize : $ . proxy ( this , "_handleWindowResize" ) ,
@@ -265,6 +255,31 @@ $.widget( "mobile.popup", $.mobile.widget, {
265255 } ) ;
266256 } ,
267257
258+ _enhance : function ( e , myId ) {
259+ var ui = {
260+ screen : $ ( "<div class='ui-screen-hidden ui-popup-screen'></div>" ) ,
261+ placeholder : $ ( "<div style='display: none;'><!-- placeholder --></div>" ) ,
262+ container : $ ( "<div class='ui-popup-container ui-popup-hidden'></div>" )
263+ } ;
264+
265+ // Apply the proto
266+ this . _page . append ( ui . screen ) ;
267+ ui . container . insertAfter ( ui . screen ) ;
268+ // Leave a placeholder where the element used to be
269+ ui . placeholder . insertAfter ( e ) ;
270+ if ( myId ) {
271+ ui . screen . attr ( "id" , myId + "-screen" ) ;
272+ ui . container . attr ( "id" , myId + "-popup" ) ;
273+ ui . placeholder
274+ . attr ( "id" , myId + "-placeholder" )
275+ . html ( "<!-- placeholder for " + myId + " -->" ) ;
276+ }
277+ e . addClass ( "ui-popup" ) . appendTo ( ui . container ) ;
278+ ui . focusElement = ui . container ;
279+
280+ return ui ;
281+ } ,
282+
268283 _applyTheme : function ( dst , theme , prefix ) {
269284 var themeStr , matches ,
270285 classes = ( dst . attr ( "class" ) || "" ) . split ( " " ) ,
0 commit comments