-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweetStrip.js
121 lines (92 loc) · 3.33 KB
/
tweetStrip.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
function TweetStrip() {
this._init();
}
TweetStrip.prototype = {
_init: function() {
this._visible = false;
this._box = "#tweetstrip";
this.hide();
var me = this;
$(document).bind('refreshed', function() {
me._refreshItems();
});
/*
$(document).bind('current-tweet-changed', function() {
me._updatePosition();
});
*/
window.addEventListener('WheelNextItem', function() {
twitter.nextTweet();
me._updatePosition(true);
}, false);
window.addEventListener('WheelPreviousItem', function() {
twitter.previousTweet();
me._updatePosition(true);
}, false);
},
isVisible: function() {
return this._visible;
},
show: function() {
console.log("showing tweetstrip");
this._visible = true;
$(this._box).animate({
bottom: 0
});
this._updatePosition(false);
openchannel.enableWheel();
},
hide: function() {
console.log("hiding tweetstrip");
this._visible = false;
$(this._box).stop().animate({
bottom: -$(this._box).outerHeight()
})
openchannel.disableWheel();
},
_refreshItems: function() {
$(this._box).children().remove();
var tweets = twitter.getTweets();
for (var i = 0; i < tweets.length; i++) {
var itemBox = document.createElement('div');
$(itemBox).attr('id', 'tweetstrip-item-' + tweets[i].id);
$(itemBox).addClass('tweetstrip-item');
$(itemBox).height($(this._box).height());
$(itemBox).width($(this._box).height() * 1.90);
$(this._box).append(itemBox);
$(itemBox).css({
left: i * $(itemBox).outerWidth(true),
});
renderTweet({
box: itemBox,
tweet: tweets[i],
});
}
// sloppy but it works :/
$(this._box).width(tweets.length * $(this._box).height() * 2.5);
$(this._box).find('.autofontsize').autoFontSize();
},
_updatePosition: function(stopOtherAnimations) {
$(this._box).find('.selected').removeClass('selected');
var selected = $(this._box).find('#tweetstrip-item-' + twitter.getCurrentTweet().id);
selected.addClass('selected');
var boxOffset = -$(this._box).offset().left;
var visibleWidth = $(window).width();
var itemOffset = selected.offset().left;
var itemWidth = selected.outerWidth(true);
console.log("visible width: " + visibleWidth);
console.log("item position: " + itemOffset);
if ((itemOffset + itemWidth) > visibleWidth) {
boxOffset += (itemOffset +itemWidth - visibleWidth);
} else if (itemOffset < 0) {
boxOffset += itemOffset - parseInt($(selected).css('padding-left').replace('px', ''));
}
if (stopOtherAnimations) {
$(this._box).stop();
}
$(this._box).animate({
opacity: 1.0,
left: -boxOffset
});
},
}