iUI: JavaScript and buttons in sub-pages

3 views
Skip to first unread message

Dave

unread,
Aug 26, 2007, 1:54:35 PM8/26/07
to iPhoneWebDev
I'm excited by how much iUI does for me in terms of creating a good
iPhone experience, but have hit some stumbling blocks:

(1) When I link to another page (which iUI loads in via Ajax), none of
its JavaScripts seem to be executing. The Safari Web Inspector sees
the script tags, but nothing happens. Any idea what I'm doing wrong?

(2) Is there a way to add/subtract buttons from the toolbar as one
navigates from page to page? For instance, my master view might need a
"New" button, but the detail view shouldn't have it.

Thanks!

Snyke

unread,
Aug 27, 2007, 9:25:35 PM8/27/07
to iPhoneWebDev
I changed the iui.js to eval javascript tags on the fly when loading
them along with other documents:

<code>
insertPages: function(nodes)
{
var targetPage;
for (var i = 0; i < nodes.length; ++i)
{
var child = nodes[i];
if(child.tagName && child.tagName.toLowerCase() ==
"script"){
eval(child.innerHTML);
}
else if (child.nodeType == 1)
{
if (!child.id)
child.id = "__" + (++newPageCount) + "__";
var clone = $(child.id);
if (clone)
clone.parentNode.replaceChild(child, clone);
else
document.body.appendChild(child);
if (child.getAttribute("selected") == "true" || !
targetPage)
targetPage = child;
--i;
}
}
if (targetPage)
tmm.showPage(targetPage);
},
</code>

At least this works when the script-tag is at the same level of the
lists used for the other pages. Haven't tried it yet with javascript
attached to DOM-elements as I add listeners on the fly.
Hope this helps ^^
--
http://www.snyke.net/blog

BikePilgrim

unread,
Aug 28, 2007, 1:30:41 AM8/28/07
to iPhoneWebDev

BikePilgrim

unread,
Aug 28, 2007, 1:36:21 AM8/28/07
to iPhoneWebDev
I believe inline event handlers still work properly in iUI-ajax loaded
pages. So now we've got both. Thanks Snyke. Is anyone here involved
with the iUI Google Code project? I requested an invitation, but I
guess Joe's too busy (probably curing cancer). I'd like to see things
like this being implemented in the core iUI framework.

On Aug 27, 6:25 pm, Snyke <Decker.Christ...@gmail.com> wrote:

Dave

unread,
Aug 28, 2007, 1:33:45 AM8/28/07
to iPhoneWebDev
Perfect, thanks! If you want functions available outside a given
script tag you have to define them like this:

window.myFunction = function() {}

...but no big deal. Any idea if there's a performance hit involved in
calling scripts this way?

David Feldman

unread,
Aug 28, 2007, 10:02:06 AM8/28/07
to iphone...@googlegroups.com
> Mobivity showed me a great way to do #2

Excellent, thanks.

On a related note, what's the best method for re-compressing iUI after
one makes changes to it?

(And, while I'm at it, can someone point me toward a primer on how to
use gzip for further compression? I've heard of it but am not familiar
with what it entails.)

--Dave

Reply all
Reply to author
Forward
0 new messages