phonegap-day-workshop-beginner
phonegap-day-workshop-beginner copied to clipboard
Vibration
Hello I just started using Phonegap today, And Im having trouble getting the vibration part to work. Can anyone suggest anything or tell me what I'm doing wrong? here is my code:
var app = { // Application Constructor initialize: function() { this.bindEvents(); }, // 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(...);' onDeviceReady: function() { app.receivedEvent('deviceready'); navigator.vibrate(3000); }, // Update DOM on a Received Event receivedEvent: function(id) { var parentElement = document.getElementById(id); var listeningElement = parentElement.querySelector('.listening'); var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
}
};
Did you include the plugin in your build system and in the config file? Also does your device support it? There are devices without it.
On Thursday, June 4, 2015, marcusalan [email protected] wrote:
Hello I just started using Phonegap today, And Im having trouble getting the vibration part to work. Can anyone suggest anything or tell me what I'm doing wrong? here is my code:
var app = { // Application Constructor initialize: function() { this.bindEvents(); }, // 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(...);' onDeviceReady: function() { app.receivedEvent('deviceready'); navigator.vibrate(3000); }, // Update DOM on a Received Event receivedEvent: function(id) { var parentElement = document.getElementById(id); var listeningElement = parentElement.querySelector('.listening'); var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;'); receivedElement.setAttribute('style', 'display:block;'); console.log('Received Event: ' + id);}
};
— Reply to this email directly or view it on GitHub https://github.com/mwbrooks/phonegap-day-workshop-beginner/issues/1.