src/js/widgets/tweetsView.js
author hamidouk
Mon, 05 Dec 2011 15:54:09 +0100
branchcap-demo
changeset 411 d5d6e98a95d3
parent 406 0e9d82ea7271
permissions -rw-r--r--
don't hide the widget.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
406
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
     1
/* a widget that displays tweet - used in conjunction with the polemicWidget */
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
     2
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
     3
IriSP.TweetsView = function(Popcorn, config, Serializer) {
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
     4
  IriSP.Widget.call(this, Popcorn, config, Serializer);
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
     5
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
     6
  this._displayingTweet = false;
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
     7
  this._timeoutId = undefined;  
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
     8
};
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
     9
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    10
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    11
IriSP.TweetsView.prototype = new IriSP.Widget();
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    12
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    13
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    14
IriSP.TweetsView.prototype.drawTweet = function(annotation) {
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    15
    var title = IriSP.formatTweet(annotation.content.title);
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    16
    var desc = IriSP.formatTweet(annotation.content.description);
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    17
   
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    18
    this.selector.find(".Ldt-SaTitle").html(title);
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    19
    this.selector.find(".Ldt-SaDescription").html(desc);
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    20
    this.selector.show("blind", 250); 
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    21
};
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    22
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    23
IriSP.TweetsView.prototype.displayTweet = function(annotation) {
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    24
  if (this._displayingTweet === false) {
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    25
    this._displayingTweet = true;
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    26
  } else {
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    27
    window.clearTimeout(this._timeoutId);
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    28
  }
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    29
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    30
  this.drawTweet(annotation);
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    31
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    32
};
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    33
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    34
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    35
IriSP.TweetsView.prototype.draw = function() {
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    36
  var _this = this;
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    37
  
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    38
  this.selector.append(Mustache.to_html(IriSP.polemicAnnotationView_template, {}));
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    39
  this._Popcorn.listen("IriSP.PolemicTweet.click", IriSP.wrap(this, this.PolemicTweetClickHandler));
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    40
};
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    41
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    42
IriSP.TweetsView.prototype.PolemicTweetClickHandler = function(tweet_id) {  
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    43
  var index, annotation;
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    44
  for (index in this._serializer._data.annotations) {
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    45
    annotation = this._serializer._data.annotations[index];
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    46
    
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    47
    if (annotation.id === tweet_id)
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    48
      break;
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    49
  }
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    50
    
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    51
  if (annotation.id !== tweet_id)
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    52
      /* we haven't found it */
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    53
      return;
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    54
  
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    55
  this.displayTweet(annotation);
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    56
  return;
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    57
};