<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: wekbit code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 14:31:22 GMT</pubDate>
    <description>DZone Snippets: wekbit code</description>
    <item>
      <title>iPhone Orientation</title>
      <link>http://snippets.dzone.com/posts/show/4912</link>
      <description>iPhoneOrientation&lt;br /&gt;Demonstrates how to handle iPhone or iPod touch orientation events using HTML, CSS, and JavaScript.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;index.html&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;&lt;br /&gt;&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;&lt;br /&gt;&lt;head&gt;&lt;br /&gt;		&lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;&lt;br /&gt;		&lt;meta name="viewport" content="width=device-width, user-scalable=no" /&gt;&lt;br /&gt;		&lt;title&gt;Handling iPhone or iPod touch Orientation Events&lt;/title&gt; &lt;br /&gt;		&lt;br /&gt;		&lt;!-- The iPhoneOrientation.css file is used to adjust the page appearance --&gt;&lt;br /&gt;		&lt;link rel="stylesheet" href="iPhoneOrientation.css" type="text/css" /&gt;&lt;br /&gt;		&lt;br /&gt;		&lt;!-- The iPhoneOrientation.js file shows how to handle iPhone orientation events --&gt;&lt;br /&gt;		&lt;script type="text/javascript" src="iPhoneOrientation.js"&gt;&lt;/script&gt;&lt;br /&gt;&lt;/head&gt;&lt;br /&gt;&lt;body class="portrait"&gt;&lt;br /&gt;		&lt;!-- Display a message that describes the current iPhone orientation after rotation --&gt;&lt;br /&gt;		&lt;div id="currentOrientation"&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;		&lt;!-- The container div is made of two inner divs: leftContainer and rightContainer. The leftContainer and rightContainer are stacked&lt;br /&gt;				 up one above the other when iPhone is in portrait orientation and side by side when iPhone is in landscape orientation --&gt;&lt;br /&gt;		&lt;div id="container"&gt;&lt;br /&gt;			&lt;!--The button class is used to build a rounded rectangle around each text --&gt;&lt;br /&gt;			&lt;!--The page appearance changes whenever iPhone rotates between portrait and landscape display views --&gt;&lt;br /&gt;			&lt;div id="leftContainer"&gt;&lt;br /&gt;					&lt;div class="button" onclick="window.location.href='http://developer.apple.com/documentation/AppleApplications/Reference/SafariWebContent/DebuggingSafarioniPhoneContent/chapter_10_section_1.html'"&gt;Debug Console&lt;/div&gt;&lt;br /&gt;					&lt;div class="button" onclick="window.location.href='http://developer.apple.com/documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/chapter_4_section_8.html'"&gt;Viewport Settings&lt;/div&gt;&lt;br /&gt;			&lt;/div&gt;&lt;br /&gt;			&lt;div id="rightContainer"&gt;&lt;br /&gt;					&lt;div class="button" onclick="window.location.href='http://developer.apple.com/documentation/AppleApplications/Reference/SafariWebContent/AdjustingtheTextSize/chapter_5_section_4.html'"&gt;Highlighting Elements&lt;/div&gt;&lt;br /&gt;					&lt;div class="button" onclick="window.location.href='http://developer.apple.com/documentation/AppleApplications/Reference/SafariWebContent/DesigningForms/chapter_7_section_1.html'"&gt;Form Auto Correction&lt;/div&gt;&lt;br /&gt;			&lt;/div&gt;&lt;br /&gt;		&lt;/div&gt;&lt;br /&gt;	&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;iPhoneOrientation.css&lt;br /&gt;&lt;code&gt;&lt;br /&gt;body &lt;br /&gt;{&lt;br /&gt;		margin: 0px;&lt;br /&gt;		padding: 0px;&lt;br /&gt;		font-size: 12px;&lt;br /&gt;		font-family: 'Lucida Grande', Verdana, sans-serif;&lt;br /&gt;		font-weight: bold;&lt;br /&gt;		/* Turn off font resizing */&lt;br /&gt;		-webkit-text-size-adjust: none;   &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* Set the background color of the page when the body tag's class attribute is equal to portrait. &lt;br /&gt;   The expression body[class="value"] is a CSS attribute selector where "body" is the html element to be styled, "class" the body's attribute to be&lt;br /&gt;   manipulated, and "value" the class attribute's value, which is either portrait, landscapeLeft, or landscapeRight.&lt;br /&gt;   This expression is used to dynamically select a body style according to the class attribute value. For instance, if the body's class attribute is set&lt;br /&gt;   to landscapeLeft, then all style declarations matching body[class="landscapeLeft"] will be used to style "Handling iPhone or iPod touch Orientation Events". &lt;br /&gt;   The JavaScript updateOrientation function in the iPhoneOrientation.js file is used to set the body's class attribute to one of these values.&lt;br /&gt;   Further information about CSS attribute selectors can be found at  http://www.w3.org/TR/css3-selectors/#attribute-selectors.&lt;br /&gt; */&lt;br /&gt;body[class="portrait"] &lt;br /&gt;{&lt;br /&gt;		background: white;    	&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* Adjust a button when the body's class attribute is equal to portrait */&lt;br /&gt;body[class="portrait"] .button    &lt;br /&gt;{	&lt;br /&gt;		background: white;&lt;br /&gt;		width: 210px;&lt;br /&gt;		height: 13px;&lt;br /&gt;		&lt;br /&gt;		padding: 10px 0px;&lt;br /&gt;		margin: 10px auto;&lt;br /&gt;		&lt;br /&gt;		font-size: 15px;&lt;br /&gt;		&lt;br /&gt;		/* text is black on the button */&lt;br /&gt;		color: black;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* The leftContainer and rightContainer div elements are stacked up one after the other when the body's class attribute is equal to portrait. &lt;br /&gt;   They are both 200 pixels wide. */&lt;br /&gt;body[class="portrait"] #leftContainer&lt;br /&gt;{&lt;br /&gt;		width: 200px;&lt;br /&gt;		margin: auto auto;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;body[class="portrait"] #rightContainer&lt;br /&gt;{&lt;br /&gt;		width: 200px;&lt;br /&gt;		margin: auto auto;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* Set the background color of the page when the body's class attribute is set to landscapeLeft */&lt;br /&gt;body[class="landscapeLeft"] &lt;br /&gt;{&lt;br /&gt;		background: lightgrey;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* Adjust a button when the body's class attribute is set to landscapeLeft */&lt;br /&gt;body[class="landscapeLeft"] .button  &lt;br /&gt;{&lt;br /&gt;		background: black;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* The container div is evenly split between leftContainer and rightContainer when the body's class attribute is set to landscapeLeft.&lt;br /&gt;   leftContainer and rightContainer are stacked side by side. leftContainer aligns buttons to the left side of the page; &lt;br /&gt;   rightContainer aligns buttons to the right side of the page. */&lt;br /&gt;body[class="landscapeLeft"] #leftContainer&lt;br /&gt;{&lt;br /&gt;		width: 50%;&lt;br /&gt;		/* Align the div to the left of the page  */&lt;br /&gt;		float: left;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;body[class="landscapeLeft"] #rightContainer&lt;br /&gt;{&lt;br /&gt;		width: 50%;&lt;br /&gt;		/* Align the div to the right of the page  */&lt;br /&gt;		float: right;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* Set the background color of the page when the body's class attribute is equal to landscapeRight */&lt;br /&gt;body[class="landscapeRight"] &lt;br /&gt;{&lt;br /&gt;		background: tan;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* Adjust a button when the body's class attribute is equal to landscapeRight */&lt;br /&gt;body[class="landscapeRight"] .button  &lt;br /&gt;{&lt;br /&gt;		background: darkred;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* The container div is evenly split between leftContainer and rightContainer when the body's class attribute is set to landscapeRight.&lt;br /&gt;   leftContainer aligns buttons to the left side of the page; rightContainer aligns buttons to the right side of the page. */&lt;br /&gt;body[class="landscapeRight"] #leftContainer&lt;br /&gt;{&lt;br /&gt;		width: 50%;&lt;br /&gt;		float: left;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;body[class="landscapeRight"] #rightContainer&lt;br /&gt;{&lt;br /&gt;		width: 50%;&lt;br /&gt;		float: right;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* Draw a rounded rectangle around a text */&lt;br /&gt; .button    &lt;br /&gt;{&lt;br /&gt;		font-weight: bold;&lt;br /&gt;		text-align: center;&lt;br /&gt;		&lt;br /&gt;		width: 130px;&lt;br /&gt;		height: 13px;&lt;br /&gt;		font-size: 10px;&lt;br /&gt;		&lt;br /&gt;		/* text is white on the button */&lt;br /&gt;		color: white;	&lt;br /&gt;	&lt;br /&gt;		/* Draw a rectangle around a text */&lt;br /&gt;		border: 1px solid black;    &lt;br /&gt;		&lt;br /&gt;		/* Round each corner of the generated rectangle */&lt;br /&gt;		-webkit-border-radius: 5px;   &lt;br /&gt;		padding: 5px 0px;&lt;br /&gt;		margin: 5px auto;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* Defines styling properties for the currentOrientation div, which shows a message that indicates iPhone's current orientation after rotation */&lt;br /&gt;#currentOrientation&lt;br /&gt;{		&lt;br /&gt;		width: 280px;&lt;br /&gt;		text-align: center;&lt;br /&gt;		margin: 10px auto;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;a&lt;br /&gt;{&lt;br /&gt;		text-decoration: none;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* The container div contains four buttons that are evenly divided between the inner leftContainer and rightContainer div elements.&lt;br /&gt;   Its width does not change when iPhone switches between portrait and landscape orientations. */&lt;br /&gt;#container&lt;br /&gt;{&lt;br /&gt;		/* fixed width across all iPhone orientation changes */&lt;br /&gt;		width: 300px;&lt;br /&gt;		margin: 10px auto;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;iPhoneOrientation.js&lt;br /&gt;&lt;code&gt;&lt;br /&gt;/* updateOrientation checks the current orientation, sets the body's class attribute to portrait, landscapeLeft, or landscapeRight, &lt;br /&gt;   and displays a descriptive message on "Handling iPhone or iPod touch Orientation Events".  */&lt;br /&gt;function updateOrientation()&lt;br /&gt;{&lt;br /&gt;	/*window.orientation returns a value that indicates whether iPhone is in portrait mode, landscape mode with the screen turned to the&lt;br /&gt;	  left, or landscape mode with the screen turned to the right. */&lt;br /&gt;	var orientation=window.orientation;&lt;br /&gt;	switch(orientation)&lt;br /&gt;	{&lt;br /&gt;	&lt;br /&gt;		case 0:&lt;br /&gt;				/* If in portrait mode, sets the body's class attribute to portrait. Consequently, all style definitions matching the body[class="portrait"] declaration&lt;br /&gt;				   in the iPhoneOrientation.css file will be selected and used to style "Handling iPhone or iPod touch Orientation Events". */&lt;br /&gt;				document.body.setAttribute("class","portrait");&lt;br /&gt;				&lt;br /&gt;				/* Add a descriptive message on "Handling iPhone or iPod touch Orientation Events"  */&lt;br /&gt;				document.getElementById("currentOrientation").innerHTML="Now in portrait orientation (Home button on the bottom).";&lt;br /&gt;				break;	&lt;br /&gt;				&lt;br /&gt;		case 90:&lt;br /&gt;				/* If in landscape mode with the screen turned to the left, sets the body's class attribute to landscapeLeft. In this case, all style definitions matching the&lt;br /&gt;				   body[class="landscapeLeft"] declaration in the iPhoneOrientation.css file will be selected and used to style "Handling iPhone or iPod touch Orientation Events". */&lt;br /&gt;				document.body.setAttribute("class","landscapeLeft");&lt;br /&gt;				&lt;br /&gt;				document.getElementById("currentOrientation").innerHTML="Now in landscape orientation and turned to the left (Home button to the right).";&lt;br /&gt;				break;&lt;br /&gt;		&lt;br /&gt;		case -90:	&lt;br /&gt;				/* If in landscape mode with the screen turned to the right, sets the body's class attribute to landscapeRight. Here, all style definitions matching the &lt;br /&gt;				   body[class="landscapeRight"] declaration in the iPhoneOrientation.css file will be selected and used to style "Handling iPhone or iPod touch Orientation Events". */&lt;br /&gt;				document.body.setAttribute("class","landscapeRight");&lt;br /&gt;				&lt;br /&gt;				document.getElementById("currentOrientation").innerHTML="Now in landscape orientation and turned to the right (Home button to the left).";&lt;br /&gt;				break;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Point to the updateOrientation function when iPhone switches between portrait and landscape modes.&lt;br /&gt;window.onorientationchange=updateOrientation;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Source: http://developer.apple.com/samplecode/iPhone/idxSafari-date.html&lt;br /&gt;( &lt;a href="http://www.ab-d.fr/"&gt;AB-D&lt;/a&gt; )&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Sat, 22 Dec 2007 12:53:44 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4912</guid>
      <author>ki4ngel (Benoit Asselin)</author>
    </item>
  </channel>
</rss>
