src/js/widgets/tweetsView.js
author hamidouk
Mon, 05 Dec 2011 15:43:54 +0100
branchcap-demo
changeset 406 0e9d82ea7271
child 411 d5d6e98a95d3
permissions -rw-r--r--
a specific widget to display the annotations for cap.
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
  var time = this._Popcorn.currentTime();  
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    33
  this._timeoutId = window.setTimeout(IriSP.wrap(this, this.clearPanel), IriSP.widgetsDefaults.TweetsWidget.tweet_display_period);
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
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    36
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    37
IriSP.TweetsView.prototype.clearPanel = function() {  
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    38
    this._displayingTweet = false;
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    39
    this._timeoutId = undefined;
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    40
    this.closePanel();
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
};
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    43
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    44
IriSP.TweetsView.prototype.closePanel = function() {
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    45
    if (this._timeoutId != undefined) {
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    46
      /* we're called from the "close window" link */
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    47
      /* cancel the timeout */
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    48
      window.clearTimeout(this._timeoutId);
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    49
      this._timeoutId = null;
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
    
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    52
    this.selector.hide("blind", 400);
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    53
    
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
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    56
/* cancel the timeout if the user clicks on the keep panel open button */
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    57
IriSP.TweetsView.prototype.keepPanel = function() {
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    58
    if (this._timeoutId != undefined) {
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    59
      /* we're called from the "close window" link */
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    60
      /* cancel the timeout */
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    61
      window.clearTimeout(this._timeoutId);
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    62
      this._timeoutId = null;
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    63
    }
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    64
};
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    65
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    66
IriSP.TweetsView.prototype.draw = function() {
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    67
  var _this = this;
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    68
  
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    69
  this.selector.append(Mustache.to_html(IriSP.polemicAnnotationView_template, {}));
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    70
  this.selector.hide();
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    71
  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
    72
};
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    73
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    74
IriSP.TweetsView.prototype.PolemicTweetClickHandler = function(tweet_id) {  
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    75
  var index, annotation;
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    76
  for (index in this._serializer._data.annotations) {
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    77
    annotation = this._serializer._data.annotations[index];
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    78
    
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    79
    if (annotation.id === tweet_id)
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    80
      break;
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    81
  }
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    82
    
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    83
  if (annotation.id !== tweet_id)
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    84
      /* we haven't found it */
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    85
      return;
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    86
  
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    87
  this.displayTweet(annotation);
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    88
  return;
0e9d82ea7271 a specific widget to display the annotations for cap.
hamidouk
parents:
diff changeset
    89
};