Guest User

Untitled

a guest
Nov 17th, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <link rel="stylesheet" type="text/css" href="css/index.css" />
  2.         <title>Hello World</title>
  3.  
  4.     <script>
  5.     var app = {
  6.     // Application Constructor
  7.     initialize: function() {
  8.       this.bindEvents();
  9.     },
  10.     // Bind Event Listeners
  11.     //
  12.     // Bind any events that are required on startup. Common events are:
  13.     // 'load', 'deviceready', 'offline', and 'online'.
  14.     bindEvents: function() {
  15.       document.addEventListener('deviceready', this.onDeviceReady, false);
  16.     },
  17.     // deviceready Event Handler
  18.     //
  19.     // The scope of 'this' is the event. In order to call the 'receivedEvent'
  20.     // function, we must explicitly call 'app.receivedEvent(...);'
  21.     onDeviceReady: function() {
  22.       app.receivedEvent('deviceready');
  23.       var pushConfig = {
  24.         pushServerURL: "http://localhost:8080/ag-push/",
  25.         android: {
  26.           senderID: "admin",
  27.           variantID: "...",
  28.           variantSecret: "..."
  29.         }
  30.       };
  31.   push.register(app.onNotification, successHandler, errorHandler, pushConfig);
  32.  
  33.   function successHandler() {
  34.     console.log('success')
  35.   }
  36.  
  37.   function errorHandler(message) {
  38.     console.log('error ' + message);
  39.   }
  40.   },
  41.   onNotification: function(event) {
  42.     alert(event.alert);
  43.   },
  44.   // Update DOM on a Received Event
  45.   receivedEvent: function(id) {
  46.     var parentElement = document.getElementById(id);
  47.     var listeningElement = parentElement.querySelector('.listening');
  48.     var receivedElement = parentElement.querySelector('.received');
  49.  
  50.     listeningElement.setAttribute('style', 'display:none;');
  51.     receivedElement.setAttribute('style', 'display:block;');
  52.  
  53.     console.log('Received Event: ' + id);
  54.   }
  55.   };
  56.  
  57.     </script>
  58.  
  59. </head>
  60.  
  61. <body>
  62.     <div class="app">
  63.         <h1>PhoneGap prova</h1>
  64.         <div id="deviceready" class="blink">
  65.             <p class="event listening">Connecting to Device</p>
  66.             <p class="event received">Device is Ready</p>
  67.         </div>
  68.     </div>
  69.     <script type="text/javascript" src="cordova.js"></script>
  70.     <script>app.initialize();</script>
  71. </body>
  72.  
  73. </html>
Advertisement
Add Comment
Please, Sign In to add comment