rails_admin_tag_list 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,17 +7,21 @@
7
7
  jQuery(function(){
8
8
  var input_id = '#{form.dom_id(field)}'
9
9
  $('.tag_suggestion[data-input-id=' + input_id + ']').click(function(event){
10
- var tag_list, new_value;
10
+ var tag_list, values, tag;
11
11
  tag_list = $(this).siblings('input#' + input_id);
12
-
13
- if (!tag_list.val().match(/\S/)) {
14
- new_value = this.innerHTML;
12
+ // Get the current values by splitting on a comma and stripping whitespace.
13
+ values = jQuery.map(tag_list.val().split(','), function(val){ return jQuery.trim(val) });
14
+ // Remove empty strings from values
15
+ values = jQuery.grep(values, function(n) { return n.length > 0 });
16
+ tag = $(this).text();
17
+ if (jQuery.inArray(tag, values) == -1) {
18
+ values.push(tag);
15
19
  } else {
16
- new_value = [tag_list.val(), this.innerHTML].join(', ');
17
- };
18
- tag_list.val(new_value);
20
+ // Remove current tag from current_values
21
+ values = jQuery.grep(values, function(n) { return n != tag });
22
+ }
23
+ tag_list.val(values.join(', '));
19
24
 
20
- event.preventDefault();
21
25
  return false;
22
26
  });
23
27
  });
@@ -1,3 +1,3 @@
1
1
  module RailsAdminTagList
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_admin_tag_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-15 00:00:00.000000000 Z
12
+ date: 2012-10-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails