src/js/widgets/tweetsWidget.js
author hamidouk
Fri, 18 Nov 2011 11:06:55 +0100
branchtweet-widget
changeset 274 fe02d003c6c4
parent 271 41258988e132
child 275 a4d2dd99187b
permissions -rw-r--r--
added support for a default profile picture in case it's not defined.
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;
274
fe02d003c6c4 added support for a default profile picture in case it's not defined.
hamidouk
parents: 271
diff changeset
    13
    var img = annotation.content.img.src;
fe02d003c6c4 added support for a default profile picture in case it's not defined.
hamidouk
parents: 271
diff changeset
    14
    if (typeof(img) === "undefined" || img === "" || img === "None") {
fe02d003c6c4 added support for a default profile picture in case it's not defined.
hamidouk
parents: 271
diff changeset
    15
      img = IriSP.widgetsDefaults.TweetsWidget.default_profile_picture;
fe02d003c6c4 added support for a default profile picture in case it's not defined.
hamidouk
parents: 271
diff changeset
    16
    }
fe02d003c6c4 added support for a default profile picture in case it's not defined.
hamidouk
parents: 271
diff changeset
    17
    
268
576cc32f0688 added display over the tweeter's avatar.
hamidouk
parents: 267
diff changeset
    18
    var imageMarkup = Mustache.to_html("<img src='{{src}}' alt='avatar'></img>", 
274
fe02d003c6c4 added support for a default profile picture in case it's not defined.
hamidouk
parents: 271
diff changeset
    19
                                       {src : img});
fe02d003c6c4 added support for a default profile picture in case it's not defined.
hamidouk
parents: 271
diff changeset
    20
268
576cc32f0688 added display over the tweeter's avatar.
hamidouk
parents: 267
diff changeset
    21
    this.selector.find(".Ldt-tweetContents").text(title);
576cc32f0688 added display over the tweeter's avatar.
hamidouk
parents: 267
diff changeset
    22
    this.selector.find(".Ldt-tweetAvatar").html(imageMarkup);
271
41258988e132 made the tweetwidget appear and disappear.
hamidouk
parents: 268
diff changeset
    23
    this.selector.show(50);
41258988e132 made the tweetwidget appear and disappear.
hamidouk
parents: 268
diff changeset
    24
    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
    25
};
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    26
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    27
IriSP.TweetsWidget.prototype.draw = function() {
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    28
  var _this = this;
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
  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
    31
	this.selector.append(tweetMarkup);
271
41258988e132 made the tweetwidget appear and disappear.
hamidouk
parents: 268
diff changeset
    32
  this.selector.hide();
41258988e132 made the tweetwidget appear and disappear.
hamidouk
parents: 268
diff changeset
    33
  
267
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    34
  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
    35
};
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    36
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    37
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
    38
  var index, annotation;
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    39
  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
    40
    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
    41
    
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    42
    if (annotation.id === tweet_id)
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    43
      break;
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
    
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    46
  if (annotation.id !== tweet_id)
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    47
      /* we haven't found it */
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    48
      return;
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    49
  
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
  this.displayTweet(annotation);
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    52
  
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    53
  var time = this._Popcorn.currentTime();
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    54
  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
    55
                                       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
    56
  
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    57
  return;
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    58
};