src/js/widgets/tweetsWidget.js
author hamidouk
Fri, 18 Nov 2011 14:33:24 +0100
branchtweet-widget
changeset 276 8a5a34ff1202
parent 275 a4d2dd99187b
child 277 ff416475397a
permissions -rw-r--r--
WIP - do not use in production ! refactoring the code to have a finite state machine (http://en.wikipedia.org/wiki/Finite_state_machine)
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);
276
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
     5
 
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
     6
  this._isDisplayingTweet = false;
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
     7
  this._ignoreClear = false;
267
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
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    10
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    11
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
    12
275
a4d2dd99187b WIP - do not use in production !
hamidouk
parents: 274
diff changeset
    13
276
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    14
IriSP.TweetsWidget.prototype.drawTweet = function(annotation) {
275
a4d2dd99187b WIP - do not use in production !
hamidouk
parents: 274
diff changeset
    15
    
267
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    16
    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
    17
    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
    18
    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
    19
      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
    20
    }
fe02d003c6c4 added support for a default profile picture in case it's not defined.
hamidouk
parents: 271
diff changeset
    21
    
268
576cc32f0688 added display over the tweeter's avatar.
hamidouk
parents: 267
diff changeset
    22
    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
    23
                                       {src : img});
fe02d003c6c4 added support for a default profile picture in case it's not defined.
hamidouk
parents: 271
diff changeset
    24
268
576cc32f0688 added display over the tweeter's avatar.
hamidouk
parents: 267
diff changeset
    25
    this.selector.find(".Ldt-tweetContents").text(title);
576cc32f0688 added display over the tweeter's avatar.
hamidouk
parents: 267
diff changeset
    26
    this.selector.find(".Ldt-tweetAvatar").html(imageMarkup);
271
41258988e132 made the tweetwidget appear and disappear.
hamidouk
parents: 268
diff changeset
    27
    this.selector.show(50);
275
a4d2dd99187b WIP - do not use in production !
hamidouk
parents: 274
diff changeset
    28
};
a4d2dd99187b WIP - do not use in production !
hamidouk
parents: 274
diff changeset
    29
276
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    30
IriSP.TweetsWidget.prototype.displayTweet = function(annotation) {
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    31
  if (this._isDisplayingTweet === false) {
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    32
    this._isDisplayingTweet = true;
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    33
  } else { /* we're already displaying a tweet */
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    34
    this._ignoreClear = true;
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    35
  }
275
a4d2dd99187b WIP - do not use in production !
hamidouk
parents: 274
diff changeset
    36
  
276
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    37
  this.drawTweet(annotation);
275
a4d2dd99187b WIP - do not use in production !
hamidouk
parents: 274
diff changeset
    38
276
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    39
  var time = this._Popcorn.currentTime();  
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    40
  // this._Popcorn.exec(time + 10, IriSP.wrap(this, this.clearPanel)); 
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    41
  window.setTimeout(IriSP.wrap(this, this.clearPanel), 10000);
275
a4d2dd99187b WIP - do not use in production !
hamidouk
parents: 274
diff changeset
    42
};
a4d2dd99187b WIP - do not use in production !
hamidouk
parents: 274
diff changeset
    43
276
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    44
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    45
IriSP.TweetsWidget.prototype.clearPanel = function() {
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    46
  debugger;
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    47
  if (this._ignoreClear === true) {
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    48
    this._ignoreClear = false;
275
a4d2dd99187b WIP - do not use in production !
hamidouk
parents: 274
diff changeset
    49
    return;
276
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    50
  } else {
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    51
    /* clear the display */
275
a4d2dd99187b WIP - do not use in production !
hamidouk
parents: 274
diff changeset
    52
    this.closePanel();
276
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    53
    this._isDisplayingTweet = false;    
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    54
    this._ignoreClear = false;    
275
a4d2dd99187b WIP - do not use in production !
hamidouk
parents: 274
diff changeset
    55
  }
a4d2dd99187b WIP - do not use in production !
hamidouk
parents: 274
diff changeset
    56
};
a4d2dd99187b WIP - do not use in production !
hamidouk
parents: 274
diff changeset
    57
a4d2dd99187b WIP - do not use in production !
hamidouk
parents: 274
diff changeset
    58
IriSP.TweetsWidget.prototype.closePanel = function() {
a4d2dd99187b WIP - do not use in production !
hamidouk
parents: 274
diff changeset
    59
  if (this._displayingTweet)
a4d2dd99187b WIP - do not use in production !
hamidouk
parents: 274
diff changeset
    60
    return;
a4d2dd99187b WIP - do not use in production !
hamidouk
parents: 274
diff changeset
    61
  else {
a4d2dd99187b WIP - do not use in production !
hamidouk
parents: 274
diff changeset
    62
    this.selector.hide(50);
a4d2dd99187b WIP - do not use in production !
hamidouk
parents: 274
diff changeset
    63
  }
267
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    64
};
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    65
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    66
IriSP.TweetsWidget.prototype.draw = function() {
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    67
  var _this = this;
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    68
  
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    69
  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
    70
	this.selector.append(tweetMarkup);
271
41258988e132 made the tweetwidget appear and disappear.
hamidouk
parents: 268
diff changeset
    71
  this.selector.hide();
41258988e132 made the tweetwidget appear and disappear.
hamidouk
parents: 268
diff changeset
    72
  
267
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    73
  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
    74
};
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    75
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    76
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
    77
  var index, annotation;
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    78
  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
    79
    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
    80
    
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    81
    if (annotation.id === tweet_id)
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    82
      break;
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    83
  }
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    84
    
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    85
  if (annotation.id !== tweet_id)
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    86
      /* we haven't found it */
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    87
      return;
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    88
  
276
8a5a34ff1202 WIP - do not use in production !
hamidouk
parents: 275
diff changeset
    89
  this.displayTweet(annotation);
267
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    90
  return;
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    91
};