src/js/widgets/annotationsWidget.js
author hamidouk
Fri, 09 Dec 2011 15:42:10 +0100
branchpopcorn-port
changeset 446 d801a7f9c7c5
parent 393 54947acf2770
child 470 19389e221722
permissions -rw-r--r--
removed unused line.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
98
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
     1
IriSP.AnnotationsWidget = function(Popcorn, config, Serializer) {
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
     2
  IriSP.Widget.call(this, Popcorn, config, Serializer);
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
     3
  
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
     4
};
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
     5
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
     6
139
ba2b3c15bd47 fixing prototype bug.
hamidouk
parents: 130
diff changeset
     7
IriSP.AnnotationsWidget.prototype = new IriSP.Widget();
98
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
     8
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
     9
IriSP.AnnotationsWidget.prototype.clear = function() {
162
2ef47ccb290f a couple fixes to the annotationsWidget tests.
hamidouk
parents: 146
diff changeset
    10
    this.selector.find(".Ldt-SaTitle").text("");
2ef47ccb290f a couple fixes to the annotationsWidget tests.
hamidouk
parents: 146
diff changeset
    11
    this.selector.find(".Ldt-SaDescription").text("");
2ef47ccb290f a couple fixes to the annotationsWidget tests.
hamidouk
parents: 146
diff changeset
    12
    this.selector.find(".Ldt-SaKeywordText").text("");
98
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    13
};
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    14
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    15
IriSP.AnnotationsWidget.prototype.displayAnnotation = function(annotation) {
264
9fb001b19dd2 clean-ups.
hamidouk
parents: 162
diff changeset
    16
98
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    17
    var title = annotation.content.title;
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    18
    var description = annotation.content.description;
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    19
    var keywords =  "" // FIXME;
309
49c2b9e63591 added segment duration display to the annotationsWidget
hamidouk
parents: 264
diff changeset
    20
    var begin = +annotation.begin / 1000;
49c2b9e63591 added segment duration display to the annotationsWidget
hamidouk
parents: 264
diff changeset
    21
    var end = +annotation.end / 1000;
98
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    22
    var duration = +this._serializer.currentMedia().meta["dc:duration"];
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    23
309
49c2b9e63591 added segment duration display to the annotationsWidget
hamidouk
parents: 264
diff changeset
    24
    var title_templ = "{{title}} - ( {{begin}} - {{end}} )";
49c2b9e63591 added segment duration display to the annotationsWidget
hamidouk
parents: 264
diff changeset
    25
    var endstr = Mustache.to_html(title_templ, {title: title, begin: IriSP.secondsToTime(begin), end: IriSP.secondsToTime(end)});
49c2b9e63591 added segment duration display to the annotationsWidget
hamidouk
parents: 264
diff changeset
    26
49c2b9e63591 added segment duration display to the annotationsWidget
hamidouk
parents: 264
diff changeset
    27
    this.selector.find(".Ldt-SaTitle").text(endstr);
162
2ef47ccb290f a couple fixes to the annotationsWidget tests.
hamidouk
parents: 146
diff changeset
    28
    this.selector.find(".Ldt-SaDescription").text(description);
98
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    29
};
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    30
125
960ce0b9f9f0 added a function to clear the widget.
hamidouk
parents: 101
diff changeset
    31
IriSP.AnnotationsWidget.prototype.clearWidget = function() {
264
9fb001b19dd2 clean-ups.
hamidouk
parents: 162
diff changeset
    32
9fb001b19dd2 clean-ups.
hamidouk
parents: 162
diff changeset
    33
    
125
960ce0b9f9f0 added a function to clear the widget.
hamidouk
parents: 101
diff changeset
    34
    /* retract the pane between two annotations */
162
2ef47ccb290f a couple fixes to the annotationsWidget tests.
hamidouk
parents: 146
diff changeset
    35
    this.selector.find(".Ldt-SaTitle").text("");
2ef47ccb290f a couple fixes to the annotationsWidget tests.
hamidouk
parents: 146
diff changeset
    36
    this.selector.find(".Ldt-SaDescription").text("");
2ef47ccb290f a couple fixes to the annotationsWidget tests.
hamidouk
parents: 146
diff changeset
    37
    this.selector.find(".Ldt-SaKeywordText").html("");
2ef47ccb290f a couple fixes to the annotationsWidget tests.
hamidouk
parents: 146
diff changeset
    38
    this.selector.find(".Ldt-ShowAnnotation").slideUp();
130
f25676c72044 added a semicolon.
hamidouk
parents: 125
diff changeset
    39
};
f25676c72044 added a semicolon.
hamidouk
parents: 125
diff changeset
    40
