| author | hamidouk |
| Fri, 18 Nov 2011 14:56:38 +0100 | |
| branch | tweet-widget |
| changeset 277 | ff416475397a |
| parent 276 | 8a5a34ff1202 |
| child 278 | ff20c80c6845 |
| permissions | -rw-r--r-- |
| 277 | 1 |
/* a widget that displays tweet - used in conjunction with the polemicWidget */ |
2 |
||
3 |
IriSP.TweetsWidget = 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.TweetsWidget.prototype = new IriSP.Widget(); |
|
12 |
||
13 |
||
14 |
IriSP.TweetsWidget.prototype.drawTweet = function(annotation) { |
|
15 |
|
|
16 |
var title = annotation.content.title; |
|
17 |
var img = annotation.content.img.src; |
|
18 |
if (typeof(img) === "undefined" || img === "" || img === "None") { |
|
19 |
img = IriSP.widgetsDefaults.TweetsWidget.default_profile_picture; |
|
20 |
} |
|
21 |
|
|
22 |
var imageMarkup = Mustache.to_html("<img src='{{src}}' alt='avatar'></img>", |
|
23 |
{src : img}); |
|
24 |
||
25 |
this.selector.find(".Ldt-tweetContents").text(title); |
|
26 |
this.selector.find(".Ldt-tweetAvatar").html(imageMarkup); |
|
27 |
this.selector.show(50); |
|
28 |
}; |
|
29 |
||
30 |
IriSP.TweetsWidget.prototype.displayTweet = function(annotation) { |
|
31 |
if (this._displayingTweet === false) { |
|
32 |
this._displayingTweet = true; |
|
33 |
} else { |
|
34 |
window.clearTimeout(this._timeoutId); |
|
35 |
} |
|
36 |
||
37 |
this.drawTweet(annotation); |
|
38 |
||
39 |
var time = this._Popcorn.currentTime(); |
|
40 |
this._timeoutId = window.setTimeout(IriSP.wrap(this, this.clearPanel), 10000); |
|
41 |
}; |
|
42 |
||
43 |
||
44 |
IriSP.TweetsWidget.prototype.clearPanel = function() { |
|
45 |
this._displayingTweet = false; |
|
46 |
this.closePanel(); |
|
47 |
}; |
|
48 |
||
49 |
IriSP.TweetsWidget.prototype.closePanel = function() { |
|
50 |
if (this._displayingTweet) |
|
51 |
return; |
|
52 |
else { |
|
53 |
this.selector.hide(50); |
|
54 |
} |
|
55 |
}; |
|
56 |
||
57 |
IriSP.TweetsWidget.prototype.draw = function() { |
|
58 |
var _this = this; |
|
59 |
|
|
60 |
var tweetMarkup = Mustache.to_html(IriSP.tweetWidget_template, {"share_template" : IriSP.share_template}); |
|
61 |
this.selector.append(tweetMarkup); |
|
62 |
this.selector.hide(); |
|
63 |
|
|
64 |
this._Popcorn.listen("IriSP.PolemicTweet.click", IriSP.wrap(this, this.PolemicTweetClickHandler)); |
|
65 |
}; |
|
66 |
||
67 |
IriSP.TweetsWidget.prototype.PolemicTweetClickHandler = function(tweet_id) { |
|
68 |
var index, annotation; |
|
69 |
for (index in this._serializer._data.annotations) { |
|
70 |
annotation = this._serializer._data.annotations[index]; |
|
71 |
|
|
72 |
if (annotation.id === tweet_id) |
|
73 |
break; |
|
74 |
} |
|
75 |
|
|
76 |
if (annotation.id !== tweet_id) |
|
77 |
/* we haven't found it */ |
|
78 |
return; |
|
79 |
|
|
80 |
this.displayTweet(annotation); |
|
81 |
return; |
|
|
267
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
82 |
}; |