Using JQM 1.4.2 and JQ 1.7.2
I'm loading the content of a popup dynamically by taping on a button element. Ideally the popup should be positioned relative to the button, but relative to the window will do. However, on both IOS and Android the page scrolls to the very top to display the popup there. I read about IOS scrolling bugs with popups ON CLOSE, but not on open. It works just fine on a desktop computer (linux, any browser will work)
Code is simple and looks like this:
html:
don't mind the $() variables too much. This is a genshi template and the variables resolve just fine, resulting in a grid of 3x3 buttons each of which triggers loading the popup. This of course is inside a page container.
- <div data-role="popup" id="popupGift" style="max-width:400px;max-height:600px;">TEST</div>
- <div id="gifts" py:if="gifts" data-role="collapsible" data-collapsed="true" data-theme="e" data-split-icon="gear" data-split-theme="d">
- <h3>Gifts</h3>
- <!--! create a grid with the gift icons with date below -->
- <div class="ui-grid-b" py:for="line in splitArray(gifts,3)" py:with="classidx=['a','b','c']">
- <div class="ui-block-${classidx[i]}" py:for="i, gift in enumerate(line)" py:if="gift" style="text-align:center">
- <button id="giftbutton${gift.id}" data-giftid="${gift.id}" class="giftbutton ui-btn ui-btn-c ui-corner-all ui-mini" onclick="Util.loadProfileGift('/mobile/gifts/view?giftid=${gift.id}');return false;"><img src="${gift.icon_src}" style="width:${gift.icon_width}px;height:${gift.icon_height}px;padding:0.5em 0.5em 0.1em 0.5em;"/><span style="display:block;font-size:7pt;font-weight:bold;">${format_date(gift.date_given)}</span></button>
- </div>
- </div>
This is the Util.loadProfileGift javascript:
the loader widget shows up and the code executes just fine. The problem is that the popup open call causes the page to scroll to the top and display the popup there.
- Util.loadProfileGift = function(url) {
- $.ajax({
- beforeSend: function() { $.mobile.loading('show'); }, //Show spinner
- complete: function() { $.mobile.loading('hide') }, //Hide spinner
- url: url,
- dataType: 'json',
- success: function(data) {
- $('#popupGift').html(data.data).trigger('create');
- $('#popupGift').popup('open');
- }
- });
- };
In case it makes any difference on what the contents looks like, this is a typical response from the server. It's html wrapped in a json variable. Yes, it's a table. For matters of testing I kept it simple.
- <table>
- <tr>
- <td colspan="2"><a href="/view_profile?id=${gift.from_id}" style="color:black">From: ${gift.name} on ${format_date(gift.date_given)}</a></td>
- </tr>
- <tr>
- <td style="vertical-align:top;"><a href="/view_profile?id=${gift.from_id}"><img src="${url(getBPhotoThumbSmall(gift.from_id,gift.photoid))}" alt="profile photo" style="padding-top:5px;"/></a></td>
- <td><div py:if="gift.message">${Markup(gift.message)}</div></td>
- </tr>
- </table>
The loader widget is shown in place of the event. The scrolling to the top of the page only occurs just before the popup is shown, so it's safe to assume something happens in lines 9 and 10 of the javascript that causes the page to scroll. It's also interesting that this is consistent between IOS (7) and Android (4.1.2)
Any pointers would be more than welcome. I've been ruffing my hair over this for the last 3 days.
Uwe