jQuery mobile open popup from popup

Deadly 提交于 2019-12-05 07:20:45

My solution

$.mobile.switchPopup = function(sourceElement, destinationElement, onswitched) {
    var afterClose = function() {
        destinationElement.popup("open");
        sourceElement.off("popupafterclose", afterClose);

        if (onswitched && typeof onswitched === "function"){
            onswitched();
        }
    };

    sourceElement.on("popupafterclose", afterClose);
    sourceElement.popup("close");
};
Kevin

I used this simple function for the work-around:

function myPopup(myPage) {
    history.back();
    setTimeout(function () {
        $(myPage).popup('open');
    }, 100);
}

@Rakoo has a nice answer. Here is a leaner version:

$.mobile.switchPopup = function(sourceElement, destinationElement, onswitched) {
    sourceElement.one("popupafterclose", function() {
        destinationElement.popup("open")
        !onswitched || typeof onswitched !== "function" || onswitched()
    }).popup("close")
};

If you don't need the onswitched feature and aren't adding it to $.mobile, It can be this short and simple:

$('#popup1').one("popupafterclose", function(){$('#popup2').popup("open")}).popup("close")

It seems that chaining popups is not possible.

The solution:

$( document ).on( "pageinit", function() {
    $( '.popupParent' ).on({
        popupafterclose: function() {
            setTimeout( function(){ $( '.popupChild' ).popup( 'open' ) }, 100 );
        }
    });
});

I used this code to switch popup from popup it works fine.

function switchpop()
{
    $( '#popupMenu' ).popup( 'close' );  
    $( "#popupMenu" ).bind({popupafterclose: function(event, ui) 
            { 
                $( "#notes" ).popup( "open" );
            }
            });                
}

After four hours of fighting with this I reduced the problem to this:

This is in a button click function on the first popup

    $('#popupCall').popup('close');

    window.setTimeout(function () { $('#popupContact').popup('open') }, 50);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!