www/js/app.js

changeset 0
76acfbeeb09c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/www/js/app.js	Mon Apr 27 16:05:06 2015 +0200
     1.3 @@ -0,0 +1,63 @@
     1.4 +/**
     1.5 + * Wait before the DOM has been loaded before initializing the Ubuntu UI layer
     1.6 + */
     1.7 +window.onload = function () {
     1.8 +    var UI = new UbuntuUI();
     1.9 +    UI.init();
    1.10 +
    1.11 +    // Wire all the simple logic
    1.12 +    document.getElementById('no').addEventListener('click', function() {
    1.13 +        UI.dialog('dialog1').hide();
    1.14 +    });
    1.15 +
    1.16 +    function getContacts() {
    1.17 +        return [].slice.call(document.querySelectorAll('#contacts li'));
    1.18 +    };
    1.19 +
    1.20 +    var contacts = getContacts();
    1.21 +    contacts.forEach(function (contact) {
    1.22 +        contact.addEventListener('click', function() {
    1.23 +            contact.classList.add('selected');
    1.24 +        });
    1.25 +    });
    1.26 +
    1.27 +    function getSelectedContacts() {
    1.28 +        var selectedContactInputs = [].slice.call(document.querySelectorAll('#contacts li label input:checked'));
    1.29 +        return selectedContactInputs.map(function (contactInputElement) { return contactInputElement.parentNode.parentNode; });
    1.30 +    }
    1.31 +
    1.32 +    function getContactName(contact) {
    1.33 +        return contact.querySelector('p').innerHTML;
    1.34 +    }
    1.35 +
    1.36 +    function displayMessage(message) {
    1.37 +        document.querySelector('#dialog1 h1').innerHTML = message;
    1.38 +        UI.dialog('dialog1').show();
    1.39 +    };
    1.40 +
    1.41 +    document.getElementById('call').addEventListener('click', function() {
    1.42 +        var sc = getSelectedContacts();
    1.43 +        if (! sc || sc.length !== 1) {
    1.44 +            displayMessage('Please select one and only one contact');
    1.45 +            return;
    1.46 +        }
    1.47 +        displayMessage('Calling: ' + getContactName(sc[0]));
    1.48 +    });
    1.49 +
    1.50 +    document.getElementById('text').addEventListener('click', function() {
    1.51 +        var sc = getSelectedContacts();
    1.52 +        if (! sc || sc.length !== 1) {
    1.53 +            displayMessage('Please select one and only one contact');
    1.54 +            return;
    1.55 +        }
    1.56 +        displayMessage('Texting: ' + getContactName(sc[0]));
    1.57 +    });
    1.58 +
    1.59 +    // Add an event listener that is pending on the initialization
    1.60 +    //  of the platform layer API, if it is being used.
    1.61 +    document.addEventListener("deviceready", function() {
    1.62 +        if (console && console.log)
    1.63 +            console.log('Platform layer API ready');
    1.64 +    }, false);
    1.65 +};
    1.66 +

mercurial