topical media & game development
mobile-js-jquery-ch06.txt / txt
chapter: The Framework and JavaScript
==================
document.bind('mobileinit', function() {
// Initialization code here
});
====================================
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>My first jQuery Mobile code</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-
1.0.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<!-- CUSTOM INITIALIZATION CODE -->
<script src="customcode.js"></script>
<script src="http://code.jquery.com/mobile/1.0/jquery.mobile-
1.0.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
</html>
====================================
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script>
document.bind("mobileinit", function() {
// Our initialization code here
});
<script>
<script src="http://code.jquery.com/mobile/1.0/jquery.mobile-
1.0.min.js"></script>
====================================
document.bind("mobileinit", function() {
// We change default values
.mobile.minScrollBack = 150;
.mobile.ns = "firt";
});
====================================
<div data-firt-role="page">
<div data-firt-role="header" data-firt-theme="a">
</div>
<div data-firt-role="content">
</div>
</div>
====================================
// Global strings
.mobile.pageLoadErrorMessage = "Error Loading Page";
// Widget strings
.mobile.dialog.prototype.options.closeBtnText = "Close"
.mobile.collapsible.prototype.options. collapseCueText = " click to collapse contents";
.mobile.selectmenu.prototype.options.closeText = "Close";
====================================
document.bind('mobileinit', function() {
// Global strings
.mobile.pageLoadErrorMessage = "Error Cargando Página";
// Widget strings
.mobile.dialog.prototype.options.closeBtnText = "Cerrar"
.mobile.collapsible.prototype.options. collapseCueText =
" click para cerrar contenido";
.mobile.selectmenu.prototype.options.closeText = "Cerrar";
});
====================================
document.bind('mobileinit', function() {
.mobile.page.prototype.options.addBackBtn = true;
.mobile.page.prototype.options.headerTheme = "b";
.mobile.listview.prototype.filter = true;
// Enables non-native menus for all selects
.mobile.activePage.id;
====================================
.mobile.changePage($("#pageId"));
====================================
.mobile.changePage(<productdetail.php>, {
method: "post",
data: {
action: 'getProduct',
id: idProduct
},
transition: "fade"
});
}
</script>
<!-- ... -->
<a href="javascript:viewProduct(5200)" data-role="button">Product details</a>
====================================
// This code shows the loading message and hide it after 2 seconds
.mobile.hidePageLoadingMsg();
}, 2000);
====================================
.mobile.defaultTransitionHandler = explodeTransitionHandler;
====================================
<div data-role="page">
<div data-role="header">
<h1>Dynamic page</h1>
</div>
<div data-role="content">
<a id="button1" href="javascript:addPages()" data-role="button">Add Pages</a>
<ul id="list1">
</ul>
</div>
</div>
====================================
function addPages() {
for (var i=1; i<5; i++) {
var page = $("<div>").jqmData("role", "page").attr("id", "page" + i);
// header
$("<div>").attr("data-role", "header").append($("<h1>")
.html("Page " + i)).appendTo(page);
// content
$("<div>").attr("data-role", "content").append($("<p>")
.html("Contents for page " + i))
.appendTo(page);
$("body").append(page);
$("<li>").append($("<a>").attr("href", "#page"+i).html("Go to page " + i))
.appendTo("#list1");
}
$("#button1").hide();
};
====================================
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8" />
<title>jQuery Mobile</title>
<script src="jquery.js"></script>
<link rel="stylesheet" type="text/css" href="jquery.mobile-1.0.css">
<script src="jquery.mobile-1.0.js"></script>
<script>
document.bind('pagebeforechange', function(event, data) {
// We receive the destination page in data.toPage and we normalize it
var url = .mobile.changePage($("#pageTemplate"), {dataUrl: data.toPage});
// We prevent normal page transition
event.preventDefault();
}
});
</script>
<meta name="viewport" content="width=device-width,user-scalable=no">
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>Dynamic pages</h1>
</div>
<div data-role="content">
<a id="button1" href="#page1" data-role="button">Page 1</a>
<a id="button1" href="#page2" data-role="button">Page 2</a>
<a id="button1" href="#page3" data-role="button">Page 3</a>
<a id="button1" href="#page4" data-role="button">Page 4</a>
</div>
</div>
<div data-role="page" id="pageTemplate">
<div data-role="header">
<h1>Header</h1>
</div>
<div data-role="content">Content</div>
<div data-role="footer">
<h4>Footer</h4>
</div>
</div>
</body>
</html>
====================================
$("a").button();
====================================
var button = $("<a>").attr("href", "somewhere.html").button();
====================================
$("#list1").listview('refresh');
$("#checkbox").val('true').checkboxradio('refresh');
====================================
<ul id="list1">
</ul>
====================================
$("#list1").listview('refresh');
====================================
$("#element").grid();
====================================
$("#content").html(newHTMLcontentWithWidgets);
$("#page1").trigger("create");
====================================
$("#page2").live("pageinit", function(event) {
});
====================================
document.bind("pageloadfailed", function(event, data) {
data.preventDefault();
// Custom error management
});
====================================
document.bind("orientationchange", function(orientation) {
if (orientation=="landscape") {
// We are now in landscape
} else {
// We are now in portrait
}
});
====================================
document.bind("mobileinit", function() {
$("#page2").live("swiperight", goBackToPage1);
});
function goBackToPage1() {
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.