0

I have the following doubt with this jquery mobile script...

$(document).on("pageinit",function(){
  alert("pageinit" + $("#unica").html());
}); 

$(document).on("pagebeforecreate",function(){
  alert("pagebeforecreate" + $("#unica").html());
});                     

$(document).on("pagecreate",function(){
  alert("pagecreate" + $("#unica").html());
});

I am making some test in this page jQm Page and I see that the alert shows me the same in the case of the pagecreate and pageinit event... So I can't figure what things can be done in each one coz I believed they were going to show something different... Well hope to get help... Cheers

Omar
  • 32,302
  • 9
  • 69
  • 112
  • possible duplicate of [Setting up the jQuery Mobile script](http://stackoverflow.com/questions/20457195/setting-up-the-jquery-mobile-script) – Omar Jan 09 '14 at 13:29
  • I understand as the other thread states, that my initialization code should be in the pageinit not document ready (as this only executes one time but the other every time the page is loaded in the dom), but my question really is another... I don't understand why I see the same markup in those 2 events !... – user3118724 Jan 09 '14 at 14:42
  • Read about `pagebeforecreate` and `pagecreate` events, however, it's not explained that on first event, `.page()` widget is created and on latter event, other _widgets_ are created. Both events wont show you any major differences in html markup, because they are used to setup jQM _widgets_. `pageinit` will show you different html markup as at this point, all widgets are initialized. – Omar Jan 09 '14 at 15:52
  • Thankx for asnwering Omar !. Just to clarify... I see the same markup in the "pagecreate" and in the "pageinit" events... But not in the "pagebeforecreate" event which executes first... One question... I saw in several places that "pageinit" event should be replaced with the "pagecreate" event... Do you consider that ok ?... – user3118724 Jan 09 '14 at 18:53
  • Which widgets are you testing? No, you don't need to wrap pageinit in pagecreate, it works independently. If you have any question let me know :) – Omar Jan 09 '14 at 19:39
  • Thankx again... Thankx for the patience... I said in my first post I see the same html mark up in the "pagecreate" and "pageinit" event, but not in the "pagebeforecreate" event (which is the first that is executed of the ones I listed)... I am not trying any widget; the only things I have are a page with header and footer... Let's do something... I'll be reading more (altough I did it) and I will write down more precisely my doubts... Thankx again... – user3118724 Jan 13 '14 at 11:34
  • I'm not sure when _toolbar_ widget is created, but since you see the same markup on `pagecreate` and `pageinit`, then they're created on `pagebeforecreate` with _page_ widget. Try _listview_ widget and check the difference. – Omar Jan 13 '14 at 11:37
  • I'll be doing that and writing down any questions... Peace – user3118724 Jan 13 '14 at 12:20

1 Answers1

0

Look the analysis I've made...

                  |     1       |     2
pagebeforecreate  | 494 / 1125  | 257 / 257
pagecreate        | 1125 / 1125 | 257 / 485
pageinit          | 1125 / 1125 | 257 / 485
pagebeforeshow    | 1125        | 485

This table can be read considering this code...

$(document).on("pageinit",function(){
  alert("pageinit" + $("#unica").html().length);
}); 

$(document).on("pagebeforecreate",function(){
  alert("pagebeforecreate" + $("#unica").html().length);
});                     

$(document).on("pagecreate",function(){
  alert("pagecreate" + $("#unica").html().length);
});

$(document).on("pagebeforeshow",function(){
  alert("pagecreate" + $("#unica").html().length);
});

In every event I try to verify which is the length of the html markup. In the first page I have a listview and the other one is a simple page. Every page has a button to go to every page. The first value in case of the first page considering the pagebeforecreate is 494; but it turn out to be 1125 when you go from page 2 to page 1. It's like the framework keeps in the dom the enhance markup.

Another thing... Consider this... 1. "pagebeforecreate": Before jqm does the "enhance" work (widget auto-initialization,etc);es decir, putting the css classess in the markup. I can manipulate the attributes via JS or modify them, etc..

  1. "pagecreate": Not all the widgets have had an opportunity to enhance the contained markup. This should be use only to create it's own widgets !.

  2. "pageinit": Similar to dom .ready. After auto-init ocurs.

What do you think or what landmark can you make ?...

Thankx