src/js/widgets/tweetsWidget.js
author hamidouk
Fri, 18 Nov 2011 14:56:38 +0100
branchtweet-widget
changeset 277 ff416475397a
parent 276 8a5a34ff1202
child 278 ff20c80c6845
permissions -rw-r--r--
fixed the bug with a clearTimeout.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
277
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
     1
/* a widget that displays tweet - used in conjunction with the polemicWidget */
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
     2
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
     3
IriSP.TweetsWidget = function(Popcorn, config, Serializer) {
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
     4
  IriSP.Widget.call(this, Popcorn, config, Serializer);
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
     5
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
     6
  this._displayingTweet = false;
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
     7
  this._timeoutId = undefined;
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
     8
};
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
     9
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    10
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    11
IriSP.TweetsWidget.prototype = new IriSP.Widget();
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    12
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    13
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    14
IriSP.TweetsWidget.prototype.drawTweet = function(annotation) {
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    15
    
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    16
    var title = annotation.content.title;
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    17
    var img = annotation.content.img.src;
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    18
    if (typeof(img) === "undefined" || img === "" || img === "None") {
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    19
      img = IriSP.widgetsDefaults.TweetsWidget.default_profile_picture;
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    20
    }
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    21
    
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    22
    var imageMarkup = Mustache.to_html("<img src='{{src}}' alt='avatar'></img>", 
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    23
                                       {src : img});
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    24
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    25
    this.selector.find(".Ldt-tweetContents").text(title);
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    26
    this.selector.find(".Ldt-tweetAvatar").html(imageMarkup);
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    27
    this.selector.show(50);
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    28
};
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    29
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    30
IriSP.TweetsWidget.prototype.displayTweet = function(annotation) {
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    31
  if (this._displayingTweet === false) {
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    32
    this._displayingTweet = true;
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    33
  } else {
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    34
    window.clearTimeout(this._timeoutId);
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    35
  }
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    36
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    37
  this.drawTweet(annotation);
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    38
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    39
  var time = this._Popcorn.currentTime();  
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    40
  this._timeoutId = window.setTimeout(IriSP.wrap(this, this.clearPanel), 10000);
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    41
};
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    42
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    43
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    44
IriSP.TweetsWidget.prototype.clearPanel = function() {  
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    45
    this._displayingTweet = false;
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    46
    this.closePanel();
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    47
};
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    48
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    49
IriSP.TweetsWidget.prototype.closePanel = function() {
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    50
  if (this._displayingTweet)
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    51
    return;
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    52
  else {
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    53
    this.selector.hide(50);
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    54
  }
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    55
};
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    56
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    57
IriSP.TweetsWidget.prototype.draw = function() {
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    58
  var _this = this;
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    59
  
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    60
  var tweetMarkup = Mustache.to_html(IriSP.tweetWidget_template, {"share_template" : IriSP.share_template});
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    61
  this.selector.append(tweetMarkup);
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    62
  this.selector.hide();
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    63
  
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    64
  this._Popcorn.listen("IriSP.PolemicTweet.click", IriSP.wrap(this, this.PolemicTweetClickHandler));
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    65
};
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    66
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    67
IriSP.TweetsWidget.prototype.PolemicTweetClickHandler = function(tweet_id) {  
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    68
  var index, annotation;
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    69
  for (index in this._serializer._data.annotations) {
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    70
    annotation = this._serializer._data.annotations[index];
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    71
    
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    72
    if (annotation.id === tweet_id)
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    73
      break;
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    74
  }
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    75
    
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    76
  if (annotation.id !== tweet_id)
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    77
      /* we haven't found it */
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    78
      return;
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    79
  
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    80
  this.displayTweet(annotation);
ff416475397a fixed the bug with a clearTimeout.
hamidouk
parents: 276
diff changeset
    81
  return;
267
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    82
};