Skip to content

Commit

Permalink
switch to using some jquery
Browse files Browse the repository at this point in the history
  • Loading branch information
tienshiao committed Jul 29, 2012
1 parent 0dccd22 commit 8ee33d5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
1 change: 1 addition & 0 deletions global.html
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<script src="jquery-1.7.2.min.js"></script>
<script src="global.js"></script>
</head>
<body>
Expand Down
4 changes: 4 additions & 0 deletions jquery-1.7.2.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions template.html
Expand Up @@ -2,6 +2,7 @@
<html style="overflow:hidden;">
<head>
<link rel="stylesheet" href="template.css" />
<script src="jquery-1.7.2.min.js"></script>
<script src="template.js"></script>
</head>
<body>
Expand Down
49 changes: 22 additions & 27 deletions template.js
Expand Up @@ -4,50 +4,45 @@ function initBar() {
if (e.message) {
var link = e.message;

if (document.readyState == 'complete') {
$(document).ready(function() {
displayBar(link);
} else {
window.addEventListener('load', function() {
displayBar(link);
});
}
});
}
} else if (e.name === 'gainFocus') {
document.getElementsByTagName('body')[0].className = document.getElementsByTagName('body')[0].className.replace(/(?:^|\s)inactive(?!\S)/, '');
$('body').removeClass('inactive');
} else if (e.name === 'loseFocus') {
document.getElementsByTagName('body')[0].className += ' inactive';
$('body').addClass('inactive');
}
}, false);
safari.self.tab.dispatchMessage('getLink', null);
}

function displayBar(link) {
document.getElementById('logo').setAttribute('href', 'http://' + link.reddit + '/');
document.getElementById('score').innerHTML = link.score;
document.getElementById('title').setAttribute('href', link.commentsHref);
document.getElementById('title').innerHTML = link.title;
document.getElementById('subreddit').setAttribute('href', 'http://www.reddit.com/r/' + link.subreddit);
document.getElementById('subreddit').innerHTML = '/r/' + link.subreddit;
document.getElementById('comments').setAttribute('href', link.commentsHref);
document.getElementById('comment-count').innerHTML = link.comments;
$('#logo').attr('href', 'http://' + link.reddit + '/');
$('#score').html(link.score);
$('#title').attr('href', link.commentsHref)
.html(link.title);
$('#subreddit').attr('href', 'http://' + link.reddit + '/r/' + link.subreddit)
.html('/r/' + link.subreddit);
$('#comments').attr('href', link.commentsHref);
$('#comment-count').html(link.comments);

var title = document.getElementById('title');
safari.self.tab.dispatchMessage('setHeight', parseInt(window.getComputedStyle(title,"").getPropertyValue('height')) + 10 + 'px');
window.addEventListener('resize', function(e) {
safari.self.tab.dispatchMessage('setHeight', parseInt(window.getComputedStyle(title,"").getPropertyValue('height')) + 10 + 'px');
}, false);
safari.self.tab.dispatchMessage('setHeight', $('.bar').first().outerHeight() + 'px');
$(window).resize(function() {
safari.self.tab.dispatchMessage('setHeight', $('.bar').first().outerHeight() + 'px');
});

document.getElementById('close').addEventListener('click', function(e) {
$('#close').click(function() {
safari.self.tab.dispatchMessage('close', null);
}, false);
});

window.addEventListener('focus', function(e) {
$(window).focus(function() {
safari.self.tab.dispatchMessage('gainFocus', null);
}, false);
});

window.addEventListener('blur', function(e) {
$(window).blur(function() {
safari.self.tab.dispatchMessage('loseFocus', null);
}, false);
});

}

Expand Down

0 comments on commit 8ee33d5

Please sign in to comment.