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.

     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();
     8     // Wire all the simple logic
     9     document.getElementById('no').addEventListener('click', function() {
    10         UI.dialog('dialog1').hide();
    11     });
    13     function getContacts() {
    14         return [].slice.call(document.querySelectorAll('#contacts li'));
    15     };
    17     var contacts = getContacts();
    18     contacts.forEach(function (contact) {
    19         contact.addEventListener('click', function() {
    20             contact.classList.add('selected');
    21         });
    22     });
    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     }
    29     function getContactName(contact) {
    30         return contact.querySelector('p').innerHTML;
    31     }
    33     function displayMessage(message) {
    34         document.querySelector('#dialog1 h1').innerHTML = message;
    35         UI.dialog('dialog1').show();
    36     };
    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     });
    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     });
    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 };

mercurial