diff options
author | Jacob Schatz <jacobschatz@Jacobs-MBP.fios-router.home> | 2015-12-24 04:36:29 +0300 |
---|---|---|
committer | Jacob Schatz <jacobschatz@Jacobs-MBP.fios-router.home> | 2015-12-24 04:36:29 +0300 |
commit | 6592bfbb9ed37c348f257106c1da35692ef6a111 (patch) | |
tree | c888fd5d59de170cd6b02ee1a196df8b94d22ba8 /app/assets/javascripts/star.js.coffee | |
parent | 7ba4482fcf6faae162ceb920044f4ec07ef048af (diff) |
Moves star code to a class
Diffstat (limited to 'app/assets/javascripts/star.js.coffee')
-rw-r--r-- | app/assets/javascripts/star.js.coffee | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/app/assets/javascripts/star.js.coffee b/app/assets/javascripts/star.js.coffee new file mode 100644 index 00000000000..d849b2e7950 --- /dev/null +++ b/app/assets/javascripts/star.js.coffee @@ -0,0 +1,22 @@ +class @Star + constructor: -> + $('.project-home-panel .toggle-star').on('ajax:success', (e, data, status, xhr) -> + $this = $(this) + $starSpan = $this.find('span') + $starIcon = $this.find('i') + + toggleStar = (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' + return + + toggleStar $starSpan.hasClass('starred') + return + ).on 'ajax:error', (e, xhr, status, error) -> + new Flash('Star toggle failed. Try again later.', 'alert') + return
\ No newline at end of file |