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