K10 Design


HostGator

iUI 0.13 - An Overview

posted March 27, 2009, last updated April 27, 2009

This is my stab at documenting the iUI interface library/framework/whatever you want to call it. I do not claim to know this fully and welcome suggestions on how to improve this documentation.

Step 1: Link in iUI javascript and css files

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>iUI Music Demo</title>

<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
<style type="text/css" media="screen">@import "../iui/iui.css";</style>
<script type="application/x-javascript" src="../iui/iui.js"></script>
</head>
<body>

Step 2: Define toolbar and main menu

  • The toolbar is a div with the class of "toolbar". The definition of the right button is optional.
  • The main List or Div should have selected="true" as an attribute to make it the main panel
  • All Lists should have Ids, which are then referenced in hrefs
  • All Lists and Divs should have Title attirubtes, which are displayed at the top of the panels
  • Hrefs that are preceeded with the hash symbol (#) reference other "panels" (lists, divs, etc.) in the same html document.
  • To reference an external document, reference the page as normal - the page will be loaded via AJAX and inserted.
  • Pages loaded via AJAX should be snippets of html, not full html pages (i.e., no html or body tags). Also, note: scripts will not run when loaded in this manner.
  • To force a complete page replacement, make the target equal to "_self" on an anchor.
  • To replace an anchor with content loaded via AJAX, make the target equal to "_replace"
Figure 1
<div class="toolbar">
    <h1 id="pageTitle"></h1>
    <a id="backButton" class="button" href="#"></a>
    <a class="button" href="#searchForm">Search</a>
</div>

<ul id="home" title="Music" selected="true">
    <li><a href="#artists">Artists</a></li>
    <li><a href="#settings">Settings</a></li>
    <li><a href="stats.php">Stats</a></li>
    <li><a href="http://code.google.com/p/iui/" target="_self">About</a></li>
    <li>Nothing</li>

</ul>
			

Step 3: Define any sub-menus

A class of "group" on a list item makes the background the bluegreen color.

Figure 2
<ul id="artists" title="Artists">
    <li class="group">B</li>
    <li><a href="#TheBeatles">The Beatles</a></li>
    <li><a href="#BelleSebastian">Belle & Sebastian</a></li>
    <li class="group">C</li>
    <li><a href="#CrowdedHouse">Crowded House</a></li>
    <li class="group">J</li>
    <li><a href="#JennyLewis">Jenny Lewis</a></li>
    <li><a href="#JohnMayer">John Mayer</a></li>
    <li class="group">Z</li>
    <li><a href="#Zero7">Zero 7</a></li>

</ul>
			
 
Figure 3
<ul id="TheBeatles" title="The Beatles">
    <li><a href="#songs">Abbey Road</a></li>
    <li><a href="#songs">Help!</a></li>
    <li><a href="#songs">Rubber Soul</a></li>
    <li><a href="#songs">Sgt. Pepper's</a></li>
    <li><a href="#songs">White Album</a></li>

</ul>
			
 
Figure 4
<ul id="songs" title="Songs">
    <li><a href="#player">Song 1</a></li>
    <li><a href="#player">Song 2</a></li>
    <li><a href="#player">Song 3</a></li>
    <li><a href="#player">Song 4</a></li>
    <li><a href="#player">Song 5</a></li>
    <li><a href="#player">Song 6</a></li>
    <li><a href="#player">Song 7</a></li>
    <li><a href="#player">Song 8</a></li>
    <li><a href="#player">Song 9</a></li>
    <li><a href="#player">Song 10</a></li>
    <li><a href="#player">Song 11</a></li>

</ul>
			

Step 4: Define any panels/dialogs

Figure 5
<div id="player" class="panel" title="Now Playing">
    <h2>If this weren't just a demo, you might be hearing a song...</h2>
</div>
			

Note: this is a Div with a class of "panel", which gives the Div a blue pinstripe background

 
Figure 6
<form id="searchForm" class="dialog" action="search.php">
    <fieldset>
        <h1>Music Search</h1>
        <a class="button leftButton" type="cancel">Cancel</a>
        <a class="button blueButton" type="submit">Search</a>
        
        <label>Artist:</label>
        <input id="artist" type="text" name="artist"/>
        <label>Song:</label>
        <input type="text" name="song"/>
    </fieldset>

</form>
			

Note: this is a form, linked from the Search button in the toolbar, defined in Part 1. The buttons for the form are the "Cancel" button in the top-left and "Search" button in the top-right. Both "buttons" are really Anchors with Types of "Cancel" and "Submit", respectively.

 
Figure 8
<form selected="true" title="Login" class="panel" method="post" action="login.php" target="_self">
    <fieldset>
        <div class="row">
            <label>Username</label>
            <input type="text" name="username" value=""/>
        </div>
        <div class="row">
            <label>Password</label>
            <input type="password" name="password" value=""/>
        </div>
    </fieldset>
    <a class="whiteButton" type="submit" href="#">Login</a>
</form>
			

Complex panels

Here is an example of a complex panel, containing On/Off switches (replacements for checkboxes) and input text boxes. Also note the use of Fieldset and Divs with class "row" to create the rounded border style.

Note: the labels are of a width-length, as defined in the stylesheet. Because the label will not wrap properly, you may have to override the default width for the labels on particular panels.

Figure 7
<div id="settings" title="Settings" class="panel">
    <h2>Playback</h2>
    <fieldset>
        <div class="row">
            <label>Repeat</label>
            <div class="toggle" onclick=""><span class="thumb"></span><span class="toggleOn">ON</span><span class="toggleOff">OFF</span></div>
        </div>
        <div class="row">
            <label>Shuffle</label>
            <div class="toggle" onclick="" toggled="true"><span class="thumb"></span><span class="toggleOn">ON</span><span class="toggleOff">OFF</span></div>
        </div>
    </fieldset>
    
    <h2>User</h2>
    <fieldset>
        <div class="row">
            <label>Name</label>
            <input type="text" name="userName" value="johnappleseed"/>
        </div>
        <div class="row">
            <label>Password</label>
            <input type="password" name="password" value="delicious"/>
        </div>
        <div class="row">
            <label>Confirm</label>
            <input type="password" name="password" value="delicious"/>
        </div>
    </fieldset>

</div>
			

Striped tables

I have hobbled together some css and images to pseudo-replicate the iTunes-styled table:

Figure 9

Here's the CSS:

.itable					{ border: 1px solid gray; }
.itable tr.header th	{ text-align: left; }
.itable tr.alt			{ background-color: #eff7ff; }
.itable tr.reg			{ background-color: #fff; }
.itable th				{ background: url(/iui/blue_hd_bg.png) top left repeat-x; border-right: 1px solid grey; }
.itable th:last-child	{ border-right: none; }
.itable td				{ border-right: 1px solid gray; }
.itable tr:first-child	{ white-space: nowrap; }
.itable tr:last-child	{ border-right: none; }

Here is the background image for the header:

<div id="schedule" title="Schedule" class="panel">
	<table class="itable" width="100%" border="0" cellspacing="0" cellpadding="3">
		<tr class="header">
			<th>Per</th>
			<th>Days</th>
			<th>Room</th>
			<th class="last">Course Name</th>
		</tr>
		<tr class="reg">
			<td class="first">HR</td>
			<td>AB</td>
			<td>147</td>
			<td class="last">Homeroom 5-1</td>
		</tr>
		<tr class="alt">
			<td class="first">01</td>
			<td>AB</td>
			<td>147</td>
			<td class="last">Math Support</td>
		</tr>
		<tr class="reg">
			<td class="first">02-04</td>
			<td>AB</td>
			<td>147</td>
			<td class="last">Science 5</td>
		</tr>
		<tr class="alt">
			<td class="first">05-07</td>
			<td>AB</td>
			<td>146</td>
			<td class="last">Math 5</td>
		</tr>
		...
	</table>
</div>

Miscellaneous Observations

  • The current version of iui.js does not work properly when submitting forms. I made 2 changes to iui.js:
    1. In the function "showPageByHref", change:

      req.open(method || "GET", href, true);

      to

      req.open("POST", href, true);

    2. Updated 04/16/2009: I have changed the "submitForm" function to the following:

      function submitForm(form)
      {
      	if (form.getAttribute("target") == "_self")
      		form.submit();
      	else
          	iui.showPageByHref(form.action, encodeForm(form), form.method || "POST");
      }
      

      This both fixes a problem with the showPageByHref call and adds the ability to submit a form in the normal manner by adding target="_self" to the form tag.

  • To capture values as you go through the menus, use the onClick event on the link to put values in a form, or pass to a javascript function.

  • If you have tried viewing your pages in Firefox, you'll notice the background images don't show around buttons. The buttons are drawn using the CSS attribute border-image, which Firefox does not support quite yet. Per a post from John Resig about the border-image CSS attribute, Firefox 3.1 will have border-image support. To prepare ahead of time, I recommend looking for -webkit-border-image in iui.css, duplicating the line containing it, and changing the beginning to -moz-border-image.

  • I was surprised the slider form element did not work on the iPhone, so after looking at this article at NextRoot about the onTouchStart, Move, and End events that replaces the mouse events on Mobile Safari, I created my own. After I clean it up, I'll add it to this page as well.

Further Experimentation (updated 04/27/2009)

I have a demo page for iUI where I have been adding enhancements - peruse it if you like.

The following enhancements have been added:

  • Dynamic loading of styelsheets when panel loads:
    <ul stylesheet="sample.css">
  • Dynamic loading of script when panel loads:
    <ul script="sample.js">
  • Defining "action button" (top-right button) per panel:
    <ul actionbutton="{'title' : 'New Widget', 'href='#newWidget', 'target' : null}">
  • Call when panel loads the first time:
    <ul onload="func()">
  • Call when panel has focus:
    <ul onfocus="func()">
  • Call when panel loses focus:
    <ul onblur="func()">
  • Call when panel is "unloaded" (back button is clicked):
    <ul onunload="func()">

Please send me any suggestions/comments to: cwzachary@roadrunner.com.