SHARE
TWEET

Untitled

a guest Jan 21st, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.   return {
  3.     // Lifecycle Hooks
  4.     beforeCreate() {
  5.       //console.log('componentBeforeCreate', this)
  6.     },
  7.     created() {
  8.       //console.log('componentCreated', this)
  9.     },
  10.     beforeMount() {
  11.       //console.log('componentBeforeMount', this)
  12.     },
  13.     mounted() {
  14.       //console.log('componentMounted', this);
  15.     },
  16.     beforeDestroy() {
  17.       //console.log('componentBeforeDestroy', this);
  18.     },
  19.     destroyed() {
  20.       //console.log('componentDestroyed', this);
  21.     },
  22.     // Component Data
  23.     data: function () {
  24.       // Must return an object
  25.       return {
  26.         options: { frequency: 500 }, // Update interval
  27.         gyro_enabled: false,
  28.       }
  29.     },
  30.     // Component Methods
  31.     methods: {
  32.  
  33.       gyroOnSuccess: function (acceleration) {
  34.         $$('#gyro').html(`
  35.               <div style="text-align: center;">X: ${acceleration.x.toFixed(4)}</div>
  36.               <div style="text-align: center;">Y: ${acceleration.y.toFixed(4)}</div>
  37.               <div style="text-align: center;">Z: ${acceleration.z.toFixed(4)}</div>`);
  38.       },
  39.  
  40.       gyroOnError: function (error) {
  41.         $$('#gyro').html(`
  42.             <div style="text-align: center;">Code: ${error.code}</div>
  43.             <div style="text-align: center;">Message: ${error.message}</div>`);
  44.       },
  45.  
  46.       gpsOnSuccess: function (position) {
  47.         $$('#gps').html(`
  48.             <div style="text-align: center;">X: ${position.coords.latitude.toFixed(4)}</div>
  49.             <div style="text-align: center;">Y: ${position.coords.longitude.toFixed(4)}</div>
  50.             <div style="text-align: center;">Z: ${position.coords.altitude.toFixed(4)}</div>`);
  51.       },
  52.  
  53.  
  54.       gpsOnError: function (error) {
  55.         $$('#gps').html(`
  56.             <div style="text-align: center;">Code: ${error.code}</div>
  57.             <div style="text-align: center;">Message: ${error.message}</div>`);
  58.       },
  59.  
  60.       testFunc: function () {
  61.         this.checkConnection();
  62.         //navigator.geolocation.watchPosition(this.gpsOnSuccess, this.gpsOnError, this.options);
  63.         navigator.vibrate(1500);
  64.         if (this.gyro_enabled == false) {
  65.           navigator.accelerometer.watchAcceleration(this.gyroOnSuccess, this.gyroOnError, this.options);
  66.           this.gyro_enabled = true;
  67.         };
  68.       },
  69.  
  70.       checkConnection: function () {
  71.         var networkState = navigator.connection.type;
  72.  
  73.         var states = {};
  74.         states[Connection.UNKNOWN] = 'Unknown';
  75.         states[Connection.ETHERNET] = 'Ethernet';
  76.         states[Connection.WIFI] = 'WiFi';
  77.         states[Connection.CELL_2G] = 'Cell 2G';
  78.         states[Connection.CELL_3G] = 'Cell 3G';
  79.         states[Connection.CELL_4G] = 'Cell 4G';
  80.         states[Connection.CELL] = 'Cell generic';
  81.         states[Connection.NONE] = 'No network';
  82.  
  83.         $$('#networktype').html(`
  84.                     <div style="text-align: center;">Network type: ${states[networkState]}</div>`
  85.         );
  86.       },
  87.     },
  88.     // Page Events
  89.     on: {
  90.       pageMounted: function (e, page) {
  91.         //console.log('pageMounted', page);
  92.       },
  93.       pageInit: function (e, page) {
  94.         //console.log('pageInit', page);
  95.       },
  96.       pageBeforeIn: function (e, page) {
  97.         //console.log('pageBeforeIn', page);
  98.       },
  99.       pageAfterIn: function (e, page) {
  100.         //console.log('pageAfterIn', page);
  101.       },
  102.       pageBeforeOut: function (e, page) {
  103.         //console.log('pageBeforeOut', page);
  104.       },
  105.       pageAfterOut: function (e, page) {
  106.         //console.log('pageAfterOut', page);
  107.       },
  108.       pageBeforeRemove: function (e, page) {
  109.         //console.log('pageBeforeRemove', page);
  110.       },
  111.     }
  112.   }
  113.  
  114.  
  115.  
  116. </script>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top