summaryrefslogtreecommitdiff
path: root/app/assets/javascripts
diff options
context:
space:
mode:
authorJacob Schatz <jacobschatz@Jacobs-MBP.fios-router.home>2015-12-23 20:36:29 -0500
committerJacob Schatz <jacobschatz@Jacobs-MBP.fios-router.home>2015-12-23 20:36:29 -0500
commit6592bfbb9ed37c348f257106c1da35692ef6a111 (patch)
treec888fd5d59de170cd6b02ee1a196df8b94d22ba8 /app/assets/javascripts
parent7ba4482fcf6faae162ceb920044f4ec07ef048af (diff)
downloadgitlab-ce-6592bfbb9ed37c348f257106c1da35692ef6a111.tar.gz
Moves star code to a class
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r--app/assets/javascripts/star.js.coffee22
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