Search code examples
jqueryjquery-mobile

jQuery-Mobile fancy popup box works with jQuery 2.1.3 but breaks with jQuery 2.2.4


Years ago, I found this "fancy alert" popup box for use with jQuery mobile. I've been using it in my Cordova apps for years.

Recently, I've been informed that version 2.1.3 of jQuery has security holes, and I needed to upgrade. The newest version of jQuery that works with jQuery Mobile is 2.2.4. So I have upgraded to 2.2.4, but it breaks my "fancy alert" popup box.

Here's my code:

function fancyAppAlert(alertContent){
    if ($("#fancyAlertPopup").length === 0) {
        $(':mobile-pagecontainer').pagecontainer('getActivePage').append('<div style="padding-top: 10px; ' +
            'padding-bottom: 20px; padding-left: 20px; padding-right: 20px; width: 86%" data-role="popup" ' +
            'id="fancyAlertPopup" data-theme="a" class="ui-content"><a href="#" data-rel="back" ' +
            'class="ui-btn ui-corner-all ui-shadow ui-btn-a ui-icon-delete ui-btn-icon-notext ui-btn-right">' +
            'Close</a><h4 id="fancyAlertText">' + alertContent + '</h4></div>').trigger("create");
    } else {
        $('#fancyAlertText').html(alertContent);
    }
    $("#fancyAlertPopup").popup( "open",{transition: "flip"} );
}

When I use jQuery 2.1.3 the above code pops up an alert window that displays the contents of alertContent. When I use jQuery 2.2.4, the exact same code gives me the following error: Uncaught TypeError: Cannot read properties of undefined (reading 'trigger')

So clearly it's the .trigger("create") that's breaking it, but I have no idea why. I can find no documentation that mentions any breaking changes between version 2.1.3 and 2.2.4. Does anyone know how to fix this? I cannot upgrade to jQuery 3.x.x because I must have jQuery Mobile 1.4.5, and jQuery 3.x.x does not work with jQuery Mobile 1.4.5.

Thanks for any help you can give.


Solution

  • Well, apparently jQuery 2.2.4 IS NOT compatible with jQuery Mobile 1.4.5. Apparently the latest version of jQuery that's compatible with jQuery Mobile is 2.1.4. That's seriously annoying...