Sample XHTML Code
Total Page:16
File Type:pdf, Size:1020Kb
Sample XHTML Code Docs version: 2.0 Version date 7/29/2009 Contents • Introduction • Home page • General page structure • Tabbed content • Navigation lists • iPhone action links Introduction These code samples illustrate how we designed and developed the user for the MIT Mobile Web. These code samples are taken from the original XHTML design mockups which were the basis of the final implementation of the live MIT Mobile Web. We’re presenting these design mockups here because showing the final functional code with its back-end integration would make it harder to read the actual markup as the web browser sees it – which is what determines what the end user actually sees and interacts with. The XHTML and CSS generated by the functional code is in any case very close to these original design mockups. We’re not presenting every page for every module here. Rather, we’re showing representative pages that illustrate user-interface patterns that appear throughout the MIT Mobile Web. After studying these code snippets and the patterns they represent, you should be able to easily understand how specific pages in the MIT Mobile Web were built, as well as how to go about building new page layouts sharing a consistent basic structure, function and building blocks. For background on why we optimized the UI for three different categories of devices, please read the Introduction to the Mobile Web document. Commented source code, images and other assets for the entire MIT Mobile Web – including functional code for back-end integration – is online as a SourceForge project at http://sourceforge.net/projects/mitmobileweb/. Important note: This document is intended for Web designers and client-side developers. As such, its contents, especially the code samples, are intentionally presented as static HTML as it would be rendered into the end-user’s device. The server-side (and, in some cases, client-side) logic that generates this HTML is not discussed here, and is instead the subject of the developer-centric documentation available elsewhere in this open- source project. Homepage The homepage provides quick and simple access to the major modules within the MIT Mobile Web. Homepage – Webkit For the Webkit versions of the homepage, we present the homepage as a space-efficient and touch- friendly grid of labeled icons. From left to right: iPhone, Palm Pre, Android. Note that only the iPhone, which supports certificates for authentication, shows the TechCASH (cashless payment system) and MIT Certificates icons; the Pre and Android (which do not yet support certificates) do not. HTML preamble. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml- basic11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="content-type" content="application/xhtml+xml" /> The viewport tag governs how content is initially scaled and whether it can be rescaled and reflowed: <meta name="viewport" id="viewport" content="width=device-width, user-scalable=no,initial- scale=1.0,maximum-scale=1.0" /> Link to the global platform-specific stylesheet (styles/webkit.css): <meta http-equiv="Content-Script-Type" content="text/javascript"> <title>MIT Mobile Web</title> <link rel="stylesheet" type="text/css" href="/styles/webkit.css" /> The optional apple-touch-icon tag lets you define a graphic that will appear on the iPhone device’s main homepage if you tap the ‘+’ button in the browser toolbar and choose to add the site to home: <link rel="apple-touch-icon" href="/images/webkit/icon.png" /> Inline styles were used extensively here only because this is the only page where these are used, and we wanted to minimize the number of separate files to download. These styles format the grid of icons and other homepage-specific formatting: <style type="text/css"> #homegrid { margin: 0 auto; padding: 0; margin-left: 2px; } #homegrid div { position: relative; width: 78px; height: 92px; margin: 0; padding: 0; float: left; font-size: 13px; line-height: 14px; text-align: center; vertical-align: top; } #homegrid a { display: block; color: #303336; text-decoration: none; padding: 8px 5px; } #homegrid a img { margin-bottom: 1px; } .intro { margin-bottom: 0; text-align: center; } .fineprint { font-size: 10px; color: #404649; } h1 { font-size: 32px; line-height: 32px; margin: 16px 15px 13px 12px; color: #112; } #logo { padding-right: 14px; } #new { position: absolute; top: -13px; right: -9px; width: 80px; height: 80px; background-image: url(images/newbig.png); background-repeat: no-repeat; color: #fff; font-size: 12px; line-height: 13px; text-align: center; overflow: hidden; } #new a { display: block; width: 50px; height: 50px; padding: 0; text-decoration: none; color: #fff; position: absolute; top: 19px; right: 10px; } #new a .newlabel { display: block; font-size: 9px; line-height: 9px; color: #ffcece; } #footer { margin-top: 0; padding-top: 24px; text-align: center; clear: both; } .badge { position: absolute; right: 10px; top: 2px; width: 24px; height: 24px; padding-top: 5px; font-size:12px; font-weight: bold; text-align: center; color: #fff; background-image: url(/images/webkit/badge.png); background-repeat: no-repeat; } </style> The iPhone web browser by default displays its titlebar and location at the top of the screen. This scrolls away along if the user scrolls a long page down. To reclaim this screen space, we have every page in our site automatically scroll to 1px from the top of the body, which effectively hides the titlebar and location and increases the height of the visible page area by 60 pixels. The empty onunload event handler addresses a usability issue where, if the user customizes their homepage settings and returns to the homepage using the browser’s Back button, the homepage may not refresh correctly. <body onload="scrollTo(0,1) onunload=""> Header with MIT branding: <h1><img src="images/mit-logo-home.gif" width="48" height="24" alt="" id="logo" />Mobile Web</h1> Large “What’s New” badge in upper right corner, which only appears if there is a recent announcement: <div id="new"><a href="/about/webkit/new/"><span class="newlabel">NEW:</span>Summer Shuttles</a></div> Primary navigation grid, using floated DIVs to create the evenly spaced grid. Whereas the initial build of the MIT Mobile Web used a table here, the page was converted to floating DIVs to better support rotated screens today and other screen resolutions in the future. Whereas the feature-phone and smartphone versions use a secondary navigation list to present the ‘About this Site’ link, here it’s presented as the last of the primary links. Note that certificate-requiring content and links (in this case, the TechCASH and MIT Certificates links) must be hidden from devices that we know not to support certificates (Pre and Android). The required code is not shown here, but can be easily implemented using client- or server-side code. <div id="container"> <div id="homegrid"> <div><a href="/people/webkit/"><img src="images/people.png" width="50" height="50" alt="People Directory" /><br/>People Directory</a></div> <div><a href="/map/webkit/"><img src="images/map.png" width="50" height="50" alt="Map" /><br/>Campus Map</a></div> <div><a href="/shuttletrack/webkit/"><img src="images/shuttletrack.png" width="50" height="50" alt="Shuttle Schedule" /><br/>Shuttle Schedule</a></div> <div><a href="/calendar/webkit/"><img src="images/calendar.png" width="50" height="50" alt="Events Calendar" /><br/>Events Calendar</a></div> <div><a href="/stellar/webkit/"><img src="images/stellar.png" width="50" height="50" alt="Stellar" /><br/>Stellar<br/><span class="fineprint">class info</span></a></div> <div><a href="/libraries/webkit/"><img src="images/libraries.png" width="50" height="50" alt="Libraries" /><br/>Libraries</a></div> <div><a href="/techcash/webkit/"><img src="images/techcash.png" width="50" height="50" alt="Tech Cash" /><br/>TechCASH</a></div> <div><a href="/emergency/webkit/"><img src="images/emergency.png" width="50" height="50" alt="Emergency Info" /><br/>Emergency Info</a></div> <div><a href="/3down/webkit/"><img src="images/3down.png" width="50" height="50" alt="3DOWN" /><br/>3DOWN<br/><span class="fineprint">service status</span></a></div> <div><a href="/careers/webkit/"><img src="images/careers.png" width="50" height="50" alt="Career Services" /><br/>Student Careers</a></div> <div><a href="/links/webkit/"><img src="images/links.png" width="50" height="50" alt="Links" /><br/>Useful<br/>Links</a></div> <div><a href="/sms/webkit/"><img src="images/sms.png" width="50" height="50" alt="SMS" /><br/>MIT SMS Service</a></div> <div><a href="/about/webkit/"><img src="images/certificates.png" width="50" height="50" alt="Certificates" /><br/>MIT Certificates</a></div> <div><a href="http://web.mit.edu"><img src="images/webmitedu.png" width="50" height="50" alt="web.mit.edu" /><br/>Full MIT Website</a></div> <div><a href="/about/webkit/"><img src="images/about.png" width="50" height="50" alt="About" /><br/>About this Site<span class="badge">2</span></a></div> <div><a href="/preferences/webkit/"><img src="images/preferences.png" width="50" height="50" alt="Preferences" /><br/>Customize Home</a></div> </div> <!-- id="homegrid" --> </div> <!-- id="container" --> Within the “About” <div>, there’s an optional <span class="badge">. This places a red badge with a number inside it, indicating the number of unread “What’s New in the MIT Mobile Web” announcements which can be accessed from the “About” page. Sitewide footer, with branding for IS&T (the MIT department responsible for the mobile web): <div id="footer"> <a href="http://web.mit.edu/ist/"><img src="/images/webkit/ist-logo.png" width="35" height="21" alt="IST" /></a>Information Services & Technology </div> </body> </html> Homepage – Touchscreen Like the Webkit category, the Touchscreen category is defined by large touch-driven interfaces.