SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 91 | Next

Richard Wagner

"Professional iPhone and iPod touch Programming: Building Applications for Mobile Safari"

These two functions are shown in the
following code:
function showDialog(page)
{
currentDialog = page;
page.setAttribute(???selected???, ???true???);
if (hasClass(page, ???dialog???) & & !page.target)
showForm(page);
}
function showForm(form)
{
form.onsubmit = function(event)
{
event.preventDefault();
submitForm(form);
};
Chapter 3: Implementing the Interface
75
form.onclick = function(event)
{
if (event.target == form & & hasClass(form, ???dialog???))
cancelDialog(form);
};
}
The showForm() function assigns event handlers to the onsubmit and onclick events of the form.
When a form is submitted, the submitForm() function submits the form data via AJAX. When an
element on the form is clicked, then the dialog is closed. The following code shows the routines that
are called:
function submitForm(form)
{
iui.showPageByHref(form.action || ???POST???, encodeForm(form), form.method);
}
function cancelDialog(form)
{
form.removeAttribute(???selected???);
}
function encodeForm(form)
{
function encode(inputs)
{
for (var i = 0; i < inputs.length; ++i)
{
if (inputs[i].name)
args.push(inputs[i].name + ???=??? + escape(inputs[i].value));
}
}
var args = [];
encode(form.getElementsByTagName(???input???));
encode(form.


Pages:
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103