michael@0: /** michael@0: * Wait before the DOM has been loaded before initializing the Ubuntu UI layer michael@0: */ michael@0: window.onload = function () { michael@0: var UI = new UbuntuUI(); michael@0: UI.init(); michael@0: michael@0: // Wire all the simple logic michael@0: document.getElementById('no').addEventListener('click', function() { michael@0: UI.dialog('dialog1').hide(); michael@0: }); michael@0: michael@0: function getContacts() { michael@0: return [].slice.call(document.querySelectorAll('#contacts li')); michael@0: }; michael@0: michael@0: var contacts = getContacts(); michael@0: contacts.forEach(function (contact) { michael@0: contact.addEventListener('click', function() { michael@0: contact.classList.add('selected'); michael@0: }); michael@0: }); michael@0: michael@0: function getSelectedContacts() { michael@0: var selectedContactInputs = [].slice.call(document.querySelectorAll('#contacts li label input:checked')); michael@0: return selectedContactInputs.map(function (contactInputElement) { return contactInputElement.parentNode.parentNode; }); michael@0: } michael@0: michael@0: function getContactName(contact) { michael@0: return contact.querySelector('p').innerHTML; michael@0: } michael@0: michael@0: function displayMessage(message) { michael@0: document.querySelector('#dialog1 h1').innerHTML = message; michael@0: UI.dialog('dialog1').show(); michael@0: }; michael@0: michael@0: document.getElementById('call').addEventListener('click', function() { michael@0: var sc = getSelectedContacts(); michael@0: if (! sc || sc.length !== 1) { michael@0: displayMessage('Please select one and only one contact'); michael@0: return; michael@0: } michael@0: displayMessage('Calling: ' + getContactName(sc[0])); michael@0: }); michael@0: michael@0: document.getElementById('text').addEventListener('click', function() { michael@0: var sc = getSelectedContacts(); michael@0: if (! sc || sc.length !== 1) { michael@0: displayMessage('Please select one and only one contact'); michael@0: return; michael@0: } michael@0: displayMessage('Texting: ' + getContactName(sc[0])); michael@0: }); michael@0: michael@0: // Add an event listener that is pending on the initialization michael@0: // of the platform layer API, if it is being used. michael@0: document.addEventListener("deviceready", function() { michael@0: if (console && console.log) michael@0: console.log('Platform layer API ready'); michael@0: }, false); michael@0: }; michael@0: