src/js/widgets/tweetsView.js
branchcap-demo
changeset 406 0e9d82ea7271
child 411 d5d6e98a95d3
equal deleted inserted replaced
405:e1ed0fdbbec9 406:0e9d82ea7271
       
     1 /* a widget that displays tweet - used in conjunction with the polemicWidget */
       
     2 
       
     3 IriSP.TweetsView = function(Popcorn, config, Serializer) {
       
     4   IriSP.Widget.call(this, Popcorn, config, Serializer);
       
     5 
       
     6   this._displayingTweet = false;
       
     7   this._timeoutId = undefined;  
       
     8 };
       
     9 
       
    10 
       
    11 IriSP.TweetsView.prototype = new IriSP.Widget();
       
    12 
       
    13 
       
    14 IriSP.TweetsView.prototype.drawTweet = function(annotation) {
       
    15     var title = IriSP.formatTweet(annotation.content.title);
       
    16     var desc = IriSP.formatTweet(annotation.content.description);
       
    17    
       
    18     this.selector.find(".Ldt-SaTitle").html(title);
       
    19     this.selector.find(".Ldt-SaDescription").html(desc);
       
    20     this.selector.show("blind", 250); 
       
    21 };
       
    22 
       
    23 IriSP.TweetsView.prototype.displayTweet = function(annotation) {
       
    24   if (this._displayingTweet === false) {
       
    25     this._displayingTweet = true;
       
    26   } else {
       
    27     window.clearTimeout(this._timeoutId);
       
    28   }
       
    29 
       
    30   this.drawTweet(annotation);
       
    31 
       
    32   var time = this._Popcorn.currentTime();  
       
    33   this._timeoutId = window.setTimeout(IriSP.wrap(this, this.clearPanel), IriSP.widgetsDefaults.TweetsWidget.tweet_display_period);
       
    34 };
       
    35 
       
    36 
       
    37 IriSP.TweetsView.prototype.clearPanel = function() {  
       
    38     this._displayingTweet = false;
       
    39     this._timeoutId = undefined;
       
    40     this.closePanel();
       
    41     
       
    42 };
       
    43 
       
    44 IriSP.TweetsView.prototype.closePanel = function() {
       
    45     if (this._timeoutId != undefined) {
       
    46       /* we're called from the "close window" link */
       
    47       /* cancel the timeout */
       
    48       window.clearTimeout(this._timeoutId);
       
    49       this._timeoutId = null;
       
    50     }
       
    51     
       
    52     this.selector.hide("blind", 400);
       
    53     
       
    54 };
       
    55 
       
    56 /* cancel the timeout if the user clicks on the keep panel open button */
       
    57 IriSP.TweetsView.prototype.keepPanel = function() {
       
    58     if (this._timeoutId != undefined) {
       
    59       /* we're called from the "close window" link */
       
    60       /* cancel the timeout */
       
    61       window.clearTimeout(this._timeoutId);
       
    62       this._timeoutId = null;
       
    63     }
       
    64 };
       
    65 
       
    66 IriSP.TweetsView.prototype.draw = function() {
       
    67   var _this = this;
       
    68   
       
    69   this.selector.append(Mustache.to_html(IriSP.polemicAnnotationView_template, {}));
       
    70   this.selector.hide();
       
    71   this._Popcorn.listen("IriSP.PolemicTweet.click", IriSP.wrap(this, this.PolemicTweetClickHandler));
       
    72 };
       
    73 
       
    74 IriSP.TweetsView.prototype.PolemicTweetClickHandler = function(tweet_id) {  
       
    75   var index, annotation;
       
    76   for (index in this._serializer._data.annotations) {
       
    77     annotation = this._serializer._data.annotations[index];
       
    78     
       
    79     if (annotation.id === tweet_id)
       
    80       break;
       
    81   }
       
    82     
       
    83   if (annotation.id !== tweet_id)
       
    84       /* we haven't found it */
       
    85       return;
       
    86   
       
    87   this.displayTweet(annotation);
       
    88   return;
       
    89 };