From 4336ddc8bfb0ed536ec0b4cd193e5c2ff1c41965 Mon Sep 17 00:00:00 2001 From: Sanjay B Date: Tue, 5 Mar 2013 17:20:51 +0530 Subject: [PATCH] basic load SRT from paste --- js/pandora-ui.js | 1 - js/speedtrans.js | 4 +++- js/ui/mainMenu.js | 6 +++-- js/ui/openRemoteDialog.js | 39 +++++++++++++++++++++++++++---- js/ui/openSRTDialog.js | 27 ++++++++++++++++++++++ js/ui/textArea.js | 48 ++++++++++++++++++++++++++++++++++----- js/ui/videoPlayer.js | 7 +++--- 7 files changed, 114 insertions(+), 18 deletions(-) create mode 100644 js/ui/openSRTDialog.js diff --git a/js/pandora-ui.js b/js/pandora-ui.js index 8b7495b..fe9e40e 100644 --- a/js/pandora-ui.js +++ b/js/pandora-ui.js @@ -120,7 +120,6 @@ pandora.ui.videoPanel = function() { } -//FIXME: should be ui.videoPlayer pandora.ui.videoPlayer = function(options) { var url = options.url; var timeline = options.timeline || "foo.png"; //FIXME diff --git a/js/speedtrans.js b/js/speedtrans.js index 5e2a81c..fe24acd 100644 --- a/js/speedtrans.js +++ b/js/speedtrans.js @@ -37,7 +37,7 @@ }); } var prefix = "js/"; - var files = ['appPanel', 'mainMenu', 'mainPanel', 'videoPanel', 'videoPlayer', 'openRemoteDialog', 'helpPanel', 'textPanel', 'textArea', 'textToolBar']; + var files = ['appPanel', 'mainMenu', 'mainPanel', 'videoPanel', 'videoPlayer', 'openRemoteDialog', 'openSRTDialog', 'helpPanel', 'textPanel', 'textArea', 'textToolBar']; var prefix = "js/ui/"; var filesToLoad = Ox.map(files, function(v) { return prefix + v + ".js"; @@ -53,6 +53,8 @@ function initSpeedtrans(data) { pandora.$ui.appPanel = pandora.ui.appPanel().appendTo(pandora.$ui.body); + pandora.$ui.openRemoteDialog = pandora.ui.openRemoteDialog(); + pandora.$ui.openSRTDialog = pandora.ui.openSRTDialog(); pandora.resizeWindow(); } diff --git a/js/ui/mainMenu.js b/js/ui/mainMenu.js index 7e3fc7b..68787d9 100644 --- a/js/ui/mainMenu.js +++ b/js/ui/mainMenu.js @@ -21,6 +21,7 @@ pandora.ui.mainMenu = function() { } }, { id: 'openRemoteFileMenu', title: 'Open online pan.do/ra file'}, + { id: 'openSRT', title: 'Load SRT file'}, { id: 'saveFileMenu', title: 'Save File', keyboard: 'shift control s'} ] } @@ -50,8 +51,9 @@ pandora.ui.mainMenu = function() { //console.log(data.files[0]); } else if (data.id == 'openRemoteFileMenu') { - pandora.$ui.openRemoteDialog = pandora.ui.openRemoteDialog().open(); - + pandora.$ui.openRemoteDialog.open(); + } else if (data.id == 'openSRT') { + pandora.$ui.openSRTDialog.open(); } else if (data.id == 'TestMenu1') { alert("clicked TestMenu1"); } diff --git a/js/ui/openRemoteDialog.js b/js/ui/openRemoteDialog.js index 0cb8b77..1b9b904 100644 --- a/js/ui/openRemoteDialog.js +++ b/js/ui/openRemoteDialog.js @@ -16,13 +16,42 @@ pandora.ui.openRemoteDialog = function() { // }); //FIXME: convert to SelectInput - var $input1 = Ox.Input({ - 'label': 'Pan.do/ra instance URL', - 'id': 'pandoraInstance', - 'labelWidth': 250, - 'width': 600 + + var instances = [ + { + 'id': 'http://pad.ma', + 'title': 'Pad.ma' + }, + { + 'id': 'http://0xdb.org', + 'title': 'Oxdb' + }, + { + 'id': 'http://indiancine.ma', + 'title': 'IndianCine.ma' + }, + { + 'id': 'other', + 'title': 'Other...' + } + ] + + var $input1 = Ox.SelectInput({ + 'items': instances, + 'label': 'Site', + 'placeholder': 'http://example.com', + 'max': 1, + 'min': 1, + 'value': instances[0]['id'], }).css({'margin': '4px'}); +// var $input1 = Ox.Input({ +// 'label': 'Pan.do/ra instance URL', +// 'id': 'pandoraInstance', +// 'labelWidth': 250, +// 'width': 600 +// }).css({'margin': '4px'}); + var $input2 = Ox.Input({ 'label': 'Pan.do/ra Video ID', 'id': 'pandoraID', diff --git a/js/ui/openSRTDialog.js b/js/ui/openSRTDialog.js new file mode 100644 index 0000000..e6f77f9 --- /dev/null +++ b/js/ui/openSRTDialog.js @@ -0,0 +1,27 @@ +pandora.ui.openSRTDialog = function() { + var $textInput = Ox.Input({ + 'type': 'textarea', + 'label': 'Paste SRT', + 'id': 'srtText', + 'labelWidth': 150, + 'width': 500, + 'height': 400 + }); + var $content = Ox.Element().append($textInput); + var that = Ox.Dialog({ + 'content': $content, + 'closeButton': true, + 'buttons': [ + Ox.Button({ + 'group': true, + 'id': 'loadSRTButton', + 'title': 'Load SRT' + }).bindEvent("click", function() { + var txt = $textInput.value(); + pandora.$ui.textArea.speedtrans.fromSrt(txt); + that.close(); + }) + ] + }); + return that; +}; diff --git a/js/ui/textArea.js b/js/ui/textArea.js index 86ce905..630f970 100644 --- a/js/ui/textArea.js +++ b/js/ui/textArea.js @@ -9,6 +9,7 @@ pandora.ui.textArea = function() { that.speedtrans = { spans: [], + storage: '', insertTc: function() { var eDom = that.find("textarea").get(0); //FIXME var scrollTop = eDom.scrollTop; @@ -102,13 +103,47 @@ pandora.ui.textArea = function() { // console.log(srt); return srt; }, - - save: function() { - + fromSrt: function(txt) { + var annots = Ox.parseSRT(txt); + var i = 0; + var spans = Ox.map(annots, function(v) { + var obj = { + 'tcInMs': parseInt(v['in'] * 1000), + 'tcOutMs': parseInt(v.out * 1000), + 'text': v.text, + 'index': i + } + i++; + return obj; + }); + console.log(spans); + var out = ''; + for (span in spans) { + if (spans.hasOwnProperty(span)) { + var sp = spans[span]; + out += ms2npt(sp.tcInMs) + "\n"; + out += sp.text; + out += "\n"; + //If the outpoint of current span is equal to inpoint of next span, dont print out timecode, and just add the extra \n to go to next span. + if (span < spans.length - 1) { + var p = parseInt(span) + 1; + if (spans[p].tcInMs != sp.tcOutMs) { + out += ms2npt(sp.tcOutMs) + "\n\n"; + } else { + out += "\n"; + } + } + } + } + console.log(out); + that.value(out); + }, + save: function() { console.log(that.value()); - var filename = pandora.$ui.videoPlayer.options("video"); - console.log(filename); - pandora.storage(filename, {'text': that.value()}); + //var videoName = pandora.$ui.videoPlayer.videoName; + //console.log(videoName); + console.log(that.storage); + pandora.storage(that.storage, {'text': that.value()}); }, load: function(options) { console.log(options); @@ -121,6 +156,7 @@ pandora.ui.textArea = function() { // var name = options.name; // } var val = pandora.storage(options.name) || {'text': ''}; + that.storage = options.name; that.value(val.text); var videoOptions = { 'url': options.url diff --git a/js/ui/videoPlayer.js b/js/ui/videoPlayer.js index 2db0a0a..cce1241 100644 --- a/js/ui/videoPlayer.js +++ b/js/ui/videoPlayer.js @@ -1,15 +1,15 @@ pandora.ui.videoPlayer = function(options) { - var url = options.url; +// var url = options.url; var timeline = options.timeline || "foo.png"; //FIXME var that = pandora.$ui.videoPlayer = Ox.VideoPlayer({ - video: url, + video: options.url, controlsTop: ['fullscreen'], controlsBottom: ['play', 'volume', 'scale', 'timeline', 'position'], height: 300, width: 400, showControlsOnLoad: true, duration: 35, - timeline: timeline, + timeline: options.timeline || 'foo.png', title: 'Test Video', enableTimeline: true, enableKeyboard: true, @@ -17,6 +17,7 @@ pandora.ui.videoPlayer = function(options) { externalControls: true // enableTimeline: true }); + //that.videoName = options.name; return that; };