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

Commit 186d286

Browse files
author
Gabriel Schulhof
committed
Popup: Correctly enhance popup and its contents before opening
This is a better fix than the one provided in the original PR for this, because it avoids the use of .enhanceWithin(), and it moves the image width/height retrieval to popupbeforeposition, which is correct, because during creation the popup is truncated to 1px x 1px. Closes gh-7290 Fixes gh-7336
1 parent 5342dfd commit 186d286

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

demos/popup-dynamic/index.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,27 @@
2222
closebtn = '<a href="#" data-rel="back" class="ui-btn ui-corner-all ui-btn-a ui-icon-delete ui-btn-icon-notext ui-btn-right">Close</a>',
2323
header = '<div data-role="header"><h2>' + brand + ' ' + model + '</h2></div>',
2424
img = '<img src="../_assets/img/' + short + '.jpg" alt="' + brand + '" class="photo">',
25-
popup = '<div data-role="popup" id="popup-' + short + '" data-short="' + short +'" data-theme="none" data-overlay-theme="a" data-corners="false" data-tolerance="15">' + closebtn + header + img + '</div>';
25+
popup = '<div data-role="popup" id="popup-' + short + '" data-short="' + short +'" data-theme="none" data-overlay-theme="a" data-corners="false" data-tolerance="15"></div>';
26+
27+
// Create the popup.
28+
$( header )
29+
.appendTo( $( popup )
30+
.appendTo( $.mobile.activePage )
31+
.popup() )
32+
.toolbar()
33+
.before( closebtn )
34+
.after( img );
2635

27-
// Create the popup. Trigger "pagecreate" instead of "create" because currently the framework doesn't bind the enhancement of toolbars to the "create" event (js/widgets/page.sections.js).
28-
$.mobile.activePage.append( popup ).trigger( "pagecreate" );
2936
// Wait with opening the popup until the popup image has been loaded in the DOM.
3037
// This ensures the popup gets the correct size and position
3138
$( ".photo", "#popup-" + short ).load(function() {
32-
var height = $( this ).height(),
33-
width = $( this ).width();
34-
// Set height and width attribute of the image
35-
$( this ).attr({ "height": height, "width": width });
3639
// Open the popup
3740
$( "#popup-" + short ).popup( "open" );
41+
3842
// Clear the fallback
3943
clearTimeout( fallback );
4044
});
45+
4146
// Fallback in case the browser doesn't fire a load event
4247
var fallback = setTimeout(function() {
4348
$( "#popup-" + short ).popup( "open" );
@@ -46,6 +51,13 @@
4651

4752
// Set a max-height to make large images shrink to fit the screen.
4853
$( document ).on( "popupbeforeposition", ".ui-popup", function() {
54+
var image = $( this ).children( "img" ),
55+
height = image.height(),
56+
width = image.width();
57+
58+
// Set height and width attribute of the image
59+
$( this ).attr({ "height": height, "width": width });
60+
4961
// 68px: 2 * 15px for top/bottom tolerance, 38px for the header.
5062
var maxHeight = $( window ).height() - 68 + "px";
5163

0 commit comments

Comments
 (0)