adds some js to click-and-add tags to the debate's tag list input
This commit is contained in:
@@ -24,6 +24,7 @@ var initialize_modules = function() {
|
||||
App.Comments.initialize();
|
||||
App.Users.initialize();
|
||||
App.Votes.initialize();
|
||||
App.Tags.initialize();
|
||||
};
|
||||
|
||||
$(function(){
|
||||
|
||||
21
app/assets/javascripts/tags.js.coffee
Normal file
21
app/assets/javascripts/tags.js.coffee
Normal 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'
|
||||
@@ -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 %>
|
||||
|
||||
Reference in New Issue
Block a user