adds some js to click-and-add tags to the debate's tag list input

This commit is contained in:
David Gil
2015-08-15 18:57:27 +02:00
parent 1de941d1fa
commit 8b89cc5117
3 changed files with 23 additions and 1 deletions

View File

@@ -24,6 +24,7 @@ var initialize_modules = function() {
App.Comments.initialize();
App.Users.initialize();
App.Votes.initialize();
App.Tags.initialize();
};
$(function(){

View File

@@ -0,0 +1,21 @@
App.Tags =
initialize: ->
$tag_input = $('input#debate_tag_list')
$('body .js-add-tag-link').each ->
$this = $(this)
unless $this.data('initialized') is 'yes'
$this.on('click', ->
name = $(this).text()
current_tags = $tag_input.val().split(',').filter(Boolean)
if $.inArray(name, current_tags) >= 0
current_tags.splice($.inArray(name, current_tags), 1);
else
current_tags.push name
$tag_input.val(current_tags.join(','))
false
).data 'initialized', 'yes'

View File

@@ -28,7 +28,7 @@
<span class="note"><%= t("debates.form.tags_instructions") %></span>
<span class="tags">
<% @featured_tags.each do |tag| %>
<a><%= tag.name %></a>
<a class="js-add-tag-link"><%= tag.name %></a>
<% end %>
</span>
<%= f.text_field :tag_list, value: @debate.tag_list.to_s %>