Skip to content

Commit

Permalink
Improving performance and some refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarsa committed Dec 2, 2009
1 parent 8692d53 commit cd414b3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 42 deletions.
11 changes: 3 additions & 8 deletions background.html
Expand Up @@ -122,7 +122,8 @@

if(this.firstRun) {
this.firstRun = false;
this.fetchNewTweets();
var _this = this;
this.timerId = setTimeout(function() { _this.fetchNewTweets.call(_this); }, this.recheckTime);
}
},

Expand Down Expand Up @@ -181,13 +182,7 @@
var len = this.tweetsCache.length;
if(len <= TweetManagerConstants.MAX_CACHED_ELEMENTS)
return;
var i = len - 1;
for(; i >= TweetManagerConstants.MAX_CACHED_ELEMENTS; --i) {
if(!this.manager.isTweetRead(this.tweetsCache[i].id)) {
break;
}
}
this.tweetsCache = this.tweetsCache.slice(0, i + 1);
this.tweetsCache = this.tweetsCache.slice(0, TweetManagerConstants.MAX_CACHED_ELEMENTS + 1);
},

updateNewTweets: function() {
Expand Down
2 changes: 1 addition & 1 deletion css/chromified.css
Expand Up @@ -48,7 +48,7 @@ input[type='text'] {

#workspace {
margin: 0px 4px 0px 4px;
min-width: 370px;
min-width: 410px;
}

.timeline {
Expand Down
2 changes: 1 addition & 1 deletion css/whisper.css
Expand Up @@ -44,7 +44,7 @@ input[type='text'] {

#workspace {
margin: 0px 4px 0px 4px;
min-width: 370px;
min-width: 410px;
}

.timeline {
Expand Down
71 changes: 39 additions & 32 deletions popup.html
Expand Up @@ -2,15 +2,8 @@

<html>
<head>
<!--
HACK: Preloading themes CSS's with an invalid media (hidden) , otherwise popup window enlarges
when loading it for the first time. (Don't know why...)
-->
<link rel="stylesheet" type="text/css" href="css/whisper.css" class="theme" media="hidden" />
<link rel="stylesheet" type="text/css" href="css/whisper-theme/jquery-ui-1.7.2.custom.css" class="theme" media="hidden"/>

<link rel="stylesheet" type="text/css" href="css/chromified.css" class="theme" />
<link rel="stylesheet" type="text/css" href="css/chromified-theme/jquery-ui-1.7.2.custom.css" class="theme" />
<!-- CSS files are loaded later by the ThemeManager -->

<link rel="stylesheet" type="text/css" href="css/sexy-combo.css" />

Expand Down Expand Up @@ -78,15 +71,12 @@
}

var ThemeManager = {
initTheme: function () {
init: function () {
var theme = localStorage.currentTheme;
if(theme) {
ThemeManager.changeTheme(theme);
$("select#theme_selector").val(theme);
}
},
updateThemeSelector: function() {
ThemeManager.initTheme();
$("select#theme_selector").sexyCombo({changeCallback: ThemeManager.changeTheme});
},
changeTheme: function (newCss) {
Expand All @@ -96,7 +86,7 @@
localStorage.currentTheme = newCss;
$("link.theme").remove();
$(newCss.split(",")).each(function(i, p) {
newLink = $("<link rel='stylesheet' type='text/css' class='theme'>").attr("href", p);
var newLink = $("<link rel='stylesheet' type='text/css' class='theme' href='" + p + "'>");
$(document.head).prepend(newLink);
});
}
Expand All @@ -106,6 +96,15 @@
replyId: null,
rtId: null,

init: function() {
if(tweetManager.composerData.isComposing) {
Composer.replyId = tweetManager.composerData.replyId;
$("#compose_tweet_area textarea").val(tweetManager.composerData.saveMessage || '');
Composer.showComposeArea(true, true);
}
Composer.textareaChanged();
},

share: function (node) {
Composer.showComposeArea(true);
var el = $("#compose_tweet_area textarea");
Expand Down Expand Up @@ -378,7 +377,12 @@
text = tweet.retweeted_status.text
}

var str = '<div tweetid="' + tweet.id + '" class="tweet">';
var tweetClass = 'tweet';
if(!tweetManager.isTweetRead(tweet.id)) {
tweetClass += ' unread';
}

var str = '<div tweetid="' + tweet.id + '" class="' + tweetClass + '">';
str += '<img class="profile" src="' + user.profile_image_url + '" onclick="openTab(\'' + TwitterLib.URLS.BASE + user.screen_name + '\')"></img>';
str += '<a href="#" class="user" onclick="openTab(\'' + TwitterLib.URLS.BASE + user.screen_name + '\')">' + user.screen_name + '</a>';
str += '<div class="text">';
Expand Down Expand Up @@ -441,9 +445,6 @@
$(".tweet .text", destination).replaceHtml(transformList[i].expression, transformList[i].replacement);
}

for(var unreadId in tweetManager.unreadTweets) {
$(".tweet[tweetid='" + unreadId +"']").addClass('unread');
}
$(".tweet.unread").hoverFor(1000,
function() {
//Hovering for <time> seconds, let's read it.
Expand Down Expand Up @@ -551,6 +552,7 @@
}

function prepareAndLoadTimeline() {
$("#update_tweets").hide();
var currentTimeline = tweetManager.currentTimeline;

tweetManager.eachTimeline(function(timeline) {
Expand All @@ -574,35 +576,39 @@
$(function() {
if(!twitterBackend.authenticated())
return;
$("#workspace").show();
ThemeManager.updateThemeSelector();
if(tweetManager.composerData.isComposing) {
Composer.replyId = tweetManager.composerData.replyId;
$("#compose_tweet_area textarea").val(tweetManager.composerData.saveMessage || '');
Composer.showComposeArea(true, true);
}
tweetManager.registerNewTweetsCallback(newTweetsAvailable);
$("#workspace").show();
$(".__username").text(tweetManager.twitterBackend.username());
Composer.textareaChanged();
Shortener.init();
ThemeManager.init();

var selectedNumber = 0;
switch(tweetManager.currentTimeline) {
case 'mentions': selectedNumber = 1; break;
case 'dms': selectedNumber = 2; break;
}
$("#tabs").tabs({
selected: selectedNumber,
select: function(event, ui) {
tweetManager.currentTimeline = ui.panel.id.split('_')[1];
prepareAndLoadTimeline();
},
show: function(event, ui) {
$("#update_tweets").hide();
prepareAndLoadTimeline();
$(ui.panel).scrollTop(tweetManager.getCurrentTimeline().currentScroll);
}
});
$("#tabs").tabs('select', "#timeline_" + tweetManager.currentTimeline);
ThemeManager.initTheme();

tweetManager.eachTimeline(function(timeline) {
//Delay loading, improving responsiveness
setTimeout(function() {
Composer.init();
Shortener.init();

prepareAndLoadTimeline();
var tabEl = $("#timeline_" + tweetManager.currentTimeline);
tabEl.scrollTop(tweetManager.getCurrentTimeline().currentScroll);

tweetManager.eachTimeline(function(timeline) {
var timelineId = this;
var tabEl = $("#timeline_" + timelineId);
tabEl.scrollTop(timeline.currentScroll);
tabEl.scroll(function(e) {
var $this = $(this);
var threshold = 50;
Expand All @@ -614,6 +620,7 @@
}
}
});
}, 0);
});
});
</script>
Expand Down

0 comments on commit cd414b3

Please sign in to comment.