| author | hamidouk |
| Mon, 05 Dec 2011 11:28:43 +0100 | |
| branch | popcorn-port |
| changeset 398 | d1883378b822 |
| parent 378 | 110311d59b2f |
| child 541 | f7667a1dde8e |
| 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 |
|
|
363
8d4b329836b6
converted the tweet widget to use the new template engine. removed a template of
hamidouk
parents:
350
diff
changeset
|
22 |
var imageMarkup = IriSP.templToHTML("<img src='{{src}}' alt='user image'></img>", |
|
293
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; |
| 367 | 28 |
var real_name = tweetContents.user.name; |
29 |
||
|
363
8d4b329836b6
converted the tweet widget to use the new template engine. removed a template of
hamidouk
parents:
350
diff
changeset
|
30 |
imageMarkup = IriSP.templToHTML("<a href='http://twitter.com/{{creator}}'><img src='{{src}}' alt='user image'></img></a>", |
|
293
314e6a13f841
tweetWidget : display better information, if available
hamidouk
parents:
285
diff
changeset
|
31 |
{src : img, creator: creator}); |
|
314e6a13f841
tweetWidget : display better information, if available
hamidouk
parents:
285
diff
changeset
|
32 |
|
|
350
c637688bd680
tweetWidget : format the tweet date according to the locale.
hamidouk
parents:
298
diff
changeset
|
33 |
var formatted_date = new Date(tweetContents.created_at).toLocaleDateString(); |
| 367 | 34 |
title = IriSP.templToHTML("<a class='Ldt-tweet_userHandle' href='http://twitter.com/{{creator}}'>@{{creator}}</a> - " + |
35 |
"<div class='Ldt-tweet_realName'>{{real_name}}</div>" + |
|
36 |
"<div class='Ldt-tweet_tweetContents'>{{{ contents }}}</div>" + |
|
37 |
"<div class='Ldt-tweet_date'>{{ date }}</div>", |
|
38 |
{creator: creator, real_name: real_name, contents : title, date : formatted_date}); |
|
| 370 | 39 |
|
40 |
this.selector.find(".Ldt-TweetReply").attr("href", "http://twitter.com/home?status=@" + creator + ":%20"); |
|
41 |
||
42 |
||
43 |
var rtText = Mustache.to_html("http://twitter.com/home?status=RT @{{creator}}: {{text}}", |
|
44 |
{creator: creator, text: IriSP.encodeURI(annotation.content.title)}); |
|
45 |
this.selector.find(".Ldt-Retweet").attr("href", rtText); |
|
|
293
314e6a13f841
tweetWidget : display better information, if available
hamidouk
parents:
285
diff
changeset
|
46 |
} |
| 277 | 47 |
|
| 285 | 48 |
this.selector.find(".Ldt-tweetContents").html(title); |
| 277 | 49 |
this.selector.find(".Ldt-tweetAvatar").html(imageMarkup); |
|
278
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
50 |
this.selector.show("blind", 250); |
| 277 | 51 |
}; |
52 |
||
53 |
IriSP.TweetsWidget.prototype.displayTweet = function(annotation) { |
|
54 |
if (this._displayingTweet === false) { |
|
55 |
this._displayingTweet = true; |
|
56 |
} else { |
|
57 |
window.clearTimeout(this._timeoutId); |
|
58 |
} |
|
59 |
||
60 |
this.drawTweet(annotation); |
|
61 |
||
62 |
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
|
63 |
this._timeoutId = window.setTimeout(IriSP.wrap(this, this.clearPanel), IriSP.widgetsDefaults.TweetsWidget.tweet_display_period); |
| 277 | 64 |
}; |
65 |
||
66 |
||
67 |
IriSP.TweetsWidget.prototype.clearPanel = function() { |
|
68 |
this._displayingTweet = false; |
|
|
278
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
69 |
this._timeoutId = undefined; |
| 277 | 70 |
this.closePanel(); |
|
278
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
71 |
|
| 277 | 72 |
}; |
73 |
||
74 |
IriSP.TweetsWidget.prototype.closePanel = function() { |
|
|
278
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
75 |
if (this._timeoutId != undefined) { |
|
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
76 |
/* we're called from the "close window" link */ |
|
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
77 |
/* cancel the timeout */ |
|
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
78 |
window.clearTimeout(this._timeoutId); |
|
378
110311d59b2f
implemented a second button to keep the tweetWidget open.
hamidouk
parents:
370
diff
changeset
|
79 |
this._timeoutId = null; |
|
278
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
80 |
} |
|
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
81 |
|
|
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
82 |
this.selector.hide("blind", 400); |
|
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
83 |
|
| 277 | 84 |
}; |
85 |
||
|
378
110311d59b2f
implemented a second button to keep the tweetWidget open.
hamidouk
parents:
370
diff
changeset
|
86 |
/* cancel the timeout if the user clicks on the keep panel open button */ |
|
110311d59b2f
implemented a second button to keep the tweetWidget open.
hamidouk
parents:
370
diff
changeset
|
87 |
IriSP.TweetsWidget.prototype.keepPanel = function() { |
|
110311d59b2f
implemented a second button to keep the tweetWidget open.
hamidouk
parents:
370
diff
changeset
|
88 |
if (this._timeoutId != undefined) { |
|
110311d59b2f
implemented a second button to keep the tweetWidget open.
hamidouk
parents:
370
diff
changeset
|
89 |
/* we're called from the "close window" link */ |
|
110311d59b2f
implemented a second button to keep the tweetWidget open.
hamidouk
parents:
370
diff
changeset
|
90 |
/* cancel the timeout */ |
|
110311d59b2f
implemented a second button to keep the tweetWidget open.
hamidouk
parents:
370
diff
changeset
|
91 |
window.clearTimeout(this._timeoutId); |
|
110311d59b2f
implemented a second button to keep the tweetWidget open.
hamidouk
parents:
370
diff
changeset
|
92 |
this._timeoutId = null; |
|
110311d59b2f
implemented a second button to keep the tweetWidget open.
hamidouk
parents:
370
diff
changeset
|
93 |
} |
|
110311d59b2f
implemented a second button to keep the tweetWidget open.
hamidouk
parents:
370
diff
changeset
|
94 |
}; |
|
110311d59b2f
implemented a second button to keep the tweetWidget open.
hamidouk
parents:
370
diff
changeset
|
95 |
|
| 277 | 96 |
IriSP.TweetsWidget.prototype.draw = function() { |
97 |
var _this = this; |
|
98 |
|
|
|
363
8d4b329836b6
converted the tweet widget to use the new template engine. removed a template of
hamidouk
parents:
350
diff
changeset
|
99 |
var tweetMarkup = IriSP.templToHTML(IriSP.tweetWidget_template, {"share_template" : IriSP.share_template}); |
| 277 | 100 |
this.selector.append(tweetMarkup); |
101 |
this.selector.hide(); |
|
|
278
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
102 |
this.selector.find(".Ldt-tweetWidgetMinimize").click(IriSP.wrap(this, this.closePanel)); |
|
378
110311d59b2f
implemented a second button to keep the tweetWidget open.
hamidouk
parents:
370
diff
changeset
|
103 |
this.selector.find(".Ldt-tweetWidgetKeepOpen").click(IriSP.wrap(this, this.keepPanel)); |
| 277 | 104 |
|
105 |
this._Popcorn.listen("IriSP.PolemicTweet.click", IriSP.wrap(this, this.PolemicTweetClickHandler)); |
|
106 |
}; |
|
107 |
||
108 |
IriSP.TweetsWidget.prototype.PolemicTweetClickHandler = function(tweet_id) { |
|
109 |
var index, annotation; |
|
110 |
for (index in this._serializer._data.annotations) { |
|
111 |
annotation = this._serializer._data.annotations[index]; |
|
112 |
|
|
113 |
if (annotation.id === tweet_id) |
|
114 |
break; |
|
115 |
} |
|
116 |
|
|
117 |
if (annotation.id !== tweet_id) |
|
118 |
/* we haven't found it */ |
|
119 |
return; |
|
120 |
|
|
121 |
this.displayTweet(annotation); |
|
122 |
return; |
|
|
350
c637688bd680
tweetWidget : format the tweet date according to the locale.
hamidouk
parents:
298
diff
changeset
|
123 |
}; |