7e6c8b694a9acbd3b63fca402a78857eee2f5ac8
[profile/ivi/saythis.git] / js / main.js
1 /*
2  * Copyright (c) 2012, Intel Corporation.
3  *
4  * This program is licensed under the terms and conditions of the 
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9
10 App = {};
11
12 (function () {
13     function init() {
14         /* initialization */
15         //license_init('license', "main_page");
16     }
17
18     function onSpeakResults(results) {
19         console.log(results);
20         $('#speakButton').removeClass('pressed');
21     }
22
23     function checkAPI() {
24         var result = wsAPI.isReady();
25         if (!result) {
26             console.log('Cannot connect to websocket API daemon');
27             wsAPI.connect();
28         }
29         return result;
30     }
31
32     $(document).ready(function()
33     {
34                 init();
35
36         $('#speakButton').click(function() {
37             if (checkAPI()) {
38                 var text = $('#inputArea').val();
39                 console.log(text);
40                 if (text && !$('#speakButton').hasClass('pressed')) {
41                     wsAPI.speak(text, onSpeakResults);
42                     $('#speakButton').addClass('pressed');
43                 }
44             }
45             console.log('Speak button clicked');
46         });
47
48         $('#inputArea').keyup(function(event) {
49                 if (event.keyCode === 13) {
50                         $('#speakButton').click();
51                 }
52         });
53     });
54 })()