|
22 | 22 | 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>',
|
23 | 23 | header = '<div data-role="header"><h2>' + brand + ' ' + model + '</h2></div>',
|
24 | 24 | 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 ); |
26 | 35 |
|
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" ); |
29 | 36 | // Wait with opening the popup until the popup image has been loaded in the DOM.
|
30 | 37 | // This ensures the popup gets the correct size and position
|
31 | 38 | $( ".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 }); |
36 | 39 | // Open the popup
|
37 | 40 | $( "#popup-" + short ).popup( "open" );
|
| 41 | + |
38 | 42 | // Clear the fallback
|
39 | 43 | clearTimeout( fallback );
|
40 | 44 | });
|
| 45 | + |
41 | 46 | // Fallback in case the browser doesn't fire a load event
|
42 | 47 | var fallback = setTimeout(function() {
|
43 | 48 | $( "#popup-" + short ).popup( "open" );
|
|
46 | 51 |
|
47 | 52 | // Set a max-height to make large images shrink to fit the screen.
|
48 | 53 | $( 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 | + |
49 | 61 | // 68px: 2 * 15px for top/bottom tolerance, 38px for the header.
|
50 | 62 | var maxHeight = $( window ).height() - 68 + "px";
|
51 | 63 |
|
|
0 commit comments