www/js/app.js

changeset 0
76acfbeeb09c
equal deleted inserted replaced
-1:000000000000 0:1cff55a8e612
1 /**
2 * Wait before the DOM has been loaded before initializing the Ubuntu UI layer
3 */
4 window.onload = function () {
5 var UI = new UbuntuUI();
6 UI.init();
7
8 // Wire all the simple logic
9 document.getElementById('no').addEventListener('click', function() {
10 UI.dialog('dialog1').hide();
11 });
12
13 function getContacts() {
14 return [].slice.call(document.querySelectorAll('#contacts li'));
15 };
16
17 var contacts = getContacts();
18 contacts.forEach(function (contact) {
19 contact.addEventListener('click', function() {
20 contact.classList.add('selected');
21 });
22 });
23
24 function getSelectedContacts() {
25 var selectedContactInputs = [].slice.call(document.querySelectorAll('#contacts li label input:checked'));
26 return selectedContactInputs.map(function (contactInputElement) { return contactInputElement.parentNode.parentNode; });
27 }
28
29 function getContactName(contact) {
30 return contact.querySelector('p').innerHTML;
31 }
32
33 function displayMessage(message) {
34 document.querySelector('#dialog1 h1').innerHTML = message;
35 UI.dialog('dialog1').show();
36 };
37
38 document.getElementById('call').addEventListener('click', function() {
39 var sc = getSelectedContacts();
40 if (! sc || sc.length !== 1) {
41 displayMessage('Please select one and only one contact');
42 return;
43 }
44 displayMessage('Calling: ' + getContactName(sc[0]));
45 });
46
47 document.getElementById('text').addEventListener('click', function() {
48 var sc = getSelectedContacts();
49 if (! sc || sc.length !== 1) {
50 displayMessage('Please select one and only one contact');
51 return;
52 }
53 displayMessage('Texting: ' + getContactName(sc[0]));
54 });
55
56 // Add an event listener that is pending on the initialization
57 // of the platform layer API, if it is being used.
58 document.addEventListener("deviceready", function() {
59 if (console && console.log)
60 console.log('Platform layer API ready');
61 }, false);
62 };
63

mercurial