JQM 1.4.1: new event "pagecontainershow"

I was confused by JQM changes:

As you may know, JQM declined the event:

$(document).on('pageshow', '#MyPage', function(){ 

and replaced it with:

$(document).on('pagecontainershow', function (e, ui) {

However, this new event is not tied to a specific page, as previously shown. However, the event:

$(document).on('pagecreate', '#MyPage', function(){ 

still attached to a specific page, and I think other event pages are still attached to specific pages.

MY QUESTION:

The fact that some events are tied to pages and others not, makes the structure very confusing. Should it be better to standardize all events since version 1.3 was in which everyone was attached to the pages?

Will the "pagecreate" event and all event pages be scanned for pages in the future, since the "pagehow" is now in version 1.4.1.

- , 1.4.1

+3
3

pagecontainershow, PAGE, "switch case" :

$(document).on('pagecontainershow', function (e, ui) {

var ThisPage = $(':mobile-pagecontainer').pagecontainer('getActivePage').attr('id');

  switch(ThisPage){

    case 'Page1':

    case 'Page2':

    case 'Page3':


etc....

, , () , , .

+2

, , , JQM 1.3 HTML , , , , , :

function setPageContainerHandlers(){
    function getPageContainerEventHandler(action){
        var handler = function(e, ui){
            var id = $(':mobile-pagecontainer').pagecontainer('getActivePage').attr('id');
            var f = window.page_handlers[action]['#' + id];
            if ('function' == typeof f){
                f(e, ui);
            }
        }

        return handler;
    }

    var events = ['pagecontainershow', 'pagecontainerhide', 'pagecontainerbeforeload', 'pagecontainerbeforeshow', 'pagecontainerload', 'pagecontainerloadfailed', 'pagecontainerchangefailed'];
    var actions = ['pageshow', 'pagehide', 'pagebeforeload', 'pagebeforeshow', 'pageload', 'pageloadfailed', 'pagechangefailed']

    for(var i = 0; i < events.length; i++){
        var handler = getPageContainerEventHandler(actions[i]);
        $(document).on(events[i], handler);
        window.page_container_handlers[events[i]] = handler;
        window.page_handlers[actions[i]] = {};
    }
}

function registerPageHandler(id, action, handler){
    window.page_handlers[action][id] = handler;
}

, setPageContainerHandlers() <script> ,

$("#results").on("pagebeforeshow", initResults);

registerPageHandler("#results", "pagebeforeshow", initResults);.

0

How easy is it to check the current page and exit the event, if not the one you need? Thus, you can use individual functions as "normal".

$(document).on('pagecontainershow', function (e, ui) {
    if (ui.toPage[0].id != "YOUR_PAGE_1") return;

    //Do you stuff for YOUR_PAGE_1 here
});

$(document).on('pagecontainershow', function (e, ui) {
    if (ui.toPage[0].id != "YOUR_PAGE_2") return;

    //Do you stuff for YOUR_PAGE_2 here
});
0
source

All Articles