src/js/widgets/tweetsView.js
branchcap-demo
changeset 406 0e9d82ea7271
child 411 d5d6e98a95d3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/js/widgets/tweetsView.js	Mon Dec 05 15:43:54 2011 +0100
@@ -0,0 +1,89 @@
+/* a widget that displays tweet - used in conjunction with the polemicWidget */
+
+IriSP.TweetsView = function(Popcorn, config, Serializer) {
+  IriSP.Widget.call(this, Popcorn, config, Serializer);
+
+  this._displayingTweet = false;
+  this._timeoutId = undefined;  
+};
+
+
+IriSP.TweetsView.prototype = new IriSP.Widget();
+
+
+IriSP.TweetsView.prototype.drawTweet = function(annotation) {
+    var title = IriSP.formatTweet(annotation.content.title);
+    var desc = IriSP.formatTweet(annotation.content.description);
+   
+    this.selector.find(".Ldt-SaTitle").html(title);
+    this.selector.find(".Ldt-SaDescription").html(desc);
+    this.selector.show("blind", 250); 
+};
+
+IriSP.TweetsView.prototype.displayTweet = function(annotation) {
+  if (this._displayingTweet === false) {
+    this._displayingTweet = true;
+  } else {
+    window.clearTimeout(this._timeoutId);
+  }
+
+  this.drawTweet(annotation);
+
+  var time = this._Popcorn.currentTime();  
+  this._timeoutId = window.setTimeout(IriSP.wrap(this, this.clearPanel), IriSP.widgetsDefaults.TweetsWidget.tweet_display_period);
+};
+
+
+IriSP.TweetsView.prototype.clearPanel = function() {  
+    this._displayingTweet = false;
+    this._timeoutId = undefined;
+    this.closePanel();
+    
+};
+
+IriSP.TweetsView.prototype.closePanel = function() {
+    if (this._timeoutId != undefined) {
+      /* we're called from the "close window" link */
+      /* cancel the timeout */
+      window.clearTimeout(this._timeoutId);
+      this._timeoutId = null;
+    }
+    
+    this.selector.hide("blind", 400);
+    
+};
+
+/* cancel the timeout if the user clicks on the keep panel open button */
+IriSP.TweetsView.prototype.keepPanel = function() {
+    if (this._timeoutId != undefined) {
+      /* we're called from the "close window" link */
+      /* cancel the timeout */
+      window.clearTimeout(this._timeoutId);
+      this._timeoutId = null;
+    }
+};
+
+IriSP.TweetsView.prototype.draw = function() {
+  var _this = this;
+  
+  this.selector.append(Mustache.to_html(IriSP.polemicAnnotationView_template, {}));
+  this.selector.hide();
+  this._Popcorn.listen("IriSP.PolemicTweet.click", IriSP.wrap(this, this.PolemicTweetClickHandler));
+};
+
+IriSP.TweetsView.prototype.PolemicTweetClickHandler = function(tweet_id) {  
+  var index, annotation;
+  for (index in this._serializer._data.annotations) {
+    annotation = this._serializer._data.annotations[index];
+    
+    if (annotation.id === tweet_id)
+      break;
+  }
+    
+  if (annotation.id !== tweet_id)
+      /* we haven't found it */
+      return;
+  
+  this.displayTweet(annotation);
+  return;
+};