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

refactoring javascript to put starring functionality in a function

parent 8bbcbe78
...@@ -16,11 +16,13 @@ ...@@ -16,11 +16,13 @@
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');
var toggleStar = function(isStarred) {
$this $this
.parent() .parent()
.find('span.count') .find('span.count')
.text(data.star_count); .text(data.star_count);
if($starSpan.hasClass('starred')){ if(isStarred){
$starSpan $starSpan
.removeClass('starred') .removeClass('starred')
.text('Star'); .text('Star');
...@@ -36,6 +38,9 @@ ...@@ -36,6 +38,9 @@
.removeClass('fa-star-o') .removeClass('fa-star-o')
.addClass('fa-star'); .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