www/js/app.js

Mon, 27 Apr 2015 16:05:06 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Mon, 27 Apr 2015 16:05:06 +0200
changeset 0
76acfbeeb09c
permissions
-rw-r--r--

Import initial genesis of local project.

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

mercurial