2010-11-10 23:43:02 +00:00
var padmaContainer ;
$ ( function ( ) {
padmaContainer = $ ( '#padmaSidebar' ) ;
padmaContainer . data ( "currentVideo" , false ) ;
2010-12-30 12:57:09 +00:00
function resize ( ) {
2010-12-30 08:48:14 +00:00
var docWidth = $ ( document ) . width ( ) ;
2011-01-02 09:19:51 +00:00
var barsWidth = $ ( '#leftBar' ) . length > 0 ? 650 : 400 ;
var essayWidth = docWidth - barsWidth ;
2010-12-30 16:17:36 +00:00
$ ( '#essayWrapper' ) . css ( "width" , essayWidth ) ;
2010-12-30 12:57:09 +00:00
}
resize ( ) ;
$ ( window ) . resize ( resize ) ;
2010-11-10 23:43:02 +00:00
} ) ;
function setupPadmaLink ( videoObj , data ) {
var $a = $ ( data . jq ) ;
2011-01-02 09:19:51 +00:00
2010-11-10 23:43:02 +00:00
// $a.data("isDisplayed", false);
2010-12-30 16:00:04 +00:00
//FIXME: tc is WRONG!!!
2011-01-01 14:14:42 +00:00
if ( ! $ . inArray ( data . linkData . type , [ "info" , "editor" , "tc" , "tcRange" , "layer" ] ) ) {
2010-12-30 15:45:42 +00:00
return false ;
}
2010-12-30 16:27:28 +00:00
// console.log(data.linkData);
2011-01-01 14:31:01 +00:00
//FIXME: this whole thing is a bit of rubbish, and they should not set type = 'tcRange'
2010-12-30 16:00:04 +00:00
if ( data . linkData . type == 'info' || data . linkData . type == 'editor' || data . linkData . type == "tc" ) {
2010-12-30 15:35:52 +00:00
data . linkData . tcIn = ms2npt ( 0 ) ;
data . linkData . tcOut = ms2npt ( videoObj . video . duration ) ;
2010-12-30 15:53:53 +00:00
data . linkData . type = "tcRange" ;
2010-11-13 19:07:59 +00:00
}
2010-12-30 15:57:36 +00:00
2011-01-01 14:14:42 +00:00
if ( data . linkData . type == 'layer' ) {
2011-02-23 09:49:07 +00:00
// console.log("LAYER");
// console.log(data.linkData);
2011-01-01 14:14:42 +00:00
var layer = videoObj . getLayerById ( data . linkData . layerId ) ;
2011-02-23 09:49:07 +00:00
// console.log(videoObj);
2011-01-01 14:14:42 +00:00
data . linkData . tcIn = ms2npt ( layer . time _in ) ;
data . linkData . tcOut = ms2npt ( layer . time _out ) ;
data . linkData . type = "tcRange" ;
}
2010-12-30 15:35:52 +00:00
var linkData = data . linkData ;
2011-01-02 09:19:51 +00:00
2010-11-10 23:43:02 +00:00
//FIXME: put this as a variable, option somewhere?
var $container = padmaContainer ;
videoObj . currentLayers = [ ] ;
2010-12-30 15:31:05 +00:00
var mid _frame _npt = ms2npt ( parseInt ( ( npt2ms ( linkData . tcIn ) + npt2ms ( linkData . tcOut ) ) / 2 ) ) ;
// console.log(mid_frame_npt);
var thumbUrl = videoObj . getFrame ( mid _frame _npt ) ;
2010-11-10 23:43:02 +00:00
//FIXME: Html may need to be conditional on linkData.type, probably put html in switch case above.
var html = tmpl ( "tmpl_tooltip" , { 'video' : videoObj , 'thumbUrl' : thumbUrl , 'linkData' : linkData } ) ;
// $a.attr("title", title);
$a . tooltip ( {
bodyHandler : function ( ) {
return html ;
} ,
showURL : false
} ) ;
$a . click ( function ( e ) {
2010-11-14 02:00:22 +00:00
// sidebarAnimateIn();
e . preventDefault ( ) ;
var currentVideo = padmaContainer . data ( "currentVideo" ) ;
2011-02-23 14:40:15 +00:00
if ( $ ( this ) . hasClass ( "nowPlaying" ) ) {
2010-11-14 02:00:22 +00:00
return ;
}
2011-02-23 14:40:15 +00:00
2010-11-14 02:00:22 +00:00
if ( currentVideo ) {
cleanupVideo ( currentVideo ) ;
}
$container . data ( "currentVideo" , videoObj ) ;
if ( ! isSidebarVisible ( ) ) {
sidebarAnimateIn ( ) ;
2011-01-02 09:19:51 +00:00
}
$ ( '.nowPlaying' ) . removeClass ( 'nowPlaying' ) ;
$ ( this ) . addClass ( "nowPlaying" ) ;
2010-11-14 02:00:22 +00:00
videoObj . getLayersData ( displayLayer , { 'linkData' : linkData } ) ;
2011-03-14 00:36:06 +00:00
// $('#loading').show().fadeTo(0.5);
2010-11-14 02:00:22 +00:00
function displayLayer ( videoObj , data ) {
2011-03-14 00:36:06 +00:00
// $('#loading').fadeOut().hide();
2010-11-14 02:00:22 +00:00
var linkData = data . linkData ;
var html = tmpl ( "tmpl_sidebar" , { 'video' : videoObj , 'linkData' : linkData } ) ;
$ ( '#padmaSidebarWrapper' ) . html ( html ) ;
$ ( '#aboutTxt' ) . hide ( ) ;
//FIXME: should be a better way to deal with displaying default layer.
var currentLayers = videoObj . getLayersAtTimecode ( npt2ms ( linkData . tcIn ) ) ;
2011-03-12 11:32:24 +00:00
// var annotHtml = getLayersHtml(npt2ms(linkData.tcIn), ['transcript']);
2011-03-14 00:41:52 +00:00
// var transcripts = filterLayersByTracks(currentLayers, ['transcript']);
2011-03-12 11:32:24 +00:00
2011-03-14 00:41:52 +00:00
// if (transcripts.length > 0) {
// var annotHtml = transcripts[0].value_html;
// } else {
// var annotHtml = '';
// }
2011-03-12 11:32:24 +00:00
2011-03-14 00:41:52 +00:00
// $('.annotationText').html(annotHtml);
2011-03-14 00:14:12 +00:00
var annotHeight = $ ( window ) . height ( ) - 340 ;
2011-03-12 11:32:24 +00:00
$ ( '.annotationText' ) . css ( { 'height' : annotHeight + "px" } ) ;
2010-11-14 02:00:22 +00:00
var videoElem = $ ( 'video' ) ;
2011-03-14 01:04:27 +00:00
var in _ms = npt2ms ( linkData . tcIn ) ;
$ ( '.annotationText' ) . html ( getLayersHtml ( in _ms , padmaConfig . default _layers ) ) ;
2011-03-13 23:10:24 +00:00
videoElem . bind ( "loadedmetadata" , function ( ) {
2011-03-14 01:04:27 +00:00
$ ( this ) . get ( 0 ) . currentTime = parseInt ( in _ms / 1000 ) ;
2011-03-13 23:10:24 +00:00
$ ( this ) . get ( 0 ) . play ( ) ;
} ) ;
2010-11-14 02:00:22 +00:00
videoElem . bind ( "play" , function ( ) {
var that = this
2011-01-02 09:19:51 +00:00
var displayLayers = padmaConfig . default _layers ;
2010-11-14 02:00:22 +00:00
videoObj . interval = setInterval ( function ( ) {
var currentTime = parseInt ( that . currentTime * 1000 ) ;
2011-03-14 01:04:27 +00:00
if ( currentTime == 0 ) { return ; } //Browser seems to return 0 as current time somewhere in between loadedmetadata, setting currentTime, and the play callback - this is a slightly silly hack - #FIXME.
// console.log(currentTime);
2011-03-13 23:10:24 +00:00
if ( currentTime > npt2ms ( linkData . tcOut ) ) {
videoElem . get ( 0 ) . pause ( ) ;
videoElem . trigger ( "ended" ) ;
return ;
}
var time _ms = currentTime ; // + npt2ms(linkData.tcIn);
2010-11-14 02:00:22 +00:00
var allLayers = videoObj . getLayersAtTimecode ( time _ms ) ;
if ( videoObj . currentLayers == allLayers ) {
return ;
}
2011-01-02 09:19:51 +00:00
var html = getLayersHtml ( time _ms , displayLayers ) ;
2010-12-30 19:29:07 +00:00
if ( html != $ ( '.annotationText' ) . html ( ) ) {
$ ( '.annotationText' ) . html ( html ) ;
2010-11-14 02:00:22 +00:00
}
} , 150 ) ;
} ) ;
videoElem . bind ( "pause" , function ( ) {
clearInterval ( videoObj . interval ) ;
} ) ;
videoElem . bind ( "ended" , function ( ) {
clearInterval ( videoObj . interval ) ;
2011-01-02 09:19:51 +00:00
if ( typeof $a . data ( "playlist" ) != 'undefined' ) {
var playlist = $a . data ( "playlist" ) ;
playlist . next ( ) ;
}
2010-11-14 02:00:22 +00:00
// cleanupVideo(videoObj);
2011-01-02 09:19:51 +00:00
// sidebarAnimateOut();
2010-11-14 02:00:22 +00:00
} ) ;
}
2010-11-10 23:43:02 +00:00
function sidebarAnimateIn ( ) {
/ *
$container . animate ( { 'width' : '400px' } , function ( ) {
$ ( this ) . animate ( { 'backgroundColor' : '#000000' } ) ;
} ) ;
var docWidth = $ ( document ) . width ( ) ;
var newWidth = docWidth - 440 ;
$ ( '#essay' ) . animate ( { 'width' : newWidth + "px" } ) ;
* /
// $container.show();
2010-11-14 02:00:22 +00:00
$ ( '#aboutTxt' ) . fadeOut ( ) ;
2010-11-10 23:43:02 +00:00
}
function sidebarAnimateOut ( ) {
$container . find ( '.padmaViewer' ) . empty ( ) ;
$ ( '#aboutTxt' ) . show ( ) ;
/ *
$container . animate ( { 'width' : '0px' } , function ( ) {
$ ( this ) . animate ( { 'backgroundColor' : '#ffffff' } ) ;
} ) ;
$ ( '#essay' ) . animate ( { 'width' : '100%' } ) ;
* /
}
2010-12-30 19:29:07 +00:00
function getLayersHtml ( tc , tracks ) {
//FIXME: This code is retarded, but we do want a way to group transcripts, descriptions, etc.
var currentLayers = videoObj . getLayersAtTimecode ( tc ) ;
var annotLayers = [ ] ;
var annotHtml = '' ;
for ( var t = 0 ; t < tracks . length ; t ++ ) {
var thisTrack = tracks [ t ] ;
var thisTrackLayers = filterLayersByTracks ( currentLayers , [ thisTrack ] ) ;
if ( thisTrackLayers . length > 0 ) {
2011-03-12 11:49:52 +00:00
annotHtml += '<span class="padmaTrack">' + thisTrack + "s:</span><br />" ;
2010-12-30 19:29:07 +00:00
}
for ( var i = 0 ; i < thisTrackLayers . length ; i ++ ) {
2011-03-12 11:49:52 +00:00
var thisTrack = thisTrackLayers [ i ] ;
2010-12-30 19:29:07 +00:00
var thisHtml = '' ;
thisHtml += " <span class='padmaAnnotation'>" + thisTrack . value _html + "</span>" ;
2011-02-21 12:28:19 +00:00
thisHtml += "<br />" ;
2011-02-21 13:57:04 +00:00
thisHtml += "<span class='padmaContributor'> -" + thisTrack . creator + "</span>" ;
2010-12-30 19:29:07 +00:00
thisHtml += "<br /><br />" ;
annotHtml += thisHtml ;
}
}
return annotHtml ;
}
2010-11-10 23:43:02 +00:00
function isSidebarVisible ( ) {
if ( padmaContainer . width ( ) > 0 ) {
return true ;
} else {
return false ;
}
}
} ) ;
}
//All functions that destroy the video must call this to ensure clean-ups are handled
// parameter is a padmaVideo object.
function cleanupVideo ( videoObj ) {
$ ( 'video' ) [ 0 ] . pause ( ) ;
2011-03-14 00:06:28 +00:00
$ ( 'video' ) . attr ( "src" , "" ) ;
2010-11-10 23:43:02 +00:00
clearInterval ( videoObj . interval ) ;
$ ( '.padmaViewer' ) . remove ( ) ;
padmaContainer . data ( "currentVideo" , false ) ;
}