src/js/widgets/tweetsWidget.js
branchtweet-widget
changeset 267 f84013fb19dc
child 268 576cc32f0688
equal deleted inserted replaced
266:1c83c4bba0ce 267:f84013fb19dc
       
     1 /* a widget that displays tweet - used in conjunction with the polemicWidget */
       
     2 
       
     3 IriSP.TweetsWidget = function(Popcorn, config, Serializer) {
       
     4   IriSP.Widget.call(this, Popcorn, config, Serializer);
       
     5   
       
     6 };
       
     7 
       
     8 
       
     9 IriSP.TweetsWidget.prototype = new IriSP.Widget();
       
    10 
       
    11 IriSP.TweetsWidget.prototype.displayTweet = function(annotation) {
       
    12 
       
    13     var title = annotation.content.title;
       
    14     var description = annotation.content.description;
       
    15     var keywords =  "" // FIXME;
       
    16     var begin = +annotation.begin;
       
    17     var end = +annotation.end;
       
    18     var duration = +this._serializer.currentMedia().meta["dc:duration"];
       
    19 
       
    20     this.selector.find(".Ldt-tweetContents").text(title);   
       
    21 };
       
    22 
       
    23 IriSP.TweetsWidget.prototype.draw = function() {
       
    24   var _this = this;
       
    25   
       
    26   var tweetMarkup = Mustache.to_html(IriSP.tweetWidget_template, {"share_template" : IriSP.share_template});
       
    27 	this.selector.append(tweetMarkup);
       
    28     
       
    29   this._Popcorn.listen("IriSP.PolemicTweet.click", IriSP.wrap(this, this.PolemicTweetClickHandler));
       
    30 };
       
    31 
       
    32 IriSP.TweetsWidget.prototype.PolemicTweetClickHandler = function(tweet_id) {  
       
    33   var index, annotation;
       
    34   for (index in this._serializer._data.annotations) {
       
    35     annotation = this._serializer._data.annotations[index];
       
    36     
       
    37     if (annotation.id === tweet_id)
       
    38       break;
       
    39   }
       
    40     
       
    41   if (annotation.id !== tweet_id)
       
    42       /* we haven't found it */
       
    43       return;
       
    44   
       
    45 
       
    46   this.displayTweet(annotation);
       
    47   
       
    48   var time = this._Popcorn.currentTime();
       
    49   this._Popcorn = this._Popcorn.code({ start : time + 0.1, end: time + 10, 
       
    50                                        onEnd: IriSP.wrap(this, this.clearTweet)});
       
    51   
       
    52   return;
       
    53 };