Skip to content

Instantly share code, notes, and snippets.

@Maxim-Kolmogorov
Created January 6, 2021 15:06
Show Gist options
  • Save Maxim-Kolmogorov/fca059291ce86f900d21ecf67d8cb260 to your computer and use it in GitHub Desktop.
Save Maxim-Kolmogorov/fca059291ce86f900d21ecf67d8cb260 to your computer and use it in GitHub Desktop.
Tutorial: Cordova plugin in Swift. Part 5.
var app = {
initialize: function() {
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
},
onDeviceReady: function() {
this.receivedEvent('deviceready');
echotest.echo('YO BRO!', function(msg) {
document.getElementById('deviceready').querySelector('.received').innerHTML = msg;
},
function(err) {
document.getElementById('deviceready').innerHTML = '<p class="event received">' + err + '</p>';
}
);
},
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);
}
};
app.initialize();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment