I'm trying to build an app using OnsenUI 2 (rc12 currently) and jQuery (3.0.0). There are many examples using the ons.ready() to do ... something. What confuses me is that Getting started example on their website uses the function. (Both examples are headers of the index.html)
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="lib/onsen/css/onsenui.css"/>
<link rel="stylesheet" href="lib/onsen/css/onsen-css-components.css"/>
<script src="lib/onsen/js/onsenui.js"></script>
<script>
ons.ready(function() {
// Init code here
});
</script>
</head>
<body>
<ons-navigator>
<ons-page>
Page 1
</ons-page>
</ons-navigator>
</body>
</html>
Yet the templates in Visual Studio 2015 don't.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="mobile-web-app-capable" content="yes" />
<!-- JS dependencies (order matters!) -->
<script src="scripts/platformOverrides.js"></script>
<script src="lib/onsen/js/onsenui.js"></script>
<!-- CSS dependencies -->
<link rel="stylesheet" href="lib/onsen/css/onsenui.css" />
<link rel="stylesheet" href="lib/onsen/css/onsen-css-components-blue-basic-theme.css" />
<title>Onsen UI Tabbar</title>
<!-- App init -->
<script>
function alertMessage(){
ons.notification.alert('Tapped!');
}
document.addEventListener('init', function(event) {
var page = event.target;
if(page.id === "home-page") {
var i = 5,
onsListContent = '',
onsListItem = document.querySelector('#main-list').innerHTML;
while(--i) {
onsListContent += onsListItem;
}
document.getElementById('main-list').innerHTML = onsListContent;
}
if(page.id === "settings-page") {
}
});
</script>
Yet, OnsenUI documentation for Tabbar (layout template; same as the one in the VS2015 example) does use it (doesn't show it in context though).
ons.ready(function() {
var myTabbar = document.querySelector("ons-tabbar")
myTabbar.addEventListener("prechange", function(e) {
if (e.index == 1) {
e.cancel();
}
})
})
And the OnsenUI interactive tutorials are the same. About half of them uses it and the other doesn't. When should I use it?