move code around

This commit is contained in:
j 2016-02-29 17:41:53 +05:30
parent ef23e4ea93
commit 17a74231aa
3 changed files with 174 additions and 174 deletions

200
js/app.js
View file

@ -7,13 +7,6 @@ var globalUser;
var videoPath = undefined;
var videoHash = undefined;
function adjustSize() {
var baseHeight = $(window).height() - 24 - 16;
$('#txt').height(baseHeight);
var baseWidth = $(window).width() - 400 - 64;
$('#txt').width(baseWidth);
}
Ox.load({
UI: {theme: 'oxlight'},
}, function() {
@ -141,101 +134,101 @@ Ox.load({
],
size: "large"
})
.css({'position': 'fixed', 'top': '0px', 'left': '0px', 'right': '0px', 'height': '20px'})
.appendTo(Ox.$body)
.bindEvent({
click: function(data) {
if (data.id == 'load_video') {
saveTxt();
videoPath = undefined;
videoHash = undefined;
textArea.elem.val('');
var path = data.files[0].name;
var extension = Ox.last(path.toLowerCase().split('.'));
if (Ox.contains([
'oga', 'ogg', 'ogv', 'ogx', 'wav', 'webm', 'mp4', 'm4v'
], extension)) {
loadVideo(data.files[0]);
} else {
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();
.css({'position': 'fixed', 'top': '0px', 'left': '0px', 'right': '0px', 'height': '20px'})
.appendTo(Ox.$body)
.bindEvent({
click: function(data) {
if (data.id == 'load_video') {
saveTxt();
videoPath = undefined;
videoHash = undefined;
textArea.elem.val('');
var path = data.files[0].name;
var extension = Ox.last(path.toLowerCase().split('.'));
if (Ox.contains([
'oga', 'ogg', 'ogv', 'ogx', 'wav', 'webm', 'mp4', 'm4v'
], extension)) {
loadVideo(data.files[0]);
} else {
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();
}
});
}
});
textArea = new TextArea("txt");
textArea.elem.val('');
globalUser.init();
@ -249,6 +242,13 @@ Ox.load({
});
function adjustSize() {
var baseHeight = $(window).height() - 24 - 16;
$('#txt').height(baseHeight);
var baseWidth = $(window).width() - 400 - 64;
$('#txt').width(baseWidth);
}
function loadTxt() {
var txt = globalUser.get_txt(videoHash);
//console.log('loadTxt', videoHash, txt.length);

View file

@ -22,11 +22,10 @@ TextArea.prototype.init = function() {
var tc = that.isTc();
if (tc) {
Video.set(tc);
}
}
});
}
//returns tc in ms if cursor is at a time-code, else returns false
TextArea.prototype.isTc = function() {
var that = this;
@ -75,7 +74,7 @@ TextArea.prototype.getWord = function(pos, val) {
break;
}
i--;
c = val.substring(i,i+1);
c = val.substring(i, i+1);
}
var firstLetter = i+1;
var d;
@ -84,18 +83,13 @@ TextArea.prototype.getWord = function(pos, val) {
break;
}
j++;
d = val.substring(j,j+1);
d = val.substring(j, j+1);
}
var lastLetter = j;
var word = val.substring(firstLetter, lastLetter);
return word;
}
function cleanNewlines(str) {
var s = str.replace(/\r\n|\r|\n/g, '\n');
return s;
}
//takes an srt as param, loads into txtarea
TextArea.prototype.fromSrt = function(txt) {
var that = this;
@ -131,45 +125,6 @@ TextArea.prototype.fromSrt = function(txt) {
}
}
function formatEnc(data) {
var r = '', n = 1;
data.forEach(function(item) {
r += n + ' ' + formatFrames(item['in']) + ' ' + formatFrames(item.out) + ' ' + item.text;
r += '\n\n';
n++;
});
return r;
}
function spansToSrt(arr, fmt, start_no) {
if (typeof start_no == 'undefined') {
start_no = 1;
}
var srt = [];
arr.forEach(function(s) {
if (s.text.trim() == '') {
} else {
var text = s.text.trim();
linebreaksRegex = new RegExp('\n+', "g")
text = text.replace(linebreaksRegex, "\n");
if (!s.tcOutMs) {
s.tcOutMs = Video.player.duration;
}
srt.push({
'in': s.tcInMs,
out: s.tcOutMs,
text: text
});
}
});
if (fmt == 'srt') {
return Ox.formatSRT(srt);
} else if (fmt == 'enc') {
return formatEnc(srt);
}
return srt;
}
//returns textarea formatted to .srt
TextArea.prototype.toSrt = function(fmt) {
if (!fmt) var fmt = 'srt';
@ -317,29 +272,3 @@ User.prototype.get_txt = function(filename) {
var that = this;
return localStorage['txt_' + filename];
}
function loadCuts(url, id) {
function pandora_api(action, data, callback) {
$.ajax({
type: "POST",
url: url,
data: {action: action, data: JSON.stringify(data)},
success: callback,
dataType: 'json'
});
}
pandora_api('get', {id: id, keys: ['cuts']}, function(result) {
var txt = '';
result.data.cuts.forEach(function(cut) {
textArea.insertTc(Ox.formatDuration(cut));
});
});
}
function loadSrt(file) {
var reader = new FileReader();
reader.onload = function(data) {
textArea.fromSrt(data.target.result);
};
reader.readAsText(file);
}

View file

@ -25,3 +25,74 @@ function getFileNameSansExt(filename) {
}
return filenameSansExt;
}
function cleanNewlines(str) {
var s = str.replace(/\r\n|\r|\n/g, '\n');
return s;
}
function formatEnc(data) {
var r = '', n = 1;
data.forEach(function(item) {
r += n + ' ' + formatFrames(item['in']) + ' ' + formatFrames(item.out) + ' ' + item.text;
r += '\n\n';
n++;
});
return r;
}
function spansToSrt(arr, fmt, start_no) {
if (typeof start_no == 'undefined') {
start_no = 1;
}
var srt = [];
arr.forEach(function(s) {
if (s.text.trim() == '') {
} else {
var text = s.text.trim();
linebreaksRegex = new RegExp('\n+', "g")
text = text.replace(linebreaksRegex, "\n");
if (!s.tcOutMs) {
s.tcOutMs = Video.player.duration;
}
srt.push({
'in': s.tcInMs,
out: s.tcOutMs,
text: text
});
}
});
if (fmt == 'srt') {
return Ox.formatSRT(srt);
} else if (fmt == 'enc') {
return formatEnc(srt);
}
return srt;
}
function loadCuts(url, id) {
function pandora_api(action, data, callback) {
$.ajax({
type: "POST",
url: url,
data: {action: action, data: JSON.stringify(data)},
success: callback,
dataType: 'json'
});
}
pandora_api('get', {id: id, keys: ['cuts']}, function(result) {
var txt = '';
result.data.cuts.forEach(function(cut) {
textArea.insertTc(Ox.formatDuration(cut));
});
});
}
function loadSrt(file) {
var reader = new FileReader();
reader.onload = function(data) {
textArea.fromSrt(data.target.result);
};
reader.readAsText(file);
}