[go: up one dir, main page]

Menu

[r3949]: / applet_control.js  Maximize  Restore  History

Download this file

210 lines (200 with data), 6.3 kB

  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
// @licstart The following is the entire license notice for the JavaScript code in this page.
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
// The following is the entire license notice for the JavaScript code in this page.
//
// Copyright 2015 New Zealand Institute of Language, Brain and Behaviour,
// University of Canterbury
// Written by Robert Fromont - robert.fromont@canterbury.ac.nz
//
// This file is part of LaBB-CAT.
//
// LaBB-CAT is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// LaBB-CAT is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with LaBB-CAT; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// As additional permission under GNU AGPL version 3 section 7, you
// may distribute non-source (e.g., minimized or compacted) forms of
// that code without the copy of the GNU AGPL normally required by
// section 4, provided you include this license notice and a URL
// through which recipients can access the Corresponding Source.
//
// @licend The above is the entire license notice for the JavaScript code in this page.
var lastId;
var editingGrid;
// send messages from the browser to the applet
function praat() // RF20040116
{
if (lastId != null)
{
document.applets[0].cmd_praat_selection(lastId);
}
else
{
document.applets[0].cmd_praat();
}
}
function praat_selection(id) // RF20040126
{
document.applets[0].cmd_praat_selection(id);
}
function praat_selection(from, to) // RF20081121
{
document.applets[0].cmd_praat_selection(from, to);
}
function praat_grid_selection(turn, from, to) // RF20090327
{
editingGrid = document.applets[0].cmd_praat_sound_and_grid(turn, from, to);
return (editingGrid != null);
}
function praat_grid_selection_zoom(turn, from, to, zfrom, zto) // RF20101220
{
editingGrid = document.applets[0].cmd_praat_sound_and_grid_and_zoom(turn, from, to, zfrom, zto);
return (editingGrid != null);
}
function praat_import_last_grid() // RF20091124
{
document.applets[0].cmd_praat_save_grid(editingGrid);
}
function repeat() // RF20031222
{
document.applets[0].cmd_repeat();
}
function stopit()
{
document.applets[0].cmd_stop();
}
function playOne(id)
{
lastId = id;
// unhighlight everything so far highlighted
for (i in aTimeout) if (aTimeout[i] != null) endplay(i);
// play it
if (document.applets[0].cmd_isID(id))
{
reponse = document.applets[0].cmd_playS(id);
}
}
function playFrom(id)
{
lastId = id;
if (!document.applets[0].isActive())
{
alert('Please wait until the applet is active.');
}
else
{
// unhighlight everything so far highlighted
for (i in aTimeout) if (aTimeout[i] != null) endplay(i);
if (document.applets[0].cmd_isID(id))
{
reponse = document.applets[0].cmd_playFrom(id);
}
}
}
function playFromLast()
{
var defaultId = lastId;
if (defaultId == "") defaultId = document.applets[0].cmd_firstS();
// unhighlight everything so far highlighted
for (i in aTimeout) if (aTimeout[i] != null) endplay(i);
playFrom(defaultId);
}
// send messages from the applet to the browser
function startplay(id)
{
// unhighlight everything so far highlighted
for (i in aTimeout) if (aTimeout[i] != null) endplay(i);
highlight(true, id);
}
function endplay(id)
{
highlight(false, id);
}
function stopplay()
{
for (i in aTimeout) if (aTimeout[i] != null) endplay(i);
}
function highlight(bHighlight, id)
{
var theItem = document.getElementById(id);
if (theItem)
{
// whatever it's currently doing, stop it
if (aTimeout[id] != null) window.clearTimeout(aTimeout[id]);
if (bHighlight)
{
aTimeout[id] = window.setTimeout("shade('"+id+"', -6);", 10);
var scrolledBy = window.pageYOffset;
if (scrolledBy == undefined) scrolledBy = document.body.scrollTop;
var windowHeight = window.innerHeight;
if (windowHeight == undefined) windowHeight = document.body.clientHeight;
var theItemTop = getAbsolutePosition(theItem).y
// if the item isn't in view
if (theItemTop + 150 > scrolledBy + windowHeight
|| theItemTop < scrolledBy)
{
// put it in the middle of the window
window.scrollTo(0, theItemTop - windowHeight/2 + 150); // TODO animate a smooth scroll
}
}
else
{
aTimeout[id] = window.setTimeout("shade('"+id+"', 3);", 10);
}
}
}
// RF20030425
function errHandler(message)
{
if (message == "NoPlayerException")
{
alert(message + "\nThe audio file is probably not accesssible.\nHave you inserted the correct CD?\nClick Refresh to retry.");
}
else if (message.match(/http:\/\/[^ ]+/))
{
alert(message);
window.open(message.match(/http:\/\/[^ ]+/)[0]);
}
else
{
alert(message);
}
}
function RealizeCompleteEvent(message)
{
//alert("RealizeCompleteEvent " + message);
}
var aTimeout = new Array();
var aShade = new Array();
var iShadeMin = 192;
function shade(id, fadeInc)
{
var div = document.getElementById(id);
if (aShade[id] == null) aShade[id] = 256;
aShade[id] += fadeInc;
if (aShade[id] >= 256)
{
div.style.background = 'transparent';
aTimeout[id] = null;
}
else
{
var hex = aShade[id].toString(16);
if (hex.length == 1) hex = "0" + hex;
div.style.background = '#' + hex + hex + hex;
if (aShade[id] > iShadeMin)
{
aTimeout[id] = window.setTimeout("shade('"+id+"', "+fadeInc+");", 10);
}
}
}