98
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    41
IriSP.AnnotationsWidget.prototype.draw = function() {
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    42
  var _this = this;
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    43
382
d68de477761b WIP - adding social buttons support.
hamidouk
parents: 312
diff changeset
    44
  var annotationMarkup = IriSP.templToHTML(IriSP.annotationWidget_template);
162
2ef47ccb290f a couple fixes to the annotationsWidget tests.
hamidouk
parents: 146
diff changeset
    45
	this.selector.append(annotationMarkup);
393
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
    46
  var view;
139
ba2b3c15bd47 fixing prototype bug.
hamidouk
parents: 130
diff changeset
    47
393
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
    48
  if (typeof(this._serializer._data.views) !== "undefined" && this._serializer._data.views !== null)
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
    49
     view = this._serializer._data.views[0];
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
    50
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
    51
  var view_type = "";
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
    52
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
    53
  if(typeof(view) !== "undefined" && typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) {
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
    54
          view_type = view.annotation_types[0];
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
    55
  }
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
    56
 
98
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    57
  var annotations = this._serializer._data.annotations;
146
b99527037c89 fixed global variable declaration bug.
hamidouk
parents: 139
diff changeset
    58
  var i;
b99527037c89 fixed global variable declaration bug.
hamidouk
parents: 139
diff changeset
    59
  
98
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    60
	for (i in annotations) {    
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    61
    var annotation = annotations[i];
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    62
    var begin = Math.round((+ annotation.begin) / 1000);
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    63
    var end = Math.round((+ annotation.end) / 1000);
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    64
393
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
    65
    if (view_type != "" && typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined"
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
    66
          && annotation.meta["id-ref"] != view_type) {
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
    67
        continue;
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
    68
    }
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
    69
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
    70
125
960ce0b9f9f0 added a function to clear the widget.
hamidouk
parents: 101
diff changeset
    71
    var conf = {start: begin, end: end, 
960ce0b9f9f0 added a function to clear the widget.
hamidouk
parents: 101
diff changeset
    72
                onStart: 
264
9fb001b19dd2 clean-ups.
hamidouk
parents: 162
diff changeset
    73
                       function(annotation) { 
9fb001b19dd2 clean-ups.
hamidouk
parents: 162
diff changeset
    74
                        return function() { 
393
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
    75
                            _this.displayAnnotation(annotation); 
264
9fb001b19dd2 clean-ups.
hamidouk
parents: 162
diff changeset
    76
                          
9fb001b19dd2 clean-ups.
hamidouk
parents: 162
diff changeset
    77
                        } }(annotation),
125
960ce0b9f9f0 added a function to clear the widget.
hamidouk
parents: 101
diff changeset
    78
                onEnd: 
264
9fb001b19dd2 clean-ups.
hamidouk
parents: 162
diff changeset
    79
                       function() { _this.clearWidget.call(_this); },
125
960ce0b9f9f0 added a function to clear the widget.
hamidouk
parents: 101
diff changeset
    80
                };
960ce0b9f9f0 added a function to clear the widget.
hamidouk
parents: 101
diff changeset
    81
    this._Popcorn = this._Popcorn.code(conf);                                             
98
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    82
  }
264
9fb001b19dd2 clean-ups.
hamidouk
parents: 162
diff changeset
    83
309
49c2b9e63591 added segment duration display to the annotationsWidget
hamidouk
parents: 264
diff changeset
    84
};