summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/star.js.coffee
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/star.js.coffee')
-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