src/js/widgets/tweetsWidget.js
author hamidouk
Thu, 17 Nov 2011 17:34:13 +0100
branchtweet-widget
changeset 271 41258988e132
parent 268 576cc32f0688
child 274 fe02d003c6c4
permissions -rw-r--r--
made the tweetwidget appear and disappear.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
267
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
     1
/* a widget that displays tweet - used in conjunction with the polemicWidget */
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
     2
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
     3
IriSP.TweetsWidget = function(Popcorn, config, Serializer) {
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
     4
  IriSP.Widget.call(this, Popcorn, config, Serializer);
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
     5
  
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
     6
};
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
     7
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
     8
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
     9
IriSP.TweetsWidget.prototype = new IriSP.Widget();
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    10
271
41258988e132 made the tweetwidget appear and disappear.
hamidouk
parents: 268
diff changeset
    11
IriSP.TweetsWidget.prototype.displayTweet = function(annotation) {    
267
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    12
    var title = annotation.content.title;
268
576cc32f0688 added display over the tweeter's avatar.
hamidouk
parents: 267
diff changeset
    13
    var imageMarkup = Mustache.to_html("<img src='{{src}}' alt='avatar'></img>", 
576cc32f0688 added display over the tweeter's avatar.
hamidouk
parents: 267
diff changeset
    14
                                       {src : annotation.content.img.src});
576cc32f0688 added display over the tweeter's avatar.
hamidouk
parents: 267
diff changeset
    15
    this.selector.find(".Ldt-tweetContents").text(title);
576cc32f0688 added display over the tweeter's avatar.
hamidouk
parents: 267
diff changeset
    16
    this.selector.find(".Ldt-tweetAvatar").html(imageMarkup);
271
41258988e132 made the tweetwidget appear and disappear.
hamidouk
parents: 268
diff changeset
    17
    this.selector.show(50);
41258988e132 made the tweetwidget appear and disappear.
hamidouk
parents: 268
diff changeset
    18
    window.setTimeout(IriSP.wrap(this, function() { this.selector.hide(50) }), 10000);
267
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    19
};
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    20
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    21
IriSP.TweetsWidget.prototype.draw = function() {
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    22
  var _this = this;
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    23
  
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    24
  var tweetMarkup = Mustache.to_html(IriSP.tweetWidget_template, {"share_template" : IriSP.share_template});
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    25
	this.selector.append(tweetMarkup);
271
41258988e132 made the tweetwidget appear and disappear.
hamidouk
parents: 268
diff changeset
    26
  this.selector.hide();
41258988e132 made the tweetwidget appear and disappear.
hamidouk
parents: 268
diff changeset
    27
  
267
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    28
  this._Popcorn.listen("IriSP.PolemicTweet.click", IriSP.wrap(this, this.PolemicTweetClickHandler));
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    29
};
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    30
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    31
IriSP.TweetsWidget.prototype.PolemicTweetClickHandler = function(tweet_id) {  
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    32
  var index, annotation;
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    33
  for (index in this._serializer._data.annotations) {
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    34
    annotation = this._serializer._data.annotations[index];
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    35
    
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    36
    if (annotation.id === tweet_id)
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    37
      break;
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    38
  }
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    39
    
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    40
  if (annotation.id !== tweet_id)
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    41
      /* we haven't found it */
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    42
      return;
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    43
  
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    44
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    45
  this.displayTweet(annotation);
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    46
  
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    47
  var time = this._Popcorn.currentTime();
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    48
  this._Popcorn = this._Popcorn.code({ start : time + 0.1, end: time + 10, 
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    49
                                       onEnd: IriSP.wrap(this, this.clearTweet)});
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    50
  
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    51
  return;
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    52
};