CB-10522: Event binding in Hello World is misleading
Fixing the Hello World example
diff --git a/package.json b/package.json
index 0f9532d..618aeb9 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,8 @@
},
"main": "index.js",
"keywords": [
- "ecosystem:cordova"
+ "ecosystem:cordova",
+ "cordova:template"
],
"author": "Apache Software Foundation",
"license": "Apache version 2.0"
diff --git a/www/js/index.js b/www/js/index.js
index c31cd83..6963dc9 100644
--- a/www/js/index.js
+++ b/www/js/index.js
@@ -19,22 +19,17 @@
var app = {
// Application Constructor
initialize: function() {
- this.bindEvents();
+ document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
},
- // Bind Event Listeners
- //
- // Bind any events that are required on startup. Common events are:
- // 'load', 'deviceready', 'offline', and 'online'.
- bindEvents: function() {
- document.addEventListener('deviceready', this.onDeviceReady, false);
- },
+
// deviceready Event Handler
//
- // The scope of 'this' is the event. In order to call the 'receivedEvent'
- // function, we must explicitly call 'app.receivedEvent(...);'
+ // Bind any cordova events here. Common events are:
+ // 'pause', 'resume', etc.
onDeviceReady: function() {
- app.receivedEvent('deviceready');
+ this.receivedEvent('deviceready');
},
+
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);