| author | hamidouk |
| Tue, 29 Nov 2011 14:34:30 +0100 | |
| branch | popcorn-port |
| changeset 350 | c637688bd680 |
| parent 298 | eccdc619ede3 |
| child 363 | 8d4b329836b6 |
| 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; |
|
|
278
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
7 |
this._timeoutId = undefined; |
| 277 | 8 |
}; |
9 |
||
10 |
||
11 |
IriSP.TweetsWidget.prototype = new IriSP.Widget(); |
|
12 |
||
13 |
||
14 |
IriSP.TweetsWidget.prototype.drawTweet = function(annotation) { |
|
15 |
|
|
| 285 | 16 |
var title = IriSP.formatTweet(annotation.content.title); |
| 277 | 17 |
var img = annotation.content.img.src; |
18 |
if (typeof(img) === "undefined" || img === "" || img === "None") { |
|
19 |
img = IriSP.widgetsDefaults.TweetsWidget.default_profile_picture; |
|
20 |
} |
|
|
293
314e6a13f841
tweetWidget : display better information, if available
hamidouk
parents:
285
diff
changeset
|
21 |
|
|
314e6a13f841
tweetWidget : display better information, if available
hamidouk
parents:
285
diff
changeset
|
22 |
var imageMarkup = Mustache.to_html("<img src='{{src}}' alt='user image'></img>", |
|
314e6a13f841
tweetWidget : display better information, if available
hamidouk
parents:
285
diff
changeset
|
23 |
{src : img}); |
| 277 | 24 |
|
|
293
314e6a13f841
tweetWidget : display better information, if available
hamidouk
parents:
285
diff
changeset
|
25 |
if (typeof(annotation.meta["dc:source"].content) !== "undefined") { |
|
314e6a13f841
tweetWidget : display better information, if available
hamidouk
parents:
285
diff
changeset
|
26 |
var tweetContents = JSON.parse(annotation.meta["dc:source"].content); |
|
314e6a13f841
tweetWidget : display better information, if available
hamidouk
parents:
285
diff
changeset
|
27 |
var creator = tweetContents.user.screen_name; |
|
314e6a13f841
tweetWidget : display better information, if available
hamidouk
parents:
285
diff
changeset
|
28 |
|
|
314e6a13f841
tweetWidget : display better information, if available
hamidouk
parents:
285
diff
changeset
|
29 |
imageMarkup = Mustache.to_html("<a href='http://twitter.com/{{creator}}'><img src='{{src}}' alt='user image'></img></a>", |
|
314e6a13f841
tweetWidget : display better information, if available
hamidouk
parents:
285
diff
changeset
|
30 |
{src : img, creator: creator}); |
|
314e6a13f841
tweetWidget : display better information, if available
hamidouk
parents:
285
diff
changeset
|
31 |
|
|
350
c637688bd680
tweetWidget : format the tweet date according to the locale.
hamidouk
parents:
298
diff
changeset
|
32 |
var formatted_date = new Date(tweetContents.created_at).toLocaleDateString(); |
|
c637688bd680
tweetWidget : format the tweet date according to the locale.
hamidouk
parents:
298
diff
changeset
|
33 |
title = Mustache.to_html(IriSP.rich_tweet_template, {contents : title, date : formatted_date}); |
|
293
314e6a13f841
tweetWidget : display better information, if available
hamidouk
parents:
285
diff
changeset
|
34 |
} |
| 277 | 35 |
|
| 285 | 36 |
this.selector.find(".Ldt-tweetContents").html(title); |
| 277 | 37 |
this.selector.find(".Ldt-tweetAvatar").html(imageMarkup); |
|
278
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
38 |
this.selector.show("blind", 250); |
| 277 | 39 |
}; |
40 |
||
41 |
IriSP.TweetsWidget.prototype.displayTweet = function(annotation) { |
|
42 |
if (this._displayingTweet === false) { |
|
43 |
this._displayingTweet = true; |
|
44 |
} else { |
|
45 |
window.clearTimeout(this._timeoutId); |
|
46 |
} |
|
47 |
||
48 |
this.drawTweet(annotation); |
|
49 |
||
50 |
var time = this._Popcorn.currentTime(); |
|
|
282
1001234e5e6e
added a var to configure the num of seconds to display the tweet.
hamidouk
parents:
278
diff
changeset
|
51 |
this._timeoutId = window.setTimeout(IriSP.wrap(this, this.clearPanel), IriSP.widgetsDefaults.TweetsWidget.tweet_display_period); |
| 277 | 52 |
}; |
53 |
||
54 |
||
55 |
IriSP.TweetsWidget.prototype.clearPanel = function() { |
|
56 |
this._displayingTweet = false; |
|
|
278
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
57 |
this._timeoutId = undefined; |
| 277 | 58 |
this.closePanel(); |
|
278
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
59 |
|
| 277 | 60 |
}; |
61 |
||
62 |
IriSP.TweetsWidget.prototype.closePanel = function() { |
|
|
278
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
63 |
if (this._timeoutId != undefined) { |
|
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
64 |
/* we're called from the "close window" link */ |
|
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
65 |
/* cancel the timeout */ |
|
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
66 |
window.clearTimeout(this._timeoutId); |
|
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
67 |
} |
|
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
68 |
|
|
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
69 |
this.selector.hide("blind", 400); |
|
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
70 |
|
| 277 | 71 |
}; |
72 |
||
73 |
IriSP.TweetsWidget.prototype.draw = function() { |
|
74 |
var _this = this; |
|
75 |
|
|
76 |
var tweetMarkup = Mustache.to_html(IriSP.tweetWidget_template, {"share_template" : IriSP.share_template}); |
|
77 |
this.selector.append(tweetMarkup); |
|
78 |
this.selector.hide(); |
|
|
278
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
79 |
this.selector.find(".Ldt-tweetWidgetMinimize").click(IriSP.wrap(this, this.closePanel)); |
| 277 | 80 |
|
81 |
this._Popcorn.listen("IriSP.PolemicTweet.click", IriSP.wrap(this, this.PolemicTweetClickHandler)); |
|
82 |
}; |
|
83 |
||
84 |
IriSP.TweetsWidget.prototype.PolemicTweetClickHandler = function(tweet_id) { |
|
85 |
var index, annotation; |
|
86 |
for (index in this._serializer._data.annotations) { |
|
87 |
annotation = this._serializer._data.annotations[index]; |
|
88 |
|
|
89 |
if (annotation.id === tweet_id) |
|
90 |
break; |
|
91 |
} |
|
92 |
|
|
93 |
if (annotation.id !== tweet_id) |
|
94 |
/* we haven't found it */ |
|
95 |
return; |
|
96 |
|
|
97 |
this.displayTweet(annotation); |
|
98 |
return; |
|
|
350
c637688bd680
tweetWidget : format the tweet date according to the locale.
hamidouk
parents:
298
diff
changeset
|
99 |
}; |