// @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);
}
}
}