diff options
author | Jacob Schatz <jacobschatz@Jacobs-MBP.fios-router.home> | 2015-12-23 20:54:51 +0300 |
---|---|---|
committer | Jacob Schatz <jacobschatz@Jacobs-MBP.fios-router.home> | 2015-12-23 20:54:51 +0300 |
commit | 52293ccd65b1de8c2f70642d8146a09518258c47 (patch) | |
tree | 737edd7c1ba4fae31b47876845ef6340afaf7309 /app | |
parent | 8bbcbe78546beda04420e4403f7e6d42b38a55e4 (diff) |
refactoring javascript to put starring functionality in a function
Diffstat (limited to 'app')
-rw-r--r-- | app/views/projects/buttons/_star.html.haml | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/app/views/projects/buttons/_star.html.haml b/app/views/projects/buttons/_star.html.haml index 0f2ee119871..f92488fd88f 100644 --- a/app/views/projects/buttons/_star.html.haml +++ b/app/views/projects/buttons/_star.html.haml @@ -16,26 +16,31 @@ var $this = $(this); var $starSpan = $this.find('span'); 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 { - $starSpan - .addClass('starred') - .text('Unstar'); - $starIcon - .removeClass('fa-star-o') - .addClass('fa-star'); - } + var toggleStar = function(isStarred) { + $this + .parent() + .find('span.count') + .text(data.star_count); + if(isStarred){ + $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) { new Flash('Star toggle failed. Try again later.', 'alert'); |