1

I'm building a mobile app using ratchet, and I love the toolset so far, but I'm running into an issue using a modal as a menu.

Here's the live index page.

This is the only custom js I'm using:

$(document).ready(function() {
    if ((navigator.userAgent.match(/Android/i))) {
        $('head').append('<link rel="stylesheet" href="css/ratchet-theme-android.min.css" type="text/css" />');
        var plainAddress = $("#appAddress").text().replace(/\s+/g, "+");
        var paramAddress = encodeURI(plainAddress);
        var urlAddress = ('geo:0,0+?q=' + paramAddress);
        $('#appLink').attr('href', urlAddress);

    } else {
        $('head').append('<link rel="stylesheet" href="css/ratchet-theme-ios.min.css" type="text/css" />');
        var plainAddress = $("#appAddress").text().replace(/\s+/g, "+");
        var paramAddress = encodeURI(plainAddress);
        var urlAddress = ('http://maps.apple.com/?q=' + paramAddress);
        $('#appLink').attr('href', urlAddress);
    };
});
$.get('modal/qrModal.html', function(qr) {
    $("#loadedModals").append(qr);
});
$.get('modal/menuModal.html', function(qr) {
    $("#loadedModals").append(qr);
});

The rest is ratchet.js from goratchet.com. I'm pulling in the menu and the qr code via js because they're not unique to every page. The menu though when launched works fine, and when a selection is made the first time, it follows through, loads the page, and closes the modal.

After that it get's finicky.

Sometimes the modal won't load, sometimes it's unresponsive, sometimes it loads, loads a newpage but doesn't exit the modal.

Is this because I've exported it to external pages? Or is something else the matter?

cvrebert
  • 9,075
  • 2
  • 38
  • 49
scotho3
  • 123
  • 1
  • 14

1 Answers1

1

It looks like your loadedModals container is being cleared out, and not repopulated after a new page is loaded via push.js.

<div id="loadedModals">
   ...
</div>

You can reload the modals after each push event by firing a callback.

var loadModal = function(){
    $.get('modal/qrModal.html', function(qr) {
        $("#loadedModals").append(qr);
    });
    $.get('modal/menuModal.html', function(qr) {
        $("#loadedModals").append(qr);
    });
};

loadModal();

window.addEventListener('push', loadModal);
Schmalzy
  • 17,044
  • 7
  • 46
  • 47
  • This was exactly what I was looking for! Javascript syntax is new to me, so I knew this was possible, i just didn't know how to express it. Thanks again! – scotho3 May 04 '14 at 20:06