| author | hamidouk |
| Mon, 21 Nov 2011 10:51:22 +0100 | |
| branch | tweet-widget |
| changeset 285 | b7aa28af2c10 |
| parent 282 | 1001234e5e6e |
| child 293 | 314e6a13f841 |
| 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 |
} |
|
21 |
|
|
22 |
var imageMarkup = Mustache.to_html("<img src='{{src}}' alt='avatar'></img>", |
|
23 |
{src : img}); |
|
24 |
||
| 285 | 25 |
this.selector.find(".Ldt-tweetContents").html(title); |
| 277 | 26 |
this.selector.find(".Ldt-tweetAvatar").html(imageMarkup); |
|
278
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
27 |
this.selector.show("blind", 250); |
| 277 | 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(); |
|
|
282
1001234e5e6e
added a var to configure the num of seconds to display the tweet.
hamidouk
parents:
278
diff
changeset
|
40 |
this._timeoutId = window.setTimeout(IriSP.wrap(this, this.clearPanel), IriSP.widgetsDefaults.TweetsWidget.tweet_display_period); |
| 277 | 41 |
}; |
42 |
||
43 |
||
44 |
IriSP.TweetsWidget.prototype.clearPanel = function() { |
|
45 |
this._displayingTweet = false; |
|
|
278
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
46 |
this._timeoutId = undefined; |
| 277 | 47 |
this.closePanel(); |
|
278
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
48 |
|
| 277 | 49 |
}; |
50 |
||
51 |
IriSP.TweetsWidget.prototype.closePanel = function() { |
|
|
278
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
52 |
if (this._timeoutId != undefined) { |
|
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
53 |
/* we're called from the "close window" link */ |
|
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
54 |
/* cancel the timeout */ |
|
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
55 |
window.clearTimeout(this._timeoutId); |
|
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
56 |
} |
|
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
57 |
|
|
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
58 |
this.selector.hide("blind", 400); |
|
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
59 |
|
| 277 | 60 |
}; |
61 |
||
62 |
IriSP.TweetsWidget.prototype.draw = function() { |
|
63 |
var _this = this; |
|
64 |
|
|
65 |
var tweetMarkup = Mustache.to_html(IriSP.tweetWidget_template, {"share_template" : IriSP.share_template}); |
|
66 |
this.selector.append(tweetMarkup); |
|
67 |
this.selector.hide(); |
|
|
278
ff20c80c6845
added a minimize functionality to the tweetwidget.
hamidouk
parents:
277
diff
changeset
|
68 |
this.selector.find(".Ldt-tweetWidgetMinimize").click(IriSP.wrap(this, this.closePanel)); |
| 277 | 69 |
|
70 |
this._Popcorn.listen("IriSP.PolemicTweet.click", IriSP.wrap(this, this.PolemicTweetClickHandler)); |
|
71 |
}; |
|
72 |
||
73 |
IriSP.TweetsWidget.prototype.PolemicTweetClickHandler = function(tweet_id) { |
|
74 |
var index, annotation; |
|
75 |
for (index in this._serializer._data.annotations) { |
|
76 |
annotation = this._serializer._data.annotations[index]; |
|
77 |
|
|
78 |
if (annotation.id === tweet_id) |
|
79 |
break; |
|
80 |
} |
|
81 |
|
|
82 |
if (annotation.id !== tweet_id) |
|
83 |
/* we haven't found it */ |
|
84 |
return; |
|
85 |
|
|
86 |
this.displayTweet(annotation); |
|
87 |
return; |
|
|
267
f84013fb19dc
added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff
changeset
|
88 |
}; |