src/js/widgets/segmentsWidget.js
branchcalage-segmentsWidget
changeset 515 54324c5d82ab
parent 514 f5865a99be69
child 516 fe8c9f4791cb
equal deleted inserted replaced
514:f5865a99be69 515:54324c5d82ab
    64     if (view_type != "" && typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined"
    64     if (view_type != "" && typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined"
    65           && annotation.meta["id-ref"] != view_type) {
    65           && annotation.meta["id-ref"] != view_type) {
    66         continue;
    66         continue;
    67     }
    67     }
    68 
    68 
    69     segments_annotations.push({annotation: annotation, pixelValue: this.segmentToPixel(annotation)});
    69     segments_annotations.push(annotation);
    70   }
    70   }
    71     
    71     
    72   var totalWidth = this.selector.width() - segments_annotations.length;
    72   var totalWidth = this.selector.width() - segments_annotations.length;
    73   
    73   var lastSegment = IriSP.underscore.max(segments_annotations, function(annotation) { return annotation.end; });
    74   var currentWidth = IriSP.underscore.reduce(segments_annotations, function(memo, segment) { return memo + segment.pixelValue; }, 0);
    74   
    75   while(currentWidth > totalWidth) {
       
    76     var max = IriSP.underscore.max(segments_annotations, function(segment) { return segment.pixelValue; });
       
    77     max.pixelValue -= 1;
       
    78     currentWidth = IriSP.underscore.reduce(segments_annotations, function(memo, segment) { return memo + segment.pixelValue; }, 0);
       
    79   }
       
    80   
       
    81   console.log(currentWidth);
       
    82   for (i = 0; i < segments_annotations.length; i++) {
    75   for (i = 0; i < segments_annotations.length; i++) {
    83   
    76   
    84     var annotation = segments_annotations[i].annotation;
    77     var annotation = segments_annotations[i];
    85     var begin = Math.round((+ annotation.begin) / 1000);
    78     var begin = (+ annotation.begin);
    86     var end = Math.round((+ annotation.end) / 1000);
    79     var end = (+ annotation.end);
    87     var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000;
    80     var duration = this._serializer.currentMedia().meta["dc:duration"];
    88     var id = annotation.id;
    81     var id = annotation.id;
    89     var startPourcent 	= IriSP.timeToPourcent(begin, duration);
    82         
    90     var startPixel = Math.floor(this.selector.parent().width() * (startPourcent / 100));
    83     var startPixel = Math.floor(this.selector.parent().width() * (begin / duration));
    91 
    84 
    92     var pourcentWidth	= Math.floor(IriSP.timeToPourcent(end, duration) - startPourcent);
    85     var endPixel = Math.floor(this.selector.parent().width() * (end / duration));
    93     //var pxWidth = Math.floor(this.selector.parent().width() * (pourcentWidth / 100));
    86     var pxWidth = endPixel - startPixel -1;
    94     var pxWidth = segments_annotations[i].pixelValue;
    87  
    95 
       
    96     /* don't show annotation with an empty length */
       
    97     if (pxWidth === 0)
       
    98       continue;
       
    99       
       
   100     var divTitle = (annotation.content.title + " - " + annotation.content.description).substr(0,55);
    88     var divTitle = (annotation.content.title + " - " + annotation.content.description).substr(0,55);
   101 
    89 
   102     if (typeof(annotation.content.color) !== "undefined")
    90     if (typeof(annotation.content.color) !== "undefined")
   103       var color = annotation.content.color;
    91       var color = annotation.content.color;
   104     else
    92     else
   114     var annotationTemplate = Mustache.to_html(IriSP.annotation_template,
   102     var annotationTemplate = Mustache.to_html(IriSP.annotation_template,
   115         {"divTitle" : divTitle, "id" : id, "startPixel" : startPixel,
   103         {"divTitle" : divTitle, "id" : id, "startPixel" : startPixel,
   116         "pxWidth" : pxWidth, "hexa_color" : hexa_color,
   104         "pxWidth" : pxWidth, "hexa_color" : hexa_color,
   117         "seekPlace" : Math.round(begin/1000)});
   105         "seekPlace" : Math.round(begin/1000)});
   118 
   106 
       
   107         
   119     this.selector.append(annotationTemplate);
   108     this.selector.append(annotationTemplate);
   120 
   109     
   121 //    IriSP.jQuery("#" + id).tooltip({ effect: 'slide'});
   110     /* add a special class to the last segment */
       
   111     if (annotation.id === lastSegment.id) {
       
   112         this.selector.find("#" + id).addClass("Ldt-lastSegment");        
       
   113         this.selector.find(".Ldt-lastSegment").css("border-color", hexa_color);
       
   114     }
   122 
   115 
   123     IriSP.jQuery("#" + id).fadeTo(0, 0.3);
   116     IriSP.jQuery("#" + id).fadeTo(0, 0.3);
   124 
   117 
   125     IriSP.jQuery("#" + id).mouseover(
   118     IriSP.jQuery("#" + id).mouseover(
   126     /* we wrap the handler in another function because js's scoping
   119     /* we wrap the handler in another function because js's scoping