Simplify demo app JavaScript (#55)
* more helpful stupid-friendly index.js
* Update comments
* Further simplify index.js
* Actually use some Cordova APIs in onDeviceReady
diff --git a/template_src/www/css/index.css b/template_src/www/css/index.css
index 85724a8..4ddca0d 100644
--- a/template_src/www/css/index.css
+++ b/template_src/www/css/index.css
@@ -89,6 +89,9 @@
display:none;
}
+#deviceready.ready .event.listening { display: none; }
+#deviceready.ready .event.received { display: block; }
+
@keyframes fade {
from { opacity: 1.0; }
50% { opacity: 0.4; }
diff --git a/template_src/www/js/index.js b/template_src/www/js/index.js
index 6963dc9..6fc66e5 100644
--- a/template_src/www/js/index.js
+++ b/template_src/www/js/index.js
@@ -16,31 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-var app = {
- // Application Constructor
- initialize: function() {
- document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
- },
- // deviceready Event Handler
- //
- // Bind any cordova events here. Common events are:
- // 'pause', 'resume', etc.
- onDeviceReady: function() {
- this.receivedEvent('deviceready');
- },
+// Wait for the deviceready event before using any of Cordova's device APIs.
+// See https://cordova.apache.org/docs/en/latest/cordova/events/events.html#deviceready
+document.addEventListener('deviceready', onDeviceReady, false);
- // Update DOM on a Received Event
- receivedEvent: function(id) {
- var parentElement = document.getElementById(id);
- var listeningElement = parentElement.querySelector('.listening');
- var receivedElement = parentElement.querySelector('.received');
+function onDeviceReady() {
+ // Cordova is now initialized. Have fun!
- listeningElement.setAttribute('style', 'display:none;');
- receivedElement.setAttribute('style', 'display:block;');
-
- console.log('Received Event: ' + id);
- }
-};
-
-app.initialize();
\ No newline at end of file
+ console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
+ document.getElementById('deviceready').classList.add('ready');
+}