This commit is contained in:
j 2016-02-29 14:56:38 +05:30
parent ae682c431d
commit 0742c28cfa

378
js/app.js
View file

@ -17,71 +17,71 @@ function adjustSize() {
Ox.load({ Ox.load({
UI: {theme: 'oxlight'}, UI: {theme: 'oxlight'},
}, function() { }, function() {
Ox.$body.show(); Ox.$body.show();
globalUser = new User(); globalUser = new User();
adjustSize(); adjustSize();
$(document).keydown(function(e) { $(document).keydown(function(e) {
if (!Video) if (!Video)
return; return;
//Esc //Esc
if (e.keyCode == 27) { if (e.keyCode == 27) {
Video.togglePause(); Video.togglePause();
if (!textArea.hasFocus) { if (!textArea.hasFocus) {
textArea.elem.focus(); textArea.elem.focus();
} }
e.preventDefault(); e.preventDefault();
} }
//The weird `~ key, currently in as a silly hack because Ranjana's Esc key does not work. //The weird `~ key, currently in as a silly hack because Ranjana's Esc key does not work.
if (e.keyCode == 192) { if (e.keyCode == 192) {
Video.togglePause(); Video.togglePause();
e.preventDefault(); e.preventDefault();
} }
//Ins or TAB //Ins or TAB
if (e.keyCode == 45 || e.keyCode == 9) { if (e.keyCode == 45 || e.keyCode == 9) {
if (!textArea.isTc()) { if (!textArea.isTc()) {
textArea.insertTc(); textArea.insertTc();
return false; return false;
} else { } else {
return false; return false;
} }
} }
//Ctrl - Seek Back //Ctrl - Seek Back
if (e.keyCode == 17) { if (e.keyCode == 17) {
var seekTime = parseInt(parseFloat($('#seekTime').val()) * 1000); var seekTime = parseInt(parseFloat($('#seekTime').val()) * 1000);
var currTime = Video.get(); var currTime = Video.get();
var newTime = currTime - seekTime; var newTime = currTime - seekTime;
Video.set(newTime); Video.set(newTime);
} }
//Alt - Seek Fwd. //Alt - Seek Fwd.
if (e.keyCode == 18) { if (e.keyCode == 18) {
var seekTime = parseInt(parseFloat($('#seekTime').val()) * 1000); var seekTime = parseInt(parseFloat($('#seekTime').val()) * 1000);
var currTime = Video.get(); var currTime = Video.get();
var newTime = currTime + seekTime; var newTime = currTime + seekTime;
Video.set(newTime); Video.set(newTime);
} }
//Space - togglePause if no focus on TA //Space - togglePause if no focus on TA
if (e.keyCode == 32 && textArea.hasFocus == false) { if (e.keyCode == 32 && textArea.hasFocus == false) {
Video.togglePause(); Video.togglePause();
} }
//PageUp - volume Up: //PageUp - volume Up:
if (e.keyCode == 33) { if (e.keyCode == 33) {
Video.volUp(); Video.volUp();
return false; return false;
} }
if (e.keyCode == 34) { if (e.keyCode == 34) {
Video.volDown(); Video.volDown();
return false; return false;
} }
}); });
$(window).bind('resize', adjustSize); $(window).bind('resize', adjustSize);
var mainMenu = new Ox.MainMenu({ var mainMenu = new Ox.MainMenu({
extras: [], extras: [],
menus: [ menus: [
{ {
id: "speedtrans", id: "speedtrans",
title: "SpeedTrans", title: "SpeedTrans",
@ -140,125 +140,125 @@ Ox.load({
} }
], ],
size: "large" size: "large"
}) })
.css({'position': 'fixed', 'top': '0px', 'left': '0px', 'right': '0px', 'height': '20px'}) .css({'position': 'fixed', 'top': '0px', 'left': '0px', 'right': '0px', 'height': '20px'})
.appendTo(Ox.$body) .appendTo(Ox.$body)
.bindEvent({ .bindEvent({
click: function(data) { click: function(data) {
if (data.id == 'load_video') { if (data.id == 'load_video') {
saveTxt(); saveTxt();
videoPath = undefined; videoPath = undefined;
videoHash = undefined; videoHash = undefined;
textArea.elem.val(''); textArea.elem.val('');
var path = data.files[0].name; var path = data.files[0].name;
if ($.inArray(getFileNameExt(path.toLowerCase()), [ if ($.inArray(getFileNameExt(path.toLowerCase()), [
'oga', 'ogg', 'ogv', 'ogx', 'wav', 'webm', 'mp4', 'm4v' 'oga', 'ogg', 'ogv', 'ogx', 'wav', 'webm', 'mp4', 'm4v'
]) != -1) { ]) != -1) {
loadVideo(data.files[0]); loadVideo(data.files[0]);
} else { } else {
alert('You can only open videos in formats supported by the browser.'); alert('You can only open videos in formats supported by the browser.');
}
} else if(data.id == 'about') {
var html = Ox.tmpl("dialog_about", {});
stDialog("About", html);
} else if(data.id == 'preferences') {
var prefs = globalUser.get_prefs(["fontSize", "theme", "autosave"]);
var html = Ox.tmpl("dialog_preferences", {});
stDialog("Preferences", html);
$('.pref_select').each(function() {
var that = this;
var pref = $(this).attr("data-pref");
var prefVal = prefs[pref];
$(this).children('option').each(function() {
if ($(this).val() == prefVal) {
$(this).attr("selected", "selected");
}
});
});
$('.pref_select').change(function() {
var key = $(this).attr("data-pref");
var val = $(this).val();
globalUser.set_pref(key, val);
});
/*
$('#pref_fontSize > option').each(function() {
if ($(this).val() == prefs.fontSize) {
$(this).attr("selected", "selected");
}
});
$('#pref_theme > option').each(function() {
if ($(this).val() == prefs.theme) {
$(this).attr("selected", "selected");
}
});
*/
} else if(data.id == 'shortcuts') {
var html = Ox.tmpl("dialog_shortcuts", {});
stDialog("Keyboard Shortcuts", html);
} else if(data.id == 'save_srt') {
var content = textArea.toSrt();
saveContent(content, 'text/plain', getFileNameSansExt(videoPath) + '.srt');
} else if(data.id == 'load_srt') {
loadSrt(data.files[0]);
} else if(data.id == 'export_encore') {
var content = textArea.toSrt("enc");
saveContent(content, 'text/plain', getFileNameSansExt(videoPath) + '.enc.txt');
} else if(data.id == 'export_html') {
var content = textArea.toHTML();
saveContent(content, 'text/html', getFileNameSansExt(videoPath) + '.html');
} else if(data.id == 'load_cuts') {
var html = Ox.tmpl("dialog_load_cuts");
var loadDialog = Ox.Dialog({
buttons: [
Ox.Button({
title: "Cancel"
}).bindEvent({
click: function() {
loadDialog.close()
}
}),
Ox.Button({
title: "Load Cuts"
}).bindEvent({
click: function() {
var url = loadDialog.find('input')[0].value.trim();
var match = url.match(/(.*)\/([A-Z]+)$/);
if (match) {
loadCuts(match[1] + '/api/', match[2]);
}
loadDialog.close();
}
}),
],
content: Ox.Element().append(html)
}).open();
}
} }
} else if(data.id == 'about') { });
var html = Ox.tmpl("dialog_about", {}); textArea = new TextArea("txt");
stDialog("About", html); textArea.elem.val('');
} else if(data.id == 'preferences') { globalUser.init();
var prefs = globalUser.get_prefs(["fontSize", "theme", "autosave"]);
var html = Ox.tmpl("dialog_preferences", {});
stDialog("Preferences", html);
$('.pref_select').each(function() {
var that = this;
var pref = $(this).attr("data-pref");
var prefVal = prefs[pref];
$(this).children('option').each(function() {
if ($(this).val() == prefVal) {
$(this).attr("selected", "selected");
}
});
});
$('.pref_select').change(function() {
var key = $(this).attr("data-pref");
var val = $(this).val();
globalUser.set_pref(key, val);
});
/*
$('#pref_fontSize > option').each(function() {
if ($(this).val() == prefs.fontSize) {
$(this).attr("selected", "selected");
}
});
$('#pref_theme > option').each(function() {
if ($(this).val() == prefs.theme) {
$(this).attr("selected", "selected");
}
});
*/
} else if(data.id == 'shortcuts') {
var html = Ox.tmpl("dialog_shortcuts", {});
stDialog("Keyboard Shortcuts", html);
} else if(data.id == 'save_srt') {
var content = textArea.toSrt();
saveContent(content, 'text/plain', getFileNameSansExt(videoPath) + '.srt');
} else if(data.id == 'load_srt') {
loadSrt(data.files[0]);
} else if(data.id == 'export_encore') {
var content = textArea.toSrt("enc");
saveContent(content, 'text/plain', getFileNameSansExt(videoPath) + '.enc.txt');
} else if(data.id == 'export_html') {
var content = textArea.toHTML();
saveContent(content, 'text/html', getFileNameSansExt(videoPath) + '.html');
} else if(data.id == 'load_cuts') {
var html = Ox.tmpl("dialog_load_cuts");
var loadDialog = Ox.Dialog({
buttons: [
Ox.Button({
title: "Cancel"
}).bindEvent({
click: function() {
loadDialog.close()
}
}),
Ox.Button({
title: "Load Cuts"
}).bindEvent({
click: function() {
var url = loadDialog.find('input')[0].value.trim();
var match = url.match(/(.*)\/([A-Z]+)$/);
if (match) {
loadCuts(match[1] + '/api/', match[2]);
}
loadDialog.close();
}
}),
],
content: Ox.Element().append(html)
}).open();
}
}
});
textArea = new TextArea("txt");
textArea.elem.val('');
globalUser.init();
//autosave every 1 minute. //autosave every 1 minute.
window.autosaveInterval = setInterval(function() { window.autosaveInterval = setInterval(function() {
if (!Ox.isUndefined(videoHash)) { if (!Ox.isUndefined(videoHash)) {
saveTxt(); saveTxt();
} }
}, 60000); }, 60000);
}); });
function loadTxt() { function loadTxt() {
var txt = globalUser.get_txt(videoHash); var txt = globalUser.get_txt(videoHash);
//console.log('loadTxt', videoHash, txt.length); //console.log('loadTxt', videoHash, txt.length);
textArea.elem.val(txt); textArea.elem.val(txt);
} }
function saveTxt() { function saveTxt() {
var content = textArea.toSrt(); var content = textArea.toSrt();
var txt = textArea.elem.val(); var txt = textArea.elem.val();
//console.log('saveTxt', videoHash, txt.length); //console.log('saveTxt', videoHash, txt.length);
globalUser.set_txt(videoHash, txt); globalUser.set_txt(videoHash, txt);
} }
function saveContent(content, type, path) { function saveContent(content, type, path) {
@ -295,27 +295,27 @@ function stDialog(titleTxt, text) {
} }
function loadVideo(videoFile) { function loadVideo(videoFile) {
Ox.oshash(videoFile, function(hash) { Ox.oshash(videoFile, function(hash) {
videoHash = hash; videoHash = hash;
var storageKey = 'txt_' + videoHash; var storageKey = 'txt_' + videoHash;
if (storageKey in localStorage) { if (storageKey in localStorage) {
loadTxt(); loadTxt();
} }
}); });
var videoUrl = URL.createObjectURL(videoFile); var videoUrl = URL.createObjectURL(videoFile);
videoPath = videoFile.name; videoPath = videoFile.name;
$('#video').attr("src", videoUrl); $('#video').attr("src", videoUrl);
$('#filepath').text(videoFile.path); $('#filepath').text(videoFile.path);
document.getElementById("video").load(); document.getElementById("video").load();
$('#video').one("loadedmetadata", function() { $('#video').one("loadedmetadata", function() {
Video = new VideoPlayer(); Video = new VideoPlayer();
Video.init("video"); Video.init("video");
Video.setDuration(Video.player.duration); Video.setDuration(Video.player.duration);
$('#insertTc').click(textArea.insertTc); $('#insertTc').click(textArea.insertTc);
videoListener = setInterval(Video.listener, 250); videoListener = setInterval(Video.listener, 250);
}); });
}; };
$(window).unload(function() { $(window).unload(function() {
saveTxt(); saveTxt();
}); });