Using the latest version of both Phonegap and JQM, how do I got about setting up the two events, deviceready
and mobileinit
?
(I have looked through the answers on here but they are outdated and give little info)
I am currently using the onload function, but there is severe lag - I can click a button that should fire a notification and it is delayed by several seconds.
Should I be using the jQuery $(document).ready()
?
What is the correct order for mobileinit
and deviceready
?
Where should my own code go?
current code below:
<script type="text/javascript" src="phonegap.js"></script>
<script type="text/javascript" src="js/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).bind("mobileinit", function() {
$.mobile.allowCrossDomainPages = true;
$.mobile.buttonMarkup.hoverDelay = 0;
$.mobile.defaultDialogTransition = 'none';
$.mobile.defaultPageTransition = 'none';
});
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
$(document).on('click', '.add-alarm', function() {
var now = new Date().getTime(),
_60_seconds_from_now = new Date(now + 5*1000);
window.plugin.notification.local.add({
title: 'title herre',
message: 'my message',
date: _60_seconds_from_now,
sound: 'TYPE_ALARM'
});
});
}
</script>
onLoad()
fired by
<body onload="onLoad()">