integration/js/editor.js
changeset 32 47f9a2d63a0a
parent 29 5ce5e26091ea
child 39 d3d8a88878ed
equal deleted inserted replaced
30:1cb099921ca8 32:47f9a2d63a0a
       
     1 
       
     2 IriSP.hc_messages = {
       
     3     duration_ : "Durée :",
       
     4     edit_segment: "Éditer le segment",
       
     5     segment_down: "Descendre le segment",
       
     6     segment_up: "Remonter le segment",
       
     7     delete_segment: "Supprimer le segment"
       
     8 }
       
     9 
     1 IriSP.Hashcut = function(options) {
    10 IriSP.Hashcut = function(options) {
       
    11     
     2     
    12     
     3     /* Load Media List */
    13     /* Load Media List */
     4     
    14     
     5     var directory = new IriSP.Model.Directory(),
    15     var directory = new IriSP.Model.Directory(),
     6         project = directory.remoteSource({
    16         project = directory.remoteSource({
     8             serializer: IriSP.serializers.medialist
    18             serializer: IriSP.serializers.medialist
     9         }),
    19         }),
    10         mashup = new IriSP.Model.Mashup(false, project),
    20         mashup = new IriSP.Model.Mashup(false, project),
    11         mediatemplate = _.template('<li class="item-video" data-media-id="<%= id %>"><img src="<%= thumbnail %>" alt="<%= title %>" />'
    21         mediatemplate = _.template('<li class="item-video" data-media-id="<%= id %>"><img src="<%= thumbnail %>" alt="<%= title %>" />'
    12             + '<span class="video-info"><span class="title-video"><%= title %></span><span class="author"><%= description %></span>'
    22             + '<span class="video-info"><span class="title-video"><%= title %></span><span class="author"><%= description %></span>'
    13             + '<span class="time-length">Durée : <span><%= duration.toString() %></span></span></span></li>'),
    23             + '<span class="time-length"><%= IriSP.hc_messages.duration_ %> <span><%= duration.toString() %></span></span></span></li>'),
    14         segmenttemplate = _.template('<li class="item-video" data-segment-id="<%= annotation.id %>" data-media-id="<%= annotation.getMedia().id %>">'
    24         segmenttemplate = _.template('<li class="item-video" data-segment-id="<%= annotation.id %>" data-media-id="<%= annotation.getMedia().id %>">'
    15             + '<img src="<%= annotation.getMedia().thumbnail %>" alt="<%= annotation.getMedia().title %>" />'
    25             + '<img src="<%= annotation.getMedia().thumbnail %>" alt="<%= annotation.getMedia().title %>" />'
    16             + '<span class="video-info"><span class="title-video"><%= annotation.getMedia().title %></span>'
    26             + '<span class="video-info"><span class="title-video"><%= annotation.getMedia().title %></span>'
    17             + '<span class="subtitle"><%= annotation.title %></span><span class="duration"><%= annotation.begin.toString() %> - <%= annotation.end.toString() %> (<%= annotation.getDuration().toString() %>)</span>'
    27             + '<span class="subtitle"><%= annotation.title %></span><span class="duration"><%= annotation.begin.toString() %> - <%= annotation.end.toString() %> (<%= annotation.getDuration().toString() %>)</span>'
    18             + '<ul class="tools"><li><a class="edit" href="#" title="Éditer le segment"></a></li><li><a class="bottom" href="#" title="Descendre le segment"></a></li>'
    28             + '<ul class="tools"><li><a class="edit" href="#" title="<%= IriSP.hc_messages.edit_segment %>"></a></li><li><a class="bottom" href="#" title="<%= IriSP.hc_messages.segment_down %>"></a></li>'
    19             + '<li><a class="top" href="#" title="Remonter le segment"></a></li><li><a class="delete" href="#" title="Supprimer le segment"></a></li></ul></span></li>'),
    29             + '<li><a class="top" href="#" title="<%= IriSP.hc_messages.segment_up %>"></a></li><li><a class="delete" href="#" title="<%= IriSP.hc_messages.delete_segment %>"></a></li></ul></span></li>'),
    20         viztemplate = _.template('<div class="frise-segment" style="background-color:<%= color %>; left:<%= left %>%; width:<%= width %>%;"></div>'),
    30         viztemplate = _.template('<div class="frise-segment" data-segment-id="<%= segmentid %>" style="background-color:<%= color %>; left:<%= left %>%; width:<%= width %>%;"></div>'),
    21         intervaltemplate = _.template('<span class="frise-indication" style="left:<%= left %>%;"><%= time.toString() %></span>'),
    31         intervaltemplate = _.template('<span class="frise-indication" style="left:<%= left %>%;"><%= time.toString() %></span>'),
    22         mediasegmenttemplate = _.template('<div class="media-segments-list"><div class="media-segment">'
    32         mediasegmenttemplate = _.template('<div class="media-segments-list"><div class="media-segment">'
    23             + '<div class="media-section media-segment-section" style="left:<%= left %>px; width:<%= width %>px; background:<%= annotation.getMedia().color %>"></div>'
    33             + '<div class="media-section media-segment-section" style="left:<%= left %>px; width:<%= width %>px; background:<%= annotation.getMedia().color %>"></div>'
    24             + '<div class="media-section media-current-section" style="left:<%= currentleft %>px; width:<%= currentwidth %>px;"><div class="media-current-section-inner"></div></div>'
    34             + '<div class="media-section media-current-section" style="left:<%= currentleft %>px; width:<%= currentwidth %>px;"><div class="media-current-section-inner"></div></div>'
    25             + '<div class="popin media-segment-popin" style="left:<%= popleft %>px"><img style="left:<%= pointerpos %>px;" class="pointer" src="img/popin-triangle.png" alt="" /><div class="popin-content">'
    35             + '<div class="popin media-segment-popin" style="left:<%= popleft %>px"><img style="left:<%= pointerpos %>px;" class="pointer" src="img/popin-triangle.png" alt="" /><div class="popin-content">'
    77         mashup.segments.forEach(function(_s) {
    87         mashup.segments.forEach(function(_s) {
    78             listhtml += segmenttemplate(_s);
    88             listhtml += segmenttemplate(_s);
    79             var vizdata = {
    89             var vizdata = {
    80                 left: k * t,
    90                 left: k * t,
    81                 width: k * _s.duration,
    91                 width: k * _s.duration,
    82                 color: _s.getMedia().color
    92                 color: _s.getMedia().color,
       
    93                 segmentid: _s.annotation.id
    83             }
    94             }
    84             vizhtml += viztemplate(vizdata);
    95             vizhtml += viztemplate(vizdata);
    85             t += _s.duration.milliseconds;
    96             t += _s.duration.milliseconds;
    86         });
    97         });
    87         
    98         
   180         })
   191         })
   181         .mouseout(timeSliderMouseOut);
   192         .mouseout(timeSliderMouseOut);
   182     timeSlider.mousemove(function(_e) {
   193     timeSlider.mousemove(function(_e) {
   183             var _x = _e.pageX - timeSlider.offset().left,
   194             var _x = _e.pageX - timeSlider.offset().left,
   184                 _t = new IriSP.Model.Time(
   195                 _t = new IriSP.Model.Time(
   185                     currentMedia ? currentMedia.duration * _x / timeSlider.width() : 0
       
   186                 );
   196                 );
   187             timeTooltip.text(_t.toString()).css("left",_x);
   197             timeTooltip.text(_t.toString()).css("left",_x);
   188         });
   198         });
   189     
   199     
   190     $(".Ldt-Ctrl").mouseover(timeSliderMouseOver).mouseout(timeSliderMouseOut);
   200     $(".Ldt-Ctrl").mouseover(timeSliderMouseOver).mouseout(timeSliderMouseOut);
   364         mashupCurrentAnnotation = null,
   374         mashupCurrentAnnotation = null,
   365         mashupSegmentBegin,
   375         mashupSegmentBegin,
   366         mashupSegmentEnd,
   376         mashupSegmentEnd,
   367         mashupTimecode = 0,
   377         mashupTimecode = 0,
   368         mashupSeeking = false,
   378         mashupSeeking = false,
   369         mashupSeekdiv,
   379         seekdiv = $(".video-wait"),
   370         mashupTimedelta;
   380         mashupTimedelta;
   371         
   381     
       
   382     function showSeek() {
       
   383         if (mashupSeeking) {
       
   384             seekdiv.show();
       
   385         }
       
   386     }
       
   387     
   372     function changeCurrentAnnotation() {
   388     function changeCurrentAnnotation() {
   373         if (mashupTimecode >= mashup.duration) {
   389         if (mashupTimecode >= mashup.duration) {
   374             if (!mashup.paused) {
   390             if (!mashup.paused) {
   375                 mashup.paused = true;
   391                 mashup.paused = true;
   376                 mashup.trigger("pause");
   392                 mashup.trigger("pause");
   407         mashupCurrentMedia.seeking = true;
   423         mashupCurrentMedia.seeking = true;
   408         
   424         
   409         if (!mashup.paused) {
   425         if (!mashup.paused) {
   410             mashupCurrentMedia.play();
   426             mashupCurrentMedia.play();
   411             mashupSeeking = true;
   427             mashupSeeking = true;
   412 //TODO:            _seekdiv.show();
   428             setTimeout(showSeek,200);
   413         }
   429         }
   414         mashup.trigger("timeupdate", new IriSP.Model.Time(mashupTimecode));
   430         mashup.trigger("timeupdate", new IriSP.Model.Time(mashupTimecode));
   415 
   431 
   416     }
   432     }
   417     
   433     
   443     }
   459     }
   444     
   460     
   445     var addMode;
   461     var addMode;
   446     
   462     
   447     function setMedia(media) {
   463     function setMedia(media) {
   448         $(".col-left .item-video").removeClass("active");
       
   449         $(".tutorial").hide();
       
   450         //TODO: Show Tutorial when Hashcut is empty
       
   451         if (currentMedia) {
   464         if (currentMedia) {
   452             currentMedia.pause();
   465             currentMedia.pause();
   453         }
   466         }
   454         currentMedia = media;
   467         currentMedia = media;
   455         if (currentMedia.elementType == "media") {
   468         if (currentMedia.elementType == "media") {
   456             $("video").hide();
   469             $("video").hide();
   457             $(".col-left .item-video[data-media-id='" + currentMedia.id + "']").addClass("active");
       
   458             showSegmentation();
   470             showSegmentation();
       
   471             if (!currentMedia.loaded) {
       
   472                 seekdiv.show();
       
   473             }
   459             var currentvideo = $('#video_' + currentMedia.id);
   474             var currentvideo = $('#video_' + currentMedia.id);
   460             if (!currentvideo.length) {
   475             if (!currentvideo.length) {
   461                 addMediaPlayer(currentMedia);
   476                 addMediaPlayer(currentMedia);
   462             }
   477             }
   463             $(".tab-media-title").text(currentMedia.title);
   478             $(".tab-media-title").text(currentMedia.title);
   489                         $(".annotation-begin").text(this.begin.toString());
   504                         $(".annotation-begin").text(this.begin.toString());
   490                         $(".annotation-end").text(this.end.toString());
   505                         $(".annotation-end").text(this.end.toString());
   491                         $(".annotation-media-title").text(this.getMedia().title);
   506                         $(".annotation-media-title").text(this.getMedia().title);
   492                         $(".annotation-description").text(this.description);
   507                         $(".annotation-description").text(this.description);
   493                         setPointerToCurrentAnnotation();
   508                         setPointerToCurrentAnnotation();
       
   509                         highlightCurrentSegment();
   494                     }
   510                     }
   495                 });
   511                 });
   496             }
   512             }
   497             if (currentMedia.loaded) {
   513             if (currentMedia.loaded) {
   498                 currentMedia.setCurrentTime(currentSegment.begin);
   514                 currentMedia.setCurrentTime(currentSegment.begin);
   653         });
   669         });
   654         
   670         
   655         // Binding UI Events and Mashup Playing to Media
   671         // Binding UI Events and Mashup Playing to Media
   656         
   672         
   657         media.on("loadedmetadata", function() {
   673         media.on("loadedmetadata", function() {
       
   674             if (media === currentMedia) {
       
   675                 seekdiv.hide();
       
   676             }
   658             mashup.checkLoaded();
   677             mashup.checkLoaded();
   659         });
   678         });
   660         
   679         
   661         media.on("play", function() {
   680         media.on("play", function() {
   662             if (media === currentMedia) {
   681             if (media === currentMedia) {
   699         
   718         
   700         media.on("seeked", function() {
   719         media.on("seeked", function() {
   701             media.seeking = false;
   720             media.seeking = false;
   702             if (mashup === currentMedia && media === mashupCurrentMedia && mashupSeeking) {
   721             if (mashup === currentMedia && media === mashupCurrentMedia && mashupSeeking) {
   703                 mashupSeeking = false;
   722                 mashupSeeking = false;
   704 //TODO:                _seekdiv.hide();
   723                 seekdiv.hide();
   705             }
   724             }
   706         });
   725         });
   707         
   726         
   708         media.on("volumechange", function() {
   727         media.on("volumechange", function() {
   709             if (media === currentMedia) {
   728             if (media === currentMedia) {
   819     }
   838     }
   820     function showPreview() {
   839     function showPreview() {
   821         $(".col-middle").removeClass("empty-mode segment-mode").addClass("pvw-mode");
   840         $(".col-middle").removeClass("empty-mode segment-mode").addClass("pvw-mode");
   822         return false;
   841         return false;
   823     }
   842     }
       
   843     function showEmpty() {
       
   844         $("video").hide();
       
   845         $(".col-middle").removeClass("pvw-mode segment-mode").addClass("empty-mode");
       
   846         return false;
       
   847     }
   824     
   848     
   825     $(".tab-pvw").click(function() {
   849     $(".tab-pvw").click(function() {
   826         if (mashup.segments.length) {
   850         if (mashup.segments.length) {
   827             setMedia(mashup);
   851             setMedia(mashup);
   828         }
   852         }
   834         var ids = $(".organize-segments .item-video").map(function(){return $(this).attr("data-segment-id")});
   858         var ids = $(".organize-segments .item-video").map(function(){return $(this).attr("data-segment-id")});
   835         mashup.setAnnotationsById(ids);
   859         mashup.setAnnotationsById(ids);
   836     }
   860     }
   837     
   861     
   838     function highlightCurrentSegment() {
   862     function highlightCurrentSegment() {
   839         $(".organize-segments .item-video").removeClass("active");
   863         $(".organize-segments .item-video, .col-left .item-video, .frise-segment").removeClass("active");
       
   864         var segmentid = undefined;
   840         if (currentMedia && currentSegment) {
   865         if (currentMedia && currentSegment) {
   841             $(".item-video[data-segment-id='" + currentSegment.id + "']").addClass("active");
   866             segmentid = currentSegment.id;
   842         }
   867         }
   843     }
   868         if (currentMedia === mashup && mashupCurrentAnnotation) {
   844     
   869             segmentid = mashupCurrentAnnotation.annotation.id;
   845     $(".organize-segments").sortable({
   870         }
       
   871         $(".item-video[data-segment-id='" + segmentid + "']").addClass("active");
       
   872         var mediaid = undefined;
       
   873         if (currentMedia) {
       
   874             mediaid = currentMedia.id;
       
   875         }
       
   876         if (currentMedia === mashup && mashupCurrentMedia) {
       
   877             mediaid = mashupCurrentMedia.id
       
   878         }
       
   879         $(".col-left .item-video[data-media-id='" + mediaid + "']").addClass("active");
       
   880     }
       
   881     
       
   882     function hoverSegment() {
       
   883         var segmentid = $(this).attr("data-segment-id");
       
   884         $(".organize-segments .item-video, .frise-segment").removeClass("active");
       
   885         $(".item-video[data-segment-id='" + segmentid + "'], .frise-segment[data-segment-id='" + segmentid + "']").addClass("active");
       
   886     }
       
   887     
       
   888     $(".frise")
       
   889     .on("mouseover", ".frise-segment", hoverSegment)
       
   890     .on("mouseout", ".frise-segment", highlightCurrentSegment)
       
   891     
       
   892     $(".organize-segments")
       
   893     .sortable({
   846         stop : reorganizeMashup
   894         stop : reorganizeMashup
   847     });
   895     })
   848     
   896     .on("mouseover", ".item-video", hoverSegment)
   849     $(".organize-segments").on("click", ".item-video", function(e) {
   897     .on("mouseout", ".item-video", highlightCurrentSegment)
       
   898     .on("click", ".item-video", function(e) {
   850         var el = $(this),
   899         var el = $(this),
   851             segment = mashup.getAnnotationById(el.attr("data-segment-id"));
   900             segment = mashup.getAnnotationById(el.attr("data-segment-id"));
   852         setMedia(mashup);
   901         setMedia(mashup);
   853         if (segment) {
   902         if (segment) {
   854             mashup.setCurrentTime(segment.begin);
   903             mashup.setCurrentTime(segment.begin);
   855         }
   904         }
   856         return false;
   905         return false;
   857     });
   906     })
   858     
   907     .on("click", ".edit", function(e) {
   859     $(".organize-segments").on("click", ".edit", function(e) {
       
   860         var currentItem = $(this).parents(".item-video"),
   908         var currentItem = $(this).parents(".item-video"),
   861             media = project.getElement(currentItem.attr("data-media-id")),
   909             media = project.getElement(currentItem.attr("data-media-id")),
   862             segment = project.getElement(currentItem.attr("data-segment-id"));
   910             segment = project.getElement(currentItem.attr("data-segment-id"));
   863         currentSegment = segment;
   911         currentSegment = segment;
   864         setMedia(media);
   912         setMedia(media);
   865         return false;
   913         return false;
   866     });
   914     })
   867     
   915     .on("click", ".top", function(e){
   868     $(".organize-segments").on("click", ".top", function(e){
       
   869         var currentItem = $(this).parents(".item-video");
   916         var currentItem = $(this).parents(".item-video");
   870         currentItem.insertBefore(currentItem.prev());
   917         currentItem.insertBefore(currentItem.prev());
   871 		reorganizeMashup();
   918 		reorganizeMashup();
   872 		return false;
   919 		return false;
   873     });
   920     })
   874     
   921     .on("click", ".bottom", function(e){
   875     $(".organize-segments").on("click", ".bottom", function(e){
       
   876         var currentItem = $(this).parents(".item-video");
   922         var currentItem = $(this).parents(".item-video");
   877         currentItem.insertAfter(currentItem.next());
   923         currentItem.insertAfter(currentItem.next());
   878 		reorganizeMashup();
   924 		reorganizeMashup();
   879         return false;
   925         return false;
   880     });
   926     })
   881     
   927     .on("click", ".delete", function(e){
   882     $(".organize-segments").on("click", ".delete", function(e){
       
   883         var id = $(this).parents(".item-video").attr("data-segment-id");
   928         var id = $(this).parents(".item-video").attr("data-segment-id");
   884         mashup.removeAnnotationById(id);
   929         mashup.removeAnnotationById(id);
       
   930         if (!mashup.segments.length) {
       
   931             showEmpty();
       
   932         }
   885         return false;
   933         return false;
   886     });
   934     });
   887     
   935     
   888     /* Tangles */
   936     /* Tangles */
   889     var tangleMsPerPixel = 100,
   937     var tangleMsPerPixel = 100,
   970         currentSegment.setBegin(s.begin);
  1018         currentSegment.setBegin(s.begin);
   971         currentSegment.setEnd(s.end);
  1019         currentSegment.setEnd(s.end);
   972         return false;
  1020         return false;
   973     });
  1021     });
   974     
  1022     
       
  1023     /* Changing Hashcut Title and description */
       
  1024    
       
  1025     $("#hashcut-title").on("keyup change input paste", function() {
       
  1026         mashup.title = $(this).val();
       
  1027         $(".title-video-wrap a").text(mashup.title);
       
  1028     });
       
  1029     
   975 }
  1030 }