-
Notifications
You must be signed in to change notification settings - Fork 0
/
UI.js
230 lines (202 loc) · 5.39 KB
/
UI.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*
// Variables
var create_email = false;
var final_transcript = '';
var recognizing = false;
var ignore_onend;
var start_timestamp;
//New functions
//var share_media = false;
//var print = false;
var current_style;
function MSS_alert(text){
document.getElementById("alert").innerHTML=text;
$('#alert').slideDown(1);
}
function showButtons(style) {
if (style == current_style) {
return;
}
//Initial display style
current_style = style;
copy_button.style.display = style;
email_button.style.display = style;
share_button.style.display = style;
print_button.style.display = style;
//Initial display context
copy_info.style.display = 'none';
email_info.style.display = 'none';
share_info.style.display = 'none';
print_button.style.display = style;
}
function copyButton() {
if (recognizing) {
//Stop recognizing and call another function
recognizing = false;
recognition.stop();
}
copy_button.style.display = 'none';
copy_info.style.display = 'inline-block';
showInfo('');
}
function emailButton() {
if (recognizing) {
create_email = true;
recognizing = false;
recognition.stop();
} else {
createEmail();
}
email_button.style.display = 'none';
email_info.style.display = 'inline-block';
showInfo('');
}
function createEmail() {
var n = final_transcript.indexOf('\n');
if (n < 0 || n >= 80) {
n = 40 + final_transcript.substring(40).indexOf(' ');
}
var subject = encodeURI(final_transcript.substring(0, n));
var body = encodeURI(final_transcript.substring(n + 1));
window.location.href = 'mailto:?subject=' + subject + '&body=' + body;
}
/* Share to other social media
function shareButton() {
if(recognizing) {
share_media = true; //Change the value of share_media
regognizing = false;
recognition.stop();
} else {
share2Media(); //Call share function
}
//Set up display attributes
share_button.style.display = 'none';
share_info.style.display = 'inline-block';
showInfo('');
}
/*
/*Share to media function
function share2Media() {
var n = final_transcript.indexOf('\n');
if( n<0 || n>=80 ) {
n = 40 + final_transcript.substring(40).indexOf(' ');
}
//Get the link of final_transcript -- the link to copy and paste
var uri = encodeURI(final_transcript.substring(0,n));
//Copy and paste the uri to a link that can be copied by the user
//May need to debug
window.location.href = 'http://' + uri;
var link = location.href;
//Display
}
function printButton() {
if (recognizing) {
print = true;
recognizing = false;
recognition.stop();
} else {
printAsPdf();
}
print_button.style.display = 'none';
print_info.style.display = 'inline-block';
showInfo('');
}
function printAsPdf () {
windows.print();
}
function startButton(event) {
if (recognizing) {
recognition.stop();
return;
}
final_transcript = '';
recognition.lang = select_dialect.value;
recognition.start();
ignore_onend = false;
final_span.innerHTML = '';
interim_span.innerHTML = '';
start_img.src = '/intl/en/chrome/assets/common/images/content/mic-slash.gif';
showInfo('info_allow');
showButtons('none');
start_timestamp = event.timeStamp;
}
function showInfo(s) {
if (s) {
for (var child = info.firstChild; child; child = child.nextSibling) {
if (child.style) {
child.style.display = child.id == s ? 'inline' : 'none';
}
}
info.style.visibility = 'visible';
} else {
info.style.visibility = 'hidden';
}
}
*/
/* init variable and action*/
var wordList = [];
var isRecording = false;
$(document).ready(function(){
document.getElementById('btn').onclick=MSS_btn_toggle;
document.getElementById('all').onclick=MSS_all;
document.getElementById('alert').onclick=MSS_dismiss_alert;
});
function MSS_dismiss_alert(){
var e = document.getElementById('alert');
if(!e.hidden){
$('#alert').slideUp(1);
}
}
function MSS_all(){
var text = "Your Word List is : \n";
for(var temp in wordList){
text+=wordList[temp].title + "\n";
}
alert(text) ;
}
function MSS_btn_toggle(){
var btn = document.getElementById('btn');
if(isRecording){
btn.innerHTML="Start";
btn.setAttribute("class","btn btn-success btn-lg");
isRecording = false;
document.getElementById('icon-record').hidden = true;
recognition.stop();
MSS_all();
}else{
btn.innerHTML="Stop";
btn.setAttribute("class","btn btn-danger btn-lg");
isRecording = true;
document.getElementById('icon-record').hidden = false;
recognition.start();
}
}
function MSS_add(data){
if(data==null)
return;
wordList.push(data);
$("#fs").fadeOut("fast",function(){
document.getElementById('slide-title').innerHTML=capitalizeEachWord(data.title);
document.getElementById('slide-punc').innerHTML=data.punc;
document.getElementById('slide-expen').innerHTML=data.expen;
document.getElementById("slide-link").setAttribute('href',data.link_url);
});
//do data change
//display new slide
$("#fs").fadeIn("fast");
if(wordList.length%9==0){
document.getElementById('wordList').innerHTML="";
}
var li = document.createElement("li");
li.setAttribute('class','list-group-item');
li.innerHTML = data.title;
document.getElementById('wordList').appendChild(li);
}
function capitalizeEachWord(str) {
return str.replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
function MSS_disp_list(){
//MSS_alert(wordList);
}