| author | hamidouk |
| Fri, 18 Nov 2011 12:12:28 +0100 | |
| branch | tweet-widget |
| changeset 275 | a4d2dd99187b |
| parent 274 | fe02d003c6c4 |
| child 276 | 8a5a34ff1202 |
| permissions | -rw-r--r-- |
|
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); |
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
5 |
|
| 275 | 6 |
/* this is a bit complex : we use a list to queue the tweets to display, for |
7 |
two reasons : |
|
8 |
- first, We want the pane to retract when there's no tweets to see - it's doable |
|
9 |
but it would lead for race conditions - imagine that the user clicks on a tweet |
|
10 |
and wants it displayed, it would display in an empty pane |
|
11 |
- second case, the pane displays a tweet and the user clicks before that the tweet |
|
12 |
has finished displaying - he wants his tweet to be displayed now, not after the |
|
13 |
previous tweet has finished. |
|
14 |
|
|
15 |
So, we queue every tweet in a message queue, which gets consumed at every call of |
|
16 |
displayTweet. |
|
17 |
*/ |
|
18 |
this._messageQueue = []; |
|
19 |
|
|
20 |
/* a variable for an edge case : when the user has clicked on a tweet and clicks on another |
|
21 |
one before that the first has been cleared. In this case, the second one will be displayed |
|
22 |
but cleared before its time. |
|
23 |
*/ |
|
24 |
this._tweetClearedBeforeEnd = false; |
|
|
267
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
25 |
}; |
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
26 |
|
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
27 |
|
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
28 |
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
|
29 |
|
| 275 | 30 |
|
31 |
IriSP.TweetsWidget.prototype.displayTweet = function(annotation) { |
|
32 |
|
|
|
267
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
33 |
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
|
34 |
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
|
35 |
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
|
36 |
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
|
37 |
} |
|
fe02d003c6c4
added support for a default profile picture in case it's not defined.
hamidouk
parents:
271
diff
changeset
|
38 |
|
| 268 | 39 |
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
|
40 |
{src : img}); |
|
fe02d003c6c4
added support for a default profile picture in case it's not defined.
hamidouk
parents:
271
diff
changeset
|
41 |
|
| 268 | 42 |
this.selector.find(".Ldt-tweetContents").text(title); |
43 |
this.selector.find(".Ldt-tweetAvatar").html(imageMarkup); |
|
| 271 | 44 |
this.selector.show(50); |
| 275 | 45 |
}; |
46 |
||
47 |
IriSP.TweetsWidget.prototype.pushQueue = function(annotation) { |
|
48 |
this._messageQueue.push(annotation); |
|
49 |
|
|
50 |
// we're pushing in the queue before another tweet has been |
|
51 |
// displayed |
|
52 |
if (this._messageQueue.length != 0) |
|
53 |
this._tweetClearedBeforeEnd = true; |
|
54 |
|
|
55 |
var annotation = this._messageQueue[0]; |
|
56 |
|
|
57 |
this.displayTweet(annotation); |
|
58 |
||
59 |
var time = this._Popcorn.currentTime(); |
|
60 |
this._Popcorn = this._Popcorn.code({ start : time + 0.1, end: time + 10, |
|
61 |
onEnd: IriSP.wrap(this, this.clearQueue)}); |
|
62 |
||
63 |
}; |
|
64 |
||
65 |
/* this does essentially the same job than handleQueue, except that it's only |
|
66 |
called by handleQueue to cleanup after a tweet. */ |
|
67 |
IriSP.TweetsWidget.prototype.clearQueue = function() { |
|
68 |
var annotation = this._messageQueue.shift(); |
|
69 |
|
|
70 |
if( this._tweetClearedBeforeEnd === true) { |
|
71 |
this._tweetClearedBeforeEnd; |
|
72 |
return; |
|
73 |
} |
|
74 |
|
|
75 |
if (this._messageQueue === []) { |
|
76 |
this.closePanel(); |
|
77 |
} |
|
78 |
}; |
|
79 |
||
80 |
IriSP.TweetsWidget.prototype.closePanel = function() { |
|
81 |
if (this._displayingTweet) |
|
82 |
return; |
|
83 |
else { |
|
84 |
this.selector.hide(50); |
|
85 |
} |
|
|
267
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
86 |
}; |
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
87 |
|
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
88 |
IriSP.TweetsWidget.prototype.draw = function() { |
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
89 |
var _this = this; |
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
90 |
|
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
91 |
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
|
92 |
this.selector.append(tweetMarkup); |
| 271 | 93 |
this.selector.hide(); |
94 |
|
|
|
267
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
95 |
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
|
96 |
}; |
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
97 |
|
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
98 |
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
|
99 |
var index, annotation; |
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
100 |
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
|
101 |
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
|
102 |
|
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
103 |
if (annotation.id === tweet_id) |
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
104 |
break; |
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
105 |
} |
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
106 |
|
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
107 |
if (annotation.id !== tweet_id) |
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
108 |
/* we haven't found it */ |
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
109 |
return; |
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
110 |
|
| 275 | 111 |
this.pushQueue(annotation); |
112 |
|
|
|
267
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
113 |
return; |
|
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
114 |
}; |