This node is then passed to iui.showPage() ,
which is the core routine to display content.
As Chapter 5 explains, setTimeout() is often used when calling certain JavaScript routines to prevent
timing inconsistencies. Using setTimeout() , iUI calls an image preloader function to load application
Chapter 3: Implementing the Interface
69
images and then a routine called checkOrientAndLocation() , which is an event handler used for
detecting and handling viewport orientation changes. (Orientation change events are fully covered in
Chapter 5 .) The setInterval function then calls checkOrientAndLocation() every 300ms when the
application runs. Note that the checkOrientAndLocation() also contains the code to hide the URL bar.
The iPhone update 1.1.1 added an orientationchange event. However, for maximum compatibility
with iPhone 1.0, I recommend continuing to use the checkOrientAndLocation() event.
Getting back to iui.showPage() , its code is as follows:
showPage: function(page, backwards)
{
if (page)
{
if (currentDialog)
{
currentDialog.removeAttribute(???selected???);
currentDialog = null;
}
if (hasClass(page, ???dialog???))
showDialog(page);
else
{
var fromPage = currentPage;
currentPage = page;
if (fromPage)
setTimeout(slidePages, 0, fromPage, page, backwards);
else
updatePage(page, fromPage);
}
}
}
The currentDialog semi - global variable is evaluated to determine whether a dialog is already
displayed.
Pages:
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95