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

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() {
@ -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

@ -26,7 +26,6 @@ TextArea.prototype.init = function() {
});
}
//returns tc in ms if cursor is at a time-code, else returns false
TextArea.prototype.isTc = function() {
var that = this;
@ -91,11 +90,6 @@ TextArea.prototype.getWord = function(pos, val) {
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);
}