Commit 52293ccd authored by Jacob Schatz's avatar Jacob Schatz

refactoring javascript to put starring functionality in a function

parent 8bbcbe78
...@@ -16,26 +16,31 @@ ...@@ -16,26 +16,31 @@
var $this = $(this); var $this = $(this);
var $starSpan = $this.find('span'); var $starSpan = $this.find('span');
var $starIcon = $this.find('i'); var $starIcon = $this.find('i');
$this
.parent()
.find('span.count')
.text(data.star_count);
if($starSpan.hasClass('starred')){
$starSpan
.removeClass('starred')
.text('Star');
$starIcon
.removeClass('fa-star')
.addClass('fa-star-o');
} else { var toggleStar = function(isStarred) {
$starSpan $this
.addClass('starred') .parent()
.text('Unstar'); .find('span.count')
$starIcon .text(data.star_count);
.removeClass('fa-star-o') if(isStarred){
.addClass('fa-star'); $starSpan
} .removeClass('starred')
.text('Star');
$starIcon
.removeClass('fa-star')
.addClass('fa-star-o');
} else {
$starSpan
.addClass('starred')
.text('Unstar');
$starIcon
.removeClass('fa-star-o')
.addClass('fa-star');
}
};
toggleStar($starSpan.hasClass('starred'));
}) })
.on('ajax:error', function (e, xhr, status, error) { .on('ajax:error', function (e, xhr, status, error) {
new Flash('Star toggle failed. Try again later.', 'alert'); new Flash('Star toggle failed. Try again later.', 'alert');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment