function audioPlayer(playerLocation)
{
while(playerLocation.childNodes.length != 0)
{
playerLocation.removeChild(playerLocation.childNodes[0]);
}
this.player = null;
if (isExplorer())
{
playerLocation.innerHTML = '';
this.player = playerLocation.childNodes[0];
this.setUrl = function(url)
{
this.player.URL = url;
}
this.play = function()
{
this.player.controls.play();
if (this.state() != 3 && window.app != null)
{
if (this.playTimerID != null)
{
return;
}
this.playTimerID = app.timer.addTimer(new objfn('forcePlay', this), 100);
}
}
this.stop = function()
{
this.player.controls.stop();
}
this.pause = function()
{
this.player.controls.pause();
}
this.state = function()
{
var conversion = new Array(0,0,4,3,5,5,2,2,0,1,0,1)
return conversion[this.player.playState];
}
this.textState = function()
{
var states = new Array('Stopped', 'Contacting', 'Buffering', 'Playing', 'Paused', 'Seeking');
return states[this.state()];
}
this.getPosition = function()
{
return this.player.controls.currentPosition*1000;
}
this.getClipLength = function()
{
try
{
return this.player.currentMedia.duration*1000;
}catch(e)
{
return 0;
}
}
this.setPosition = function(pos)
{
return this.player.controls.currentPosition = pos/1000;
}
}else if (isMozilla())
{
playerLocation.innerHTML = '';
this.player = playerLocation.childNodes[0];
this.setUrl = function(url)
{
playerLocation.innerHTML = '';
this.player = playerLocation.childNodes[0];
/*
this.requestedURL = url;
this.player.SetSource(url);
this.stop();
this.player.SetSource(url);
var parent = this;
var fn = function()
{
parent.player.SetSource(url);
var fn2 = function()
{
parent.player.SetSource(url);
parent.play();
}
// setTimeout(fn2, 100);
}
setTimeout(fn, 100);
*/
// this.checkUrlChanged();
}
this.checkUrlChanged = function()
{
if (this.player.GetSource() == this.oldRealURL)
{
this.player.SetSource(this.requestedURL);
var parent = this;
var fn = function()
{
parent.checkUrlChanged();
}
setTimeout(fn, 200);
}else
{
this.oldRealURL = this.player.GetSource();
this.play();
}
}
this.play = function()
{
this.player.DoPlay();
// if (this.player.GetPlayState() != 3 && window.app != null)
// {
// this.playTimerID = app.timer.addTimer(new objfn('forcePlay', this), 100);
// }
}
this.stop = function()
{
this.player.DoStop();
}
this.pause = function()
{
this.player.DoPause();
}
this.state = function()
{
var result = null;
try
{
result = this.player.GetPlayState();
}catch(e)
{
result = 0;
}
return result;
}
this.textState = function()
{
var states = new Array('Stopped', 'Contacting', 'Buffering', 'Playing', 'Paused', 'Seeking');
return states[this.player.GetPlayState()];
}
this.getPosition = function()
{
var result = null;
try
{
result = this.player.GetPosition();
}catch(e)
{
result = 0;
}
return result;
}
this.getClipLength = function()
{
var result = null;
try
{
result = this.player.GetLength();
}catch(e)
{
result = 0;
}
return result;
}
this.setPosition = function(pos)
{
return this.player.SetPosition(pos);
}
}
this.monitorEvents = function()
{
if (this.oldClipLength != this.getClipLength())
{
this.oldClipLength = this.getClipLength();
if (this.clipLenMon != null)
{
this.clipLenMon.run(this.oldClipLength);
}
}
if (this.oldState != this.state())
{
this.oldState = this.state();
if (this.stateMon != null)
{
this.stateMon.run(this.oldState, this.textState());
}
}
}
this.forcePlay = function()
{
if (this.state() != 3)
{
this.play();
return;
}
if (this.playTimerID == null)
{
return;
}
app.timer.removeTimer(this.playTimerID);
this.playTimerID = null;
}
this.oldClipLength = 0;
this.oldState = -1;
if (window.app != null)
{
this.monEventTimerID = app.timer.addTimer(new objfn('monitorEvents', this), 100);
}
}
function createPlayerCaptionDisplay()
{
var div = document.createElement('div');
divToHorizontalSplitContainer(div);
var infoDisplay = document.createElement('div');
divToContainer(infoDisplay);
infoDisplay.appendChild(document.createTextNode('Caption Info'));
div.addContainer(infoDisplay, 50);
var captionDisplay = document.createElement('div');
divToContainer(captionDisplay);
captionDisplay.className = 'centered';
captionDisplay.appendChild(document.createTextNode('Caption Container'));
div.addContainer(captionDisplay);
var editorCnt = document.createElement('div');
divToContainer(editorCnt);
// editorCnt.style['background'] = '#FFEEFF';
div.addContainer(editorCnt, 25);
editorCnt.style['position'] = 'relative';
var precisionSliderCnt = document.createElement('div');
divToContainer(precisionSliderCnt);
// precisionSliderCnt.style['background'] = '#FFEEFF';
div.addContainer(precisionSliderCnt, 60);
precisionSliderCnt.style['position'] = 'relative';
var slideHandle = document.createElement('div');
slideHandle.style['height'] = '20px';
slideHandle.style['width'] = '20px';
// slideHandle.style['background'] = '#FFFF00';
slideHandle.className = 'player_media_slider_button';
var positionSlider = createHorizontalSlider(100, 0, 20, 400, slideHandle, 20, null);
positionSlider.style['top'] = '40px';
positionSlider.style['left'] = '20px';
positionSlider.style['position'] = 'absolute';
positionSlider.className = 'player_media_slider_bar';
var lineSlider = document.createElement('div');
divToContainer(lineSlider);
// lineSlider.style['background'] = "#AAAAFF";
lineSlider.style['position'] = 'absolute';
lineSlider.style['height'] = '20px';
lineSlider.style['width'] = '20px';
lineSlider.style['top'] = '20px';
lineSlider.style['left'] = '21px';
var zoomDropDown = document.createElement('div');
zoomDropDown.style['position'] = 'absolute';
zoomDropDown.style['height'] = '20px';
zoomDropDown.style['top'] = '0px';
zoomDropDown.style['left'] = '20px';
zoomDropDown.className = 'player_captionInfo';
zoomDropDown.appendChild(document.createTextNode('Zoom: '));
var zoomSelect = document.createElement('select');
zoomSelect.onchange = function()
{
app.cach.setVariable('precisionSliderMillisecondsPerPixel', this.value);
}
zoomSelect.className = 'player_media_dropdown';
var zoomOptions = new Array(10, 20, 30, 40, 50, 60, 70, 80, 90, 100);
var zoomOption;
for(var i = 0; i < zoomOptions.length; i++)
{
zoomOption = document.createElement('option');
zoomOption.value = zoomOptions[i];
zoomOption.appendChild(document.createTextNode(zoomOptions[i].toString() + ' milliseconds/pixel'));
zoomSelect.appendChild(zoomOption);
}
zoomDropDown.appendChild(zoomSelect);
zoomSelect.onchange();
precisionSliderCnt.sliderToSeconds = function(number)
{
var sliderHalf = (this.positionSlider.sliderMax)/2;
var numberOffset = number - sliderHalf;
var currPos = app.getFunction('player', 'getPosition').run();
var finalPos = currPos + (numberOffset*app.cach.get('precisionSliderMillisecondsPerPixel'));
if (finalPos < 0)
{
finalPos = 0;
}
var maxPos = app.getFunction('player', 'getClipLength').run();
if (finalPos > maxPos)
{
finalPos = maxPos;
}
return finalPos;
}
precisionSliderCnt.intToTime = function(number)
{
number = this.sliderToSeconds(number);
if (number < 0) {number = 0;}
number = number / 1000;
var minutes = Math.floor(number/60);
var seconds = number - (minutes * 60);
seconds = Math.round(seconds*100)/100;
if (seconds < 10)
{
seconds = '0' + seconds.toString();
}else
{
seconds = seconds.toString();
}
return minutes.toString() + ':' + seconds;
}
precisionSliderCnt.readPosSlideChange = function(pos)
{
app.getFunction('player', 'setPosition').run(this.sliderToSeconds(pos));
this.resizeChildren();
}
positionSlider.posToTextFn = new objfn('intToTime', precisionSliderCnt);
positionSlider.posMonFn = new objfn('readPosSlideChange', precisionSliderCnt);
precisionSliderCnt.appendChild(zoomDropDown);
precisionSliderCnt.appendChild(lineSlider);
precisionSliderCnt.appendChild(positionSlider);
precisionSliderCnt.lineSlider = lineSlider;
precisionSliderCnt.positionSlider = positionSlider;
precisionSliderCnt.resizeChildren = function()
{
this.positionSlider.sliderMax = (this.currX-40)-this.positionSlider.sliderWidth;
this.positionSlider.setPos((this.positionSlider.sliderMax)/2);
this.positionSlider.setWidth(this.currX-40);
this.lineSlider.setSize((this.currX-40), 20);
}
var capMan = new captionManager(infoDisplay, captionDisplay, precisionSliderCnt, editorCnt);
app.addComponent('captionManager', capMan);
return div;
}
function captionManager(infoDiv, capDiv, precisionSliderCnt, editorCnt)
{
this.infoDiv = infoDiv;
this.capDiv = capDiv;
this.editorCnt = editorCnt;
this.lineSlider = new lineSlideMonitor(precisionSliderCnt.lineSlider, precisionSliderCnt.positionSlider, this);
clearChildNodes(capDiv);
clearChildNodes(infoDiv);
clearChildNodes(editorCnt);
capDiv.className = 'centered';
this.textContainer = document.createElement('span');
this.gurmukhiTextSpan = document.createElement('span');
this.gurmukhiText = document.createTextNode('<>');
this.gurmukhiTextSpan.appendChild(this.gurmukhiText);
this.gurmukhiTextSpan.className = 'player_media_gurmukhi_text';
this.englishTextSpan = document.createElement('span');
this.englishText = document.createTextNode('Ik On-ankar');
this.englishTextSpan.appendChild(this.englishText);
this.englishTextSpan.className = 'player_media_english_text';
this.translationTextSpan = document.createElement('span');
this.translationText = document.createTextNode('One God');
this.translationTextSpan.appendChild(this.translationText);
this.translationTextSpan.className = 'player_media_english_text';
this.editButtonCnt = document.createElement('span');
this.textContainer.appendChild(this.gurmukhiTextSpan);
this.textContainer.appendChild(document.createElement('br'));
this.textContainer.appendChild(this.englishTextSpan);
this.textContainer.appendChild(document.createElement('br'));
this.textContainer.appendChild(this.translationTextSpan);
this.editTextContainer = document.createElement('span');
this.editTextContainer.className = 'player_media_edit_text_container';
this.editTextContainer.style['visibility'] = 'hidden';
this.editTextContainer.style['display'] = 'none';
this.timeInput = document.createElement('input');
this.timeInput.className = 'player_media_input_box player_media_english_text';
this.timeInput.style['width'] = '100px';
makeInputTimeReader(this.timeInput);
this.timeInput.monitorChange = new objfn('monitorEditingTimeInput', this);
this.gurmukhiInput = document.createElement('input');
this.gurmukhiInput.className = 'player_media_input_box player_media_gurmukhi_text';
this.gurmukhiInput.style['width'] = '390px';
this.englishInput = document.createElement('input');
this.englishInput.className = 'player_media_input_box player_media_english_text';
this.englishInput.style['width'] = '390px';
this.translationInput = document.createElement('input');
this.translationInput.className = 'player_media_input_box player_media_english_text';
this.translationInput.style['width'] = '390px';
this.editTextContainer.appendChild(this.timeInput);
this.editTextContainer.appendChild(document.createElement('br'));
this.editTextContainer.appendChild(this.gurmukhiInput);
this.editTextContainer.appendChild(document.createElement('br'));
this.editTextContainer.appendChild(this.englishInput);
this.editTextContainer.appendChild(document.createElement('br'));
this.editTextContainer.appendChild(this.translationInput);
capDiv.appendChild(this.editTextContainer);
capDiv.appendChild(this.textContainer);
capDiv.appendChild(document.createElement('br'));
capDiv.appendChild(this.editButtonCnt);
infoDiv.className = 'player_captionInfo';
this.captions = new Array();
this.editable = false;
this.editMode = false;
this.editing = false;
this.editingLine = -1;
this.optPrevTimeCheck = -1;
this.optNextTimeCheck = -1;
this.previousRenderedCap = -1;
this.addNewLine = function()
{
var line = {};
var match = new RegExp("^([\\x20-\\xFF]*)$");
if (!match.test(this.gurmukhiInput.value))
{
alert("The following line contains invalid characters:\n"+this.gurmukhiInput.value);
return;
}
if (!match.test(this.englishInput.value))
{
alert("The following line contains invalid characters:\n"+this.englishInput.value);
return;
}
if (!match.test(this.translationInput.value))
{
alert("The following line contains invalid characters:\n"+this.translationInput.value);
return;
}
line['time'] = this.timeInput.currVal;
line['gurmukhi'] = this.gurmukhiInput.value;
line['english'] = this.englishInput.value;
line['translation'] = this.translationInput.value;
line['captionid'] = this.currentCaptionID;
this.captions[this.captions.length] = line;
this.newlyAddedLineID = this.fixLinePosition(this.captions.length-1);
clearChildNodes(this.editButtonCnt);
var rsp = new phpRequest(new objfn('finishedAddlingCaption', this), 'addCaption', 'caption_responder', 'app/jsresponder.php');
rsp.run(this.captions[this.newlyAddedLineID]);
}
this.finishedAddlingCaption = function(newID)
{
this.captions[this.newlyAddedLineID]['id'] = newID;
this.finishedSavingCaption();
}
this.monitorEditingTimeInput = function(time)
{
if (!this.editing){return;}
if (this.editingLine == -1) {return;}
this.updateCaptionLine(time, this.gurmukhiInput.value, this.englishInput.value, this.translationInput.value);
this.editingLine = this.fixLinePosition(this.editingLine);
this.optPrevTimeCheck = -1;
this.optNextTimeCheck = -1;
this.previousRenderedCap = this.editingLine;
}
this.didEditorChangeLineCaptions = function()
{
if (!this.editing){return false;}
if (this.editingLine == -1) {return false;}
if (this.timeInput.currVal != this.editorOriginalTime ||
this.gurmukhiInput.value != this.editorOriginalGurmukhi ||
this.englishInput.value != this.editorOriginalEnglish ||
this.translationInput.value != this.editorOriginalTranslation)
{
return true;
}
return false;
}
this.updateCaptionLine = function(time, gurmukhi, english, translation)
{
if (!this.editing) {return;}
this.captions[this.editingLine]['time'] = time;
this.captions[this.editingLine]['gurmukhi'] = gurmukhi;
this.captions[this.editingLine]['english'] = english;
this.captions[this.editingLine]['translation'] = translation;
}
this.fixLinePosition = function(index)
{
if (index != 0)
{
if (this.captions[index]['time'] < this.captions[index-1]['time'])
{
return this.fixLinePositionBack(index);
}
}
if(index != this.captions.length-1)
{
if (this.captions[index]['time'] > this.captions[index+1]['time'])
{
return this.fixLinePositionForward(index);
}
}
return index;
}
this.fixLinePositionForward = function(index)
{
var tmp;
while(index != this.captions.length-1 && this.captions[index]['time'] > this.captions[index+1]['time'])
{
tmp = this.captions[index+1];
this.captions[index+1] = this.captions[index];
this.captions[index] = tmp;
index++;
}
this.lineSlider.clearLines();
return index;
}
this.fixLinePositionBack = function(index)
{
var tmp;
while(index != 0 && this.captions[index]['time'] < this.captions[index-1]['time'])
{
tmp = this.captions[index-1];
this.captions[index-1] = this.captions[index];
this.captions[index] = tmp;
index--;
}
this.lineSlider.clearLines();
return index;
}
this.updateCaptions = function()
{
var currPos = app.getFunction('player', 'getPosition').run()/1000;
this.lineSlider.searchNewLines(currPos);
if (this.editing)
{
return;
}
if (currPos >= this.optPrevTimeCheck && currPos < this.optNextTimeCheck)
{
return;
}
var currCap = this.getCurrentCaption(currPos);
if (currCap == null)
{
this.optPrevTimeCheck = -1;
this.optNextTimeCheck = -1;
this.previousRenderedCap = -1;
this.gurmukhiText.nodeValue = '';
this.englishText.nodeValue = '';
this.translationText.nodeValue = '';
clearChildNodes(this.editButtonCnt);
this.textContainer.style['visibility'] = 'visible';
this.textContainer.style['display'] = 'block';
this.editTextContainer.style['visibility'] = 'hidden';
this.editTextContainer.style['display'] = 'none';
return;
}
if (currCap != this.captions.length-1)
{
this.optNextTimeCheck = this.captions[currCap+1]['time'];
this.optPrevTimeCheck = this.captions[currCap]['time'];
}else
{
this.optNextTimeCheck = -1;
this.optPrevTimeCheck = -1;
}
if (this.previousRenderedCap != currCap)
{
this.previousRenderedCap = currCap;
this.gurmukhiText.nodeValue = this.captions[currCap]['gurmukhi'];
this.englishText.nodeValue = this.captions[currCap]['english'];
this.translationText.nodeValue = this.captions[currCap]['translation'];
this.textContainer.style['visibility'] = 'visible';
this.textContainer.style['display'] = 'block';
this.editTextContainer.style['visibility'] = 'hidden';
this.editTextContainer.style['display'] = 'none';
clearChildNodes(this.editButtonCnt);
if (this.editMode)
{
var editButton = document.createElement('input');
editButton.type = 'button';
editButton.value = 'Edit';
editButton.className = 'player_media_input_button';
editButton.parent = this;
editButton.onclick = function()
{
this.parent.setEditingLine(this.parent.previousRenderedCap);
}
this.editButtonCnt.appendChild(editButton);
}
}
}
this.setEditingLine = function(index)
{
this.previousRenderedCap = index;
this.editing = true;
this.editingLine = index;
this.textContainer.style['visibility'] = 'hidden';
this.textContainer.style['display'] = 'none';
this.editTextContainer.style['visibility'] = 'visible';
this.editTextContainer.style['display'] = 'block';
clearChildNodes(this.editButtonCnt);
this.editorOriginalTime = this.captions[index]['time'];
this.editorOriginalGurmukhi = this.captions[index]['gurmukhi'];
this.editorOriginalEnglish = this.captions[index]['english'];
this.editorOriginalTranslation = this.captions[index]['translation'];
this.timeInput.setValue(this.captions[index]['time']);
this.gurmukhiInput.value = this.captions[index]['gurmukhi'];
this.englishInput.value = this.captions[index]['english'];
this.translationInput.value = this.captions[index]['translation'];
var save = document.createElement('input');
save.type = 'button';
save.className = 'player_media_input_button';
save.value = 'Save';
save.parent = this;
save.onclick = function()
{
var match = new RegExp("^([\\x20-\\xFF]*)$");
if (!match.test(this.parent.gurmukhiInput.value))
{
alert("The following line contains invalid characters:\n"+this.parent.gurmukhiInput.value);
return;
}
if (!match.test(this.parent.englishInput.value))
{
alert("The following line contains invalid characters:\n"+this.parent.englishInput.value);
return;
}
if (!match.test(this.parent.translationInput.value))
{
alert("The following line contains invalid characters:\n"+this.parent.translationInput.value);
return;
}
this.parent.updateCaptionLine(this.parent.timeInput.currVal, this.parent.gurmukhiInput.value, this.parent.englishInput.value, this.parent.translationInput.value);
var rsp = new phpRequest(new objfn('finishedSavingCaption' ,this.parent), 'updateCaption', 'caption_responder', 'app/jsresponder.php');
rsp.run(this.parent.captions[this.parent.editingLine]);
this.parent.fixLinePosition(this.parent.editingLine);
clearChildNodes(this.parent.editButtonCnt);
}
var cancel = document.createElement('input');
cancel.type = 'button';
cancel.className = 'player_media_input_button';
cancel.value = 'Cancel';
cancel.parent = this;
cancel.onclick = function()
{
this.parent.updateCaptionLine(this.parent.editorOriginalTime, this.parent.editorOriginalGurmukhi, this.parent.editorOriginalEnglish, this.parent.editorOriginalTranslation);
this.parent.fixLinePosition(this.parent.editingLine);
this.parent.editing = false;
this.parent.optPrevTimeCheck = -1;
this.parent.optNextTimeCheck = -1;
this.parent.previousRenderedCap = -1;
}
var deleteButton = document.createElement('input');
deleteButton.type = 'button';
deleteButton.className = 'player_media_input_button';
deleteButton.value = 'Delete';
deleteButton.parent = this;
deleteButton.onclick = function()
{
if (!confirm('Are you sure you want to delete this line?'))
{
return;
}
this.parent.captions[this.parent.editingLine]['time'] = this.parent.captions[this.parent.captions.length-1]['time']+1;
this.parent.fixLinePosition(this.parent.editingLine);
var removed = this.parent.captions.pop();
var rsp = new phpRequest(new objfn('finishedSavingCaption', this.parent), 'removeCaption', 'caption_responder', 'app/jsresponder.php');
rsp.run(removed['id']);
clearChildNodes(this.parent.editButtonCnt);
}
this.editButtonCnt.appendChild(save);
this.editButtonCnt.appendChild(deleteButton);
this.editButtonCnt.appendChild(cancel);
}
this.finishedSavingCaption = function()
{
this.editing = false;
this.optPrevTimeCheck = -1;
this.optNextTimeCheck = -1;
this.previousRenderedCap = -1;
}
this.getCurrentCaption = function(currPos)
{
if (this.captions == null || this.captions.length == 0)
{
return null;
}
return this.binarySearchCaptions(this.captions, currPos, 0, this.captions.length-1);
/*
for(var i = 0; i < this.captions.length-1; i++)
{
if (currPos >= this.captions[i].time && currPos < this.captions[i+1].time)
{
break;
}
}
if (i == 0)
{
return null;
}
return i;
*/
}
this.binarySearchCaptions = function(arr, search, start, end)
{
if (search >= arr[end]['time'])
{
return end;
}
if (search < arr[start]['time'])
{
return null;
}
if (start == end)
{
return null;
}
var mid = Math.floor((start+end)/2);
if (search >= arr[mid]['time'] && search < arr[mid+1]['time'])
{
return mid;
}
if (search < arr[mid]['time'])
{
return this.binarySearchCaptions(arr, search, start, mid);
}else
{
return this.binarySearchCaptions(arr, search, mid, end);
}
}
this.loadCaptions = function(id)
{
if (id == null || id == '')
{
this.captions = new Array();
this.editable = false;
this.currentCaptionID = null;
this.captionReader({'editable':'0', 'captions':new Array()});
return;
}
this.currentCaptionID = id;
var rsp = new phpRequest(new objfn('captionReader' ,this), 'getCaptions', 'caption_responder', 'app/jsresponder.php');
rsp.run(id);
}
this.captionReader = function(result)
{
if(result.editable == '1')
{
this.editable = true;
}else
{
this.editable = false;
}
this.captionInfo = result['captionInfo'];
var media = app.cach.get('currentMedia');
clearChildNodes(this.captionCreateSubmitCnt);
if (this.editable && !app.auth.inGroup('caption_admin'))
{
if (this.captionInfo != null && this.captionInfo['submitted'] == 'N')
{
var newCap = document.createElement('input');
newCap.className = 'media_browser_input_normal_button';
newCap.type = 'button';
newCap.value = 'Submit Captions';
newCap.parent = this;
newCap.onclick = function()
{
if (!confirm("Submitting captions alerts the admins that you have finished working on this caption. The admins will look over the captions and either suggest improvements, or make the caption public. If you have any questions you can always e-mail us at sikhshabads@gmail.com.\nContinue?"))
{
return;
}
var rsp = new phpRequest(new objfn('userChange' ,this.parent), 'submitCaption', 'caption_responder', 'app/jsresponder.php');
rsp.run(this.parent.captionInfo['id']);
}
this.captionCreateSubmitCnt.appendChild(newCap);
}
if (this.captionInfo['submitted'] == 'Y')
{
var capStatus = document.createElement('span');
capStatus.appendChild(document.createTextNode('Caption Submitted'));
capStatus.className = 'media_browser_link';
capStatus.onclick = function()
{
alert('Your captions have been submitted. You can continue to make minor changes to your captions, but once your captions goes public, you will no longer be able to modify them. If you want to cancel your request, please e-mail sikhshabads@gmail.com.');
}
this.captionCreateSubmitCnt.appendChild(capStatus);
}
}else
{
if (media['createCap'] == '1' || app.auth.inGroup('caption_admin'))
{
var newCap = document.createElement('input');
newCap.className = 'media_browser_input_normal_button';
newCap.type = 'button';
newCap.value = 'Create Captions';
newCap.parent = this;
newCap.onclick = function()
{
var media = app.cach.get('currentMedia');
if (media == null)
{
return;
}
if (!confirm("Creating a new caption allows you to make your own captions for this media.\nContinue?"))
{
return;
}
var rsp = new phpRequest(new objfn('userChange' ,this.parent), 'createCaption', 'media_responder', 'app/jsresponder.php');
rsp.run(media['id']);
}
this.captionCreateSubmitCnt.appendChild(newCap);
}
}
this.editMode = false;
this.editing = false;
this.optPrevTimeCheck = -1;
this.optNextTimeCheck = -1;
this.previousRenderedCap = -1;
this.lineSlider.clearLines();
this.captions = result['captions'];
for(var i = 0; i < this.captions.length; i++)
{
this.captions[i]['time'] = parseFloat(this.captions[i]['time']);
}
this.redrawEditorContainer();
}
this.redrawEditorContainer = function()
{
clearChildNodes(this.editorCnt);
if (!this.editable)
{
return;
}
this.optPrevTimeCheck = -1;
this.optNextTimeCheck = -1;
this.previousRenderedCap = -1;
var modeSwitch;
modeSwitch = document.createElement('input');
modeSwitch.type = 'button';
modeSwitch.className = 'user_menu_input_button';
modeSwitch.parent = this;
if (!this.editMode)
{
modeSwitch.value = 'Edit Mode';
modeSwitch.onclick = function()
{
this.parent.editMode = true;
this.parent.editing = false;
this.parent.redrawEditorContainer();
}
this.editorCnt.appendChild(modeSwitch);
}else
{
modeSwitch.value = 'View Mode';
modeSwitch.onclick = function()
{
if (this.parent.didEditorChangeLineCaptions())
{
alert('You are currently editing a line. Save or cancel it before switching to view mode.');
return;
}
this.parent.editing = false;
this.parent.editMode = false;
this.parent.redrawEditorContainer();
}
this.editorCnt.appendChild(modeSwitch);
var addLine = document.createElement('input');
addLine.type = 'button';
addLine.className = 'user_menu_input_button';
addLine.parent = this;
addLine.value = 'Add Line';
addLine.onclick = function()
{
this.parent.setAddNewLine();
}
this.editorCnt.appendChild(addLine);
if (app.auth.inGroup('caption_admin') && this.captionInfo != null)
{
var modifyCapPublic = document.createElement('input');
modifyCapPublic.type = 'button';
modifyCapPublic.className = 'user_menu_input_button';
modifyCapPublic.parent = this;
if (this.captionInfo['public'] == 'Y')
{
modifyCapPublic.value = 'Make Private';
modifyCapPublic.onclick = function()
{
if (!confirm('Are you sure you want to make this caption private?'))
{
return;
}
var rsp = new phpRequest(new objfn('userChange' ,this.parent), 'setCaptionPublic', 'caption_responder', 'app/jsresponder.php');
rsp.run(this.parent.captionInfo['id'], 'N');
}
}else
{
modifyCapPublic.value = 'Make Public';
modifyCapPublic.onclick = function()
{
if (!confirm('Are you sure you want to make this caption public?'))
{
return;
}
var rsp = new phpRequest(new objfn('userChange' ,this.parent), 'setCaptionPublic', 'caption_responder', 'app/jsresponder.php');
rsp.run(this.parent.captionInfo['id'], 'Y');
}
}
this.editorCnt.appendChild(modifyCapPublic);
}
}
}
this.setAddNewLine = function()
{
this.editing = true;
this.editingLine = -1;
this.textContainer.style['visibility'] = 'hidden';
this.textContainer.style['display'] = 'none';
this.editTextContainer.style['visibility'] = 'visible';
this.editTextContainer.style['display'] = 'block';
clearChildNodes(this.editButtonCnt);
this.timeInput.setValue(app.getFunction('player', 'getPosition').run()/1000);
this.gurmukhiInput.value = 'gurmuKI';
this.englishInput.value = 'English Pronunciation';
this.translationInput.value = 'Translation';
var cancel = document.createElement('input');
cancel.type = 'button';
cancel.className = 'player_media_input_button';
cancel.value = 'Cancel';
cancel.parent = this;
cancel.onclick = function()
{
this.parent.editing = false;
this.parent.optPrevTimeCheck = -1;
this.parent.optNextTimeCheck = -1;
this.parent.previousRenderedCap = -1;
}
var addLine = document.createElement('input');
addLine.type = 'button';
addLine.className = 'player_media_input_button';
addLine.value = 'Add';
addLine.parent = this;
addLine.onclick = function()
{
this.parent.addNewLine();
}
var copyLine = document.createElement('input');
copyLine.type = 'button';
copyLine.className = 'player_media_input_button';
copyLine.value = 'Copy Existing';
copyLine.parent = this;
copyLine.onclick = function()
{
this.parent.editCopyLine();
}
this.editButtonCnt.appendChild(addLine);
this.editButtonCnt.appendChild(copyLine);
this.editButtonCnt.appendChild(cancel);
}
this.editCopyLine = function()
{
if (this.captions == null || this.captions.length == 0)
{
alert('This is the first line being added. There are no other lines to copy from!');
return;
}
if (this.editingLine == -1)
{
this.editingLine = this.previousRenderedCap;
}
this.copyCurrentLineIntoNewLine();
clearChildNodes(this.editButtonCnt);
var cancel = document.createElement('input');
cancel.type = 'button';
cancel.className = 'player_media_input_button';
cancel.value = 'Cancel Copy';
cancel.parent = this;
cancel.onclick = function()
{
this.parent.setAddNewLine();
}
var addLine = document.createElement('input');
addLine.type = 'button';
addLine.className = 'player_media_input_button';
addLine.value = 'Add';
addLine.parent = this;
addLine.onclick = function()
{
this.parent.addNewLine();
}
var prevLine = document.createElement('input');
prevLine.type = 'button';
prevLine.className = 'player_media_input_button';
prevLine.value = 'Previous Line';
prevLine.parent = this;
prevLine.onclick = function()
{
if (this.parent.editingLine == 0)
{
return;
}
this.nextLine.disabled = false;
this.parent.editingLine = this.parent.editingLine - 1;
if (this.parent.editingLine == 0)
{
this.disabled = true;
}
this.parent.copyCurrentLineIntoNewLine();
}
if (this.editingLine == 0)
{
prevLine.disabled = true;
}
var nextLine = document.createElement('input');
nextLine.type = 'button';
nextLine.className = 'player_media_input_button';
nextLine.value = 'Next Line';
nextLine.parent = this;
nextLine.onclick = function()
{
if (this.parent.editingLine == this.parent.captions.length-1)
{
return;
}
this.prevLine.disabled = false;
this.parent.editingLine = this.parent.editingLine + 1;
if (this.parent.editingLine == this.parent.captions.length-1)
{
this.disabled = true;
}
this.parent.copyCurrentLineIntoNewLine();
}
if (this.editingLine == this.captions.length-1)
{
nextLine.disabled = true;
}
prevLine.nextLine = nextLine;
nextLine.prevLine = prevLine;
this.editButtonCnt.appendChild(prevLine);
this.editButtonCnt.appendChild(nextLine);
this.editButtonCnt.appendChild(document.createElement('br'));
this.editButtonCnt.appendChild(addLine);
this.editButtonCnt.appendChild(cancel);
}
this.copyCurrentLineIntoNewLine = function()
{
this.gurmukhiInput.value = this.captions[this.editingLine]['gurmukhi'];
this.englishInput.value = this.captions[this.editingLine]['english'];
this.translationInput.value = this.captions[this.editingLine]['translation'];
}
this.newMedia = function(info)
{
clearChildNodes(this.infoDiv);
var status = document.createElement('div');
status.className = 'player_media_info';
status.appendChild(document.createTextNode('Name: ' + info['name']));
status.appendChild(document.createElement('br'));
status.appendChild(document.createTextNode('Description: ' + info['description']));
this.infoDiv.appendChild(status);
var captionInfo = document.createElement('div');
captionInfo.className = 'player_media_info';
captionInfo.appendChild(document.createTextNode('Captions: '));
var capDropDown = document.createElement('select');
capDropDown.className = 'player_media_dropdown';
captionInfo.appendChild(capDropDown);
capDropDown.parent = this;
capDropDown.onchange = function()
{
this.parent.loadCaptions(this.value);
}
var captions = info['captions'];
for(var i = 0; i < captions.length; i++)
{
var option = document.createElement('option');
option.value = captions[i]['id'];
if (captions[i]['public'] == '1')
{
option.appendChild(document.createTextNode('by ' + captions[i]['username'] +'['+captions[i]['id'].toString()+']'));
}else if(captions[i]['public'] == '0')
{
option.appendChild(document.createTextNode('-by ' + captions[i]['username'] +'['+ captions[i]['id'].toString() + ']'));
}
capDropDown.appendChild(option);
}
this.captionCreateSubmitCnt = document.createElement('div');
captionInfo.appendChild(this.captionCreateSubmitCnt);
this.infoDiv.appendChild(captionInfo);
capDropDown.onchange();
}
this.userChange = function()
{
var media = app.cach.get('currentMedia');
if (media == null)
{
return;
}
var rsp = new phpRequest(new objfn('setNewMediaInfo' ,this), 'getMediaInfo', 'media_responder', 'app/jsresponder.php');
rsp.run(media['id']);
}
this.setNewMediaInfo = function(info)
{
app.cach.setVariable('currentMedia', info);
}
app.cach.bind('currentMedia', new objfn('newMedia', this));
app.cach.bind('userInfo', new objfn('userChange', this));
app.timer.addTimer(new objfn('updateCaptions', this), 100);
}
function makeInputTimeReader(input)
{
input.setValue = function(seconds)
{
if (seconds < 0)
{
seconds = 0;
}
this.currVal = seconds;
var minutes = Math.floor(seconds/60);
seconds = seconds - (minutes * 60);
seconds = Math.round(seconds*100)/100;
if (seconds < 10)
{
seconds = '0' + seconds.toString();
}else
{
seconds = seconds.toString();
}
this.value = minutes.toString() + ':' + seconds;
}
input.onblur = function()
{
var failure = true;
try
{
var text = this.value;
var colPos = text.indexOf(':');
var seconds;
var minutes;
if (colPos == -1)
{
minutes = 0;
seconds = parseFloat(text);
}else
{
minutes = parseFloat(text.substring(0, colPos));
seconds = parseFloat(text.substring(colPos+1));
}
if (!isNaN(minutes) && !isNaN(seconds))
{
this.setValue(minutes*60 + seconds);
failure = false;
}
}catch(e)
{
}
if (failure)
{
alert("Unable to recognize time format.\nUse minutes:seconds.\nEG. 2:30.5");
this.setValue(this.currVal);
}
if (this.monitorChange != null)
{
this.monitorChange.run(this.currVal);
}
}
}
function flashaudioplayer(playerLocation)
{
while(playerLocation.childNodes.length != 0)
{
playerLocation.removeChild(playerLocation.childNodes[0]);
}
this.flashObjectName = "FlashAudioPlayerIdentifier";
this.soundCompleteCBName = this.flashObjectName + "_complete_cb";
var parent = this;
window[this.soundCompleteCBName] = function()
{
parent.soundCompleteFlashCB();
}
if (isExplorer())
{
playerLocation.innerHTML = '';
}else
{
playerLocation.innerHTML = '