src/js/widgets/annotationsWidget.js
author veltr
Thu, 08 Mar 2012 18:38:46 +0100
branchpopcorn-port
changeset 830 18ca612e9ff0
parent 820 7968346b9689
child 838 03b03865eb9b
permissions -rw-r--r--
Lots of changes
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);
541
f7667a1dde8e react to said signal.
hamidouk
parents: 538
diff changeset
     3
  /* flag used when we're creating an annotation */
f7667a1dde8e react to said signal.
hamidouk
parents: 538
diff changeset
     4
  this._hidden = false;
98
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
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
     7
139
ba2b3c15bd47 fixing prototype bug.
hamidouk
parents: 130
diff changeset
     8
IriSP.AnnotationsWidget.prototype = new IriSP.Widget();
98
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
     9
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    10
IriSP.AnnotationsWidget.prototype.clear = function() {
162
2ef47ccb290f a couple fixes to the annotationsWidget tests.
hamidouk
parents: 146
diff changeset
    11
    this.selector.find(".Ldt-SaTitle").text("");
2ef47ccb290f a couple fixes to the annotationsWidget tests.
hamidouk
parents: 146
diff changeset
    12
    this.selector.find(".Ldt-SaDescription").text("");
2ef47ccb290f a couple fixes to the annotationsWidget tests.
hamidouk
parents: 146
diff changeset
    13
    this.selector.find(".Ldt-SaKeywordText").text("");
98
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
541
f7667a1dde8e react to said signal.
hamidouk
parents: 538
diff changeset
    16
IriSP.AnnotationsWidget.prototype.displayAnnotation = function(annotation) {       
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;
798
56fd575cb447 little clean modif.
cavaliet
parents: 782
diff changeset
    19
    var keywords =  "";
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;
820
7968346b9689 Added compatibility with cinecast format (with get_aliased)
veltr
parents: 798
diff changeset
    22
    var duration = this._serializer.getDuration();
782
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    23
    var tags = "";
470
19389e221722 the annotationWidget "share" buttons now work correctly.
hamidouk
parents: 393
diff changeset
    24
    
309
49c2b9e63591 added segment duration display to the annotationsWidget
hamidouk
parents: 264
diff changeset
    25
    var title_templ = "{{title}} - ( {{begin}} - {{end}} )";
49c2b9e63591 added segment duration display to the annotationsWidget
hamidouk
parents: 264
diff changeset
    26
    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
    27
49c2b9e63591 added segment duration display to the annotationsWidget
hamidouk
parents: 264
diff changeset
    28
    this.selector.find(".Ldt-SaTitle").text(endstr);
162
2ef47ccb290f a couple fixes to the annotationsWidget tests.
hamidouk
parents: 146
diff changeset
    29
    this.selector.find(".Ldt-SaDescription").text(description);
470
19389e221722 the annotationWidget "share" buttons now work correctly.
hamidouk
parents: 393
diff changeset
    30
    
782
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    31
    
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    32
    if (!IriSP.null_or_undefined(annotation.tags) && !IriSP.null_or_undefined(this._serializer._data.tags)) {
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    33
      /* save the tag id and keywords in a unique structure */
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    34
      var tag_list = {};
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    35
      for (var i = 0; i < this._serializer._data.tags.length; i++) {
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    36
        var id = this._serializer._data.tags[i]["id"];
820
7968346b9689 Added compatibility with cinecast format (with get_aliased)
veltr
parents: 798
diff changeset
    37
        var keyword = IriSP.get_aliased(this._serializer._data.tags[i]["meta"], ["dc:title", "title"]);
782
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    38
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    39
        tag_list[id] = keyword;
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    40
      }
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    41
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    42
      /* then browse the list of defined tags for the current annotation */
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    43
      for (var i = 0; i < annotation.tags.length; i++) {
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    44
        if (tag_list.hasOwnProperty(annotation.tags[i]["id-ref"]))
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    45
          tags += tag_list[annotation.tags[i]["id-ref"]] + ", ";
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    46
      }
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    47
    }
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    48
    
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    49
    tags = "Keywords: " + tags.slice(0, tags.length - 2);
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    50
    
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    51
    this.selector.find(".Ldt-SaKeywords").text(tags);
144e215dd324 added tags.
hamidouk
parents: 777
diff changeset
    52
    
470
19389e221722 the annotationWidget "share" buttons now work correctly.
hamidouk
parents: 393
diff changeset
    53
    // update sharing buttons
19389e221722 the annotationWidget "share" buttons now work correctly.
hamidouk
parents: 393
diff changeset
    54
    var defaults = IriSP.widgetsDefaults.AnnotationsWidget;
19389e221722 the annotationWidget "share" buttons now work correctly.
hamidouk
parents: 393
diff changeset
    55
    var text = defaults.share_text;
19389e221722 the annotationWidget "share" buttons now work correctly.
hamidouk
parents: 393
diff changeset
    56
    var fb_link = defaults.fb_link;
19389e221722 the annotationWidget "share" buttons now work correctly.
hamidouk
parents: 393
diff changeset
    57
    var tw_link = defaults.tw_link;
19389e221722 the annotationWidget "share" buttons now work correctly.
hamidouk
parents: 393
diff changeset
    58
    var gplus_link = defaults.gplus_link;
651
c43441822b1b use the new annotation shortening functions.
hamidouk
parents: 595
diff changeset
    59
    var url = document.location.href + "#id=" + annotation.id;
c43441822b1b use the new annotation shortening functions.
hamidouk
parents: 595
diff changeset
    60
    this.selector.find(".Ldt-fbShare").attr("href", IriSP.mkFbUrl(url, text));
c43441822b1b use the new annotation shortening functions.
hamidouk
parents: 595
diff changeset
    61
    this.selector.find(".Ldt-TwShare").attr("href", IriSP.mkTweetUrl(url, text));
c43441822b1b use the new annotation shortening functions.
hamidouk
parents: 595
diff changeset
    62
    this.selector.find(".Ldt-GplusShare").attr("href", IriSP.mkGplusUrl(url, text));
98
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    63
};
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    64
541
f7667a1dde8e react to said signal.
hamidouk
parents: 538
diff changeset
    65
IriSP.AnnotationsWidget.prototype.clearWidget = function() {   
125
960ce0b9f9f0 added a function to clear the widget.
hamidouk
parents: 101
diff changeset
    66
    /* retract the pane between two annotations */
162
2ef47ccb290f a couple fixes to the annotationsWidget tests.
hamidouk
parents: 146
diff changeset
    67
    this.selector.find(".Ldt-SaTitle").text("");
2ef47ccb290f a couple fixes to the annotationsWidget tests.
hamidouk
parents: 146
diff changeset
    68
    this.selector.find(".Ldt-SaDescription").text("");
2ef47ccb290f a couple fixes to the annotationsWidget tests.
hamidouk
parents: 146
diff changeset
    69
    this.selector.find(".Ldt-SaKeywordText").html("");
2ef47ccb290f a couple fixes to the annotationsWidget tests.
hamidouk
parents: 146
diff changeset
    70
    this.selector.find(".Ldt-ShowAnnotation").slideUp();
130
f25676c72044 added a semicolon.
hamidouk
parents: 125
diff changeset
    71
};
f25676c72044 added a semicolon.
hamidouk
parents: 125
diff changeset
    72
98
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    73
IriSP.AnnotationsWidget.prototype.draw = function() {
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    74
  var _this = this;
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    75
382
d68de477761b WIP - adding social buttons support.
hamidouk
parents: 312
diff changeset
    76
  var annotationMarkup = IriSP.templToHTML(IriSP.annotationWidget_template);
162
2ef47ccb290f a couple fixes to the annotationsWidget tests.
hamidouk
parents: 146
diff changeset
    77
	this.selector.append(annotationMarkup);
541
f7667a1dde8e react to said signal.
hamidouk
parents: 538
diff changeset
    78
777
96e89720ff18 added show/hide message. Removed reaction to annotateClick signal
hamidouk
parents: 651
diff changeset
    79
  this._Popcorn.listen("IriSP.AnnotationsWidget.show", 
96e89720ff18 added show/hide message. Removed reaction to annotateClick signal
hamidouk
parents: 651
diff changeset
    80
                        IriSP.wrap(this, this.show));
96e89720ff18 added show/hide message. Removed reaction to annotateClick signal
hamidouk
parents: 651
diff changeset
    81
  this._Popcorn.listen("IriSP.AnnotationsWidget.hide", 
96e89720ff18 added show/hide message. Removed reaction to annotateClick signal
hamidouk
parents: 651
diff changeset
    82
                        IriSP.wrap(this, this.hide));
96e89720ff18 added show/hide message. Removed reaction to annotateClick signal
hamidouk
parents: 651
diff changeset
    83
 
595
29d86e6c61a6 finished going through the widgets to add stricter line checking.
hamidouk
parents: 541
diff changeset
    84
  var legal_ids = [];
29d86e6c61a6 finished going through the widgets to add stricter line checking.
hamidouk
parents: 541
diff changeset
    85
  if (typeof(this._serializer.getChapitrage()) !== "undefined")
29d86e6c61a6 finished going through the widgets to add stricter line checking.
hamidouk
parents: 541
diff changeset
    86
    legal_ids.push(this._serializer.getChapitrage());
29d86e6c61a6 finished going through the widgets to add stricter line checking.
hamidouk
parents: 541
diff changeset
    87
  else 
29d86e6c61a6 finished going through the widgets to add stricter line checking.
hamidouk
parents: 541
diff changeset
    88
    legal_ids = this._serializer.getNonTweetIds();
538
b778b2f93ef4 fixed a similar "id-ref" bug.
hamidouk
parents: 493
diff changeset
    89
  
98
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    90
  var annotations = this._serializer._data.annotations;
146
b99527037c89 fixed global variable declaration bug.
hamidouk
parents: 139
diff changeset
    91
  var i;
b99527037c89 fixed global variable declaration bug.
hamidouk
parents: 139
diff changeset
    92
  
98
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    93
	for (i in annotations) {    
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    94
    var annotation = annotations[i];
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    95
    var begin = Math.round((+ annotation.begin) / 1000);
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    96
    var end = Math.round((+ annotation.end) / 1000);
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
    97
538
b778b2f93ef4 fixed a similar "id-ref" bug.
hamidouk
parents: 493
diff changeset
    98
    if (typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined"
b778b2f93ef4 fixed a similar "id-ref" bug.
hamidouk
parents: 493
diff changeset
    99
          && !IriSP.underscore.include(legal_ids, annotation.meta["id-ref"])) {
393
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
   100
        continue;
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
   101
    }
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
   102
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
   103
125
960ce0b9f9f0 added a function to clear the widget.
hamidouk
parents: 101
diff changeset
   104
    var conf = {start: begin, end: end, 
960ce0b9f9f0 added a function to clear the widget.
hamidouk
parents: 101
diff changeset
   105
                onStart: 
264
9fb001b19dd2 clean-ups.
hamidouk
parents: 162
diff changeset
   106
                       function(annotation) { 
9fb001b19dd2 clean-ups.
hamidouk
parents: 162
diff changeset
   107
                        return function() { 
393
54947acf2770 ignore tweets.
hamidouk
parents: 382
diff changeset
   108
                            _this.displayAnnotation(annotation); 
264
9fb001b19dd2 clean-ups.
hamidouk
parents: 162
diff changeset
   109
                          
9fb001b19dd2 clean-ups.
hamidouk
parents: 162
diff changeset
   110
                        } }(annotation),
125
960ce0b9f9f0 added a function to clear the widget.
hamidouk
parents: 101
diff changeset
   111
                onEnd: 
493
f7333cdf5320 fixed trailing comma to please IE.
hamidouk
parents: 470
diff changeset
   112
                       function() { _this.clearWidget.call(_this); }
125
960ce0b9f9f0 added a function to clear the widget.
hamidouk
parents: 101
diff changeset
   113
                };
960ce0b9f9f0 added a function to clear the widget.
hamidouk
parents: 101
diff changeset
   114
    this._Popcorn = this._Popcorn.code(conf);                                             
98
ed4ac18baf07 broke the widgets.js in multiple files.
hamidouk
parents:
diff changeset
   115
  }
264
9fb001b19dd2 clean-ups.
hamidouk
parents: 162
diff changeset
   116
309
49c2b9e63591 added segment duration display to the annotationsWidget
hamidouk
parents: 264
diff changeset
   117
};
541
f7667a1dde8e react to said signal.
hamidouk
parents: 538
diff changeset
   118
777
96e89720ff18 added show/hide message. Removed reaction to annotateClick signal
hamidouk
parents: 651
diff changeset
   119
IriSP.AnnotationsWidget.prototype.hide = function() {
541
f7667a1dde8e react to said signal.
hamidouk
parents: 538
diff changeset
   120
  if (this._hidden == false) {
f7667a1dde8e react to said signal.
hamidouk
parents: 538
diff changeset
   121
    this.selector.hide();
f7667a1dde8e react to said signal.
hamidouk
parents: 538
diff changeset
   122
    this._hidden = true;
777
96e89720ff18 added show/hide message. Removed reaction to annotateClick signal
hamidouk
parents: 651
diff changeset
   123
  }
96e89720ff18 added show/hide message. Removed reaction to annotateClick signal
hamidouk
parents: 651
diff changeset
   124
};
96e89720ff18 added show/hide message. Removed reaction to annotateClick signal
hamidouk
parents: 651
diff changeset
   125
96e89720ff18 added show/hide message. Removed reaction to annotateClick signal
hamidouk
parents: 651
diff changeset
   126
IriSP.AnnotationsWidget.prototype.show = function() {
96e89720ff18 added show/hide message. Removed reaction to annotateClick signal
hamidouk
parents: 651
diff changeset
   127
  if (this._hidden == true) {
541
f7667a1dde8e react to said signal.
hamidouk
parents: 538
diff changeset
   128
    this.selector.show();
f7667a1dde8e react to said signal.
hamidouk
parents: 538
diff changeset
   129
    this._hidden = false;
f7667a1dde8e react to said signal.
hamidouk
parents: 538
diff changeset
   130
  }
f7667a1dde8e react to said signal.
hamidouk
parents: 538
diff changeset
   131
};