src/widgets/Annotation.js
branchnew-model
changeset 876 03967b6ada7c
child 880 4c7b33bf2795
equal deleted inserted replaced
875:43629caa77bc 876:03967b6ada7c
       
     1 // TODO: Open share links in a small window
       
     2 
       
     3 IriSP.Widgets.Annotation = function(player, config) {
       
     4     IriSP.Widgets.Widget.call(this, player, config);
       
     5     this.lastAnnotation = false;
       
     6 };
       
     7 
       
     8 IriSP.Widgets.Annotation.prototype = new IriSP.Widgets.Widget();
       
     9 
       
    10 IriSP.Widgets.Annotation.prototype.messages = {
       
    11     "fr": {
       
    12         share_on: "Partager sur",
       
    13         watching: "Je regarde ",
       
    14         on_site: " sur ",
       
    15         tags: "Mots-clés :"
       
    16     },
       
    17     "en": {
       
    18         share_on: "Share on",
       
    19         watching: "I'm watching ",
       
    20         on_site: " on ",
       
    21         tags: "Keywords:"
       
    22     }
       
    23 }
       
    24 
       
    25 IriSP.Widgets.Annotation.prototype.template =
       
    26     '<div class="Ldt-Annotation-Widget {{#show_top_border}}Ldt-Annotation-ShowTop{{/show_top_border}}">'
       
    27     + '<div class="Ldt-Annotation-Inner"></div></div>';
       
    28 
       
    29 IriSP.Widgets.Annotation.prototype.defaults = {
       
    30     annotation_type : "chap",
       
    31     show_top_border : false,
       
    32     site_name : "Lignes de Temps"
       
    33 }
       
    34 
       
    35 IriSP.Widgets.Annotation.prototype.draw = function() {
       
    36     this.renderTemplate();
       
    37     this.bindPopcorn("timeupdate","onTimeupdate");
       
    38     this.onTimeupdate();
       
    39 }
       
    40 
       
    41 IriSP.Widgets.Annotation.prototype.onTimeupdate = function() {
       
    42     var _time = Math.floor(this.player.popcorn.currentTime() * 1000),
       
    43         _list = this.getWidgetAnnotations().filter(function(_annotation) {
       
    44             return _annotation.begin <= _time && _annotation.end > _time;
       
    45         });
       
    46     if (_list.length) {
       
    47         if (_list[0].id !== this.lastAnnotation) {
       
    48             this.drawAnnotation(_list[0]);
       
    49         }
       
    50     }
       
    51     else {
       
    52         this.$.find('.Ldt-Annotation-Inner').html('');
       
    53     }
       
    54 }
       
    55 
       
    56 IriSP.Widgets.Annotation.prototype.drawAnnotation = function(_annotation) {
       
    57     this.lastAnnotation = _annotation.id;
       
    58     console.log(_annotation);
       
    59     var _url = (typeof _annotation.url !== "undefined" 
       
    60             ? _annotation.url
       
    61             : (document.location.href.replace(/#.*$/,'') + '#id='  + _annotation.namespacedId.name)),
       
    62         _text = this.l10n.watching + _annotation.title + (this.site_name ? this.l10n.on_site + this.site_name : ''),
       
    63         _tmpl = '<div class="Ldt-Annotation-ShareIcons">'
       
    64             + '<a href="{{fb_url}}" target="_blank" class="Ldt-Annotation-Share Ldt-Annotation-Fb" title="{{l10n.share_on}} Facebook"></a>'
       
    65             + '<a href="{{twitter_url}}" target="_blank" class="Ldt-Annotation-Share Ldt-Annotation-Twitter" title="{{l10n.share_on}} Twitter"></a>'
       
    66             + '<a href="{{gplus_url}}" target="_blank" class="Ldt-Annotation-Share Ldt-Annotation-Gplus" title="{{l10n.share_on}} Google+"></a>'
       
    67             + '</div>'
       
    68             + '<h3><span class="Ldt-Annotation-Title">{{title}}</span> ( <span class="Ldt-Annotation-Time">{{begin}} - {{end}}</span> )</h3>'
       
    69             + '<p class="Ldt-Annotation-Description">{{description}}</p>'
       
    70             + '{{#tags.length}}<ul class="Ldt-Annotation-Tags"><li class="Ldt-Annotation-TagLabel">{{l10n.tags}}</li>{{#tags}}<li>{{.}}</li>{{/tags}}</ul>{{/tags.length}}',
       
    71         _attr = {
       
    72             title: _annotation.title,
       
    73             description: _annotation.description,
       
    74             begin: _annotation.begin.toString(),
       
    75             end: _annotation.end.toString(),
       
    76             tags: _annotation.getTagTexts(),
       
    77             l10n: this.l10n
       
    78         }
       
    79     _attr.fb_url = "http://www.facebook.com/share.php?" + IriSP.jQuery.param({ u: _url, t: _text });
       
    80     _attr.twitter_url = "https://twitter.com/intent/tweet?" + IriSP.jQuery.param({ url: _url, text: _text });
       
    81     _attr.gplus_url = "https://plusone.google.com/_/+1/confirm?" + IriSP.jQuery.param({ url: _url, title: _text });
       
    82     this.$.find('.Ldt-Annotation-Inner').html(Mustache.to_html(_tmpl, _attr));
       
    83 }