fixed the segments widget.
--- a/src/js/widgets/segmentsWidget.js Thu Oct 20 15:50:04 2011 +0200
+++ b/src/js/widgets/segmentsWidget.js Thu Oct 20 15:52:00 2011 +0200
@@ -8,38 +8,51 @@
var annotations = this._serializer._data.annotations;
- for (i in annotations) {
+ var i = 0;
+ for (i = 0; i < annotations.length; i++) {
var annotation = annotations[i];
- console.log(annotation);
+
var begin = Math.round((+ annotation.begin) / 1000);
var end = Math.round((+ annotation.end) / 1000);
- var duration = (annotation.end - annotation.begin);
+ var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000;
var id = annotation.id;
var startPourcent = IriSP.timeToPourcent(begin, duration);
var endPourcent = IriSP.timeToPourcent(end, duration) - startPourcent;
var divTitle = annotation.content.title.substr(0,55);
var color = annotation.content.color
-
+
+
var annotationTemplate = Mustache.to_html(IriSP.annotation_template,
{"divTitle" : divTitle, "id" : id, "startPourcent" : startPourcent,
"endPourcent" : endPourcent, "hexa_color" : IriSP.DEC_HEXA_COLOR(color),
"seekPlace" : Math.round(begin/1000)});
+
var toolTipTemplate = Mustache.to_html(IriSP.tooltip_template,
{"title" : divTitle, "begin" : begin, "end" : end,
"description": annotation.content.description});
-
- IriSP.jQuery("<div>" + annotationTemplate + "</div>").appendTo("#Ldt-Annotations");
+
+ IriSP.jQuery(annotationTemplate).appendTo("#Ldt-Annotations");
// TOOLTIP BUG !
IriSP.jQuery("#" + id).tooltip({ effect: 'slide'});
IriSP.jQuery("#" + id).fadeTo(0,0.3);
+
IriSP.jQuery("#" + id).mouseover(function() {
IriSP.jQuery("#" + id).animate({opacity: 0.6}, 5);
}).mouseout(function(){
IriSP.jQuery("#" + id).animate({opacity: 0.3}, 5);
- });
+ });
+
+ IriSP.jQuery("#" + id).click(function(_this, annotation) {
+ return function() { _this.clickHandler(annotation)};
+ }(this, annotation));
}
-};
\ No newline at end of file
+};
+
+IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) {
+ var begin = Math.round((+ annotation.begin) / 1000);
+ this._Popcorn.currentTime(begin)
+}
\ No newline at end of file
--- a/unittests/tests/segmentsWidget.js Thu Oct 20 15:50:04 2011 +0200
+++ b/unittests/tests/segmentsWidget.js Thu Oct 20 15:52:00 2011 +0200
@@ -34,20 +34,23 @@
var widget = new IriSP.SegmentsWidget(this.Popcorn, this.config, this.ser);
widget.draw();
- console.dir(IriSP.jQuery("#Ldt-Annotations").get(0));
equal(IriSP.jQuery("#Ldt-Annotations").length, 1, "test if the div has been added correctly");
equal(IriSP.jQuery("#Ldt-Annotations").children().length, this.ser._data.annotations.length, "test if children have been added correctly");
});
- test("test annotation display function", function() {
- /*
- var widget = new IriSP.AnnotationsWidget(this.Popcorn, this.config, this.ser);
+ test("test click on a random segment", function() {
+ var widget = new IriSP.SegmentsWidget(this.Popcorn, this.config, this.ser);
widget.draw();
- var annotation = {content: {"title": "title", "description": "description", "keywords": "keywords"}};
- widget.displayAnnotation(annotation);
- equal(IriSP.jQuery("#Ldt-SaTitle").text(), "title", "title set correctly");
- equal(IriSP.jQuery("#Ldt-SaDescription").text(), "description", "description set correctly");
- equal(IriSP.jQuery("#Ldt-SaKeywordText").text(), "Mots clefs : ", "keywords field set correctly");
- */
+
+ var spy_callback = this.spy();
+ var spy_handler = sinon.spy(widget, "clickHandler");
+ this.Popcorn.listen("timeupdate", spy_callback);
+
+ var selector = IriSP.jQuery("#Ldt-Annotations :not(first-child)");
+ var random = Math.round(Math.random() * selector.length);
+ selector.eq(random).click();
+
+ ok(spy_callback.called, "the currenttime was changed");
+ ok(spy_handler.called, "handling function has been called");
});
};
\ No newline at end of file