You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2019/11/22 13:34:54 UTC

[cordova-app-hello-world] branch master updated: Simplify demo app JavaScript (#55)

This is an automated email from the ASF dual-hosted git repository.

raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-app-hello-world.git


The following commit(s) were added to refs/heads/master by this push:
     new 45bdc7c  Simplify demo app JavaScript (#55)
45bdc7c is described below

commit 45bdc7c388f3db8fe78cf47d4547c5b5878ee030
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Fri Nov 22 14:34:48 2019 +0100

    Simplify demo app JavaScript (#55)
    
    * more helpful stupid-friendly index.js
    
    * Update comments
    
    * Further simplify index.js
    
    * Actually use some Cordova APIs in onDeviceReady
---
 template_src/www/css/index.css |  3 +++
 template_src/www/js/index.js   | 33 ++++++++-------------------------
 2 files changed, 11 insertions(+), 25 deletions(-)

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 @@ h1 {
     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');
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org