smart_tag 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
data/lib/smart_tag/engine.rb
CHANGED
data/lib/smart_tag/helper.rb
CHANGED
@@ -11,7 +11,7 @@ module SmartTag
|
|
11
11
|
def smart_tag(name, method, options = {})
|
12
12
|
input_html = (options.delete(:input_html) || {})
|
13
13
|
hash = input_html.stringify_keys
|
14
|
-
instance_tag = ActionView::Base::
|
14
|
+
instance_tag = ActionView::Base::FormBuilder.new(name, method, self, options.delete(:object))
|
15
15
|
instance_tag.send(:add_default_name_and_id, hash)
|
16
16
|
output_buffer = ActiveSupport::SafeBuffer.new
|
17
17
|
output_buffer << instance_tag.to_text_area_tag(input_html)
|
data/lib/smart_tag/version.rb
CHANGED
data/smart_tag.gemspec
CHANGED
@@ -0,0 +1,83 @@
|
|
1
|
+
(function($){
|
2
|
+
$(document).ready(function() {
|
3
|
+
|
4
|
+
function smart_tag(select) {
|
5
|
+
|
6
|
+
function in_array(array, value) {
|
7
|
+
for (var i = array.length - 1; i >= 0; i--) {
|
8
|
+
if (array[i] == value) {
|
9
|
+
return true;
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
return false;
|
14
|
+
}
|
15
|
+
|
16
|
+
function get_options_text(options) {
|
17
|
+
var options_text = [];
|
18
|
+
for (var i = options.length - 1; i >= 0; i--) {
|
19
|
+
var text = $(options[i]).text();
|
20
|
+
|
21
|
+
if (!in_array(options_text, text)) {
|
22
|
+
options_text.push(text);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
return options_text;
|
27
|
+
}
|
28
|
+
|
29
|
+
function add_tags(ul) {
|
30
|
+
var selected_options_text = get_options_text(select.children('option:selected'));
|
31
|
+
ul.tagit("removeAll");
|
32
|
+
for (var i = selected_options_text.length - 1; i >= 0; i--) {
|
33
|
+
ul.tagit("createTag", selected_options_text[i]);
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
function ul_to_selected(tags) {
|
38
|
+
for (var i = options.length - 1; i >= 0; i--) {
|
39
|
+
var option = $(options[i]);
|
40
|
+
if (in_array(tags, option.text())) {
|
41
|
+
option.attr("selected", true);
|
42
|
+
} else {
|
43
|
+
option.attr("selected", false);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
var options = select.children('option');
|
49
|
+
var all_options_text = get_options_text(options);
|
50
|
+
var ul = $('<ul class="' + select.attr('id') + '_smart_tag"></ul>');
|
51
|
+
|
52
|
+
select.before(ul);
|
53
|
+
|
54
|
+
ul.css({
|
55
|
+
'margin-left': '0px',
|
56
|
+
'width': '488px'
|
57
|
+
});
|
58
|
+
|
59
|
+
ul.tagit({
|
60
|
+
availableTags: all_options_text,
|
61
|
+
afterTagAdded: function(event, ui) {
|
62
|
+
ul_to_selected(ul.tagit("assignedTags"));
|
63
|
+
},
|
64
|
+
afterTagRemoved: function(event, ui) {
|
65
|
+
ul_to_selected(ul.tagit("assignedTags"));
|
66
|
+
}
|
67
|
+
});
|
68
|
+
|
69
|
+
add_tags(ul);
|
70
|
+
|
71
|
+
select.change(function(){
|
72
|
+
add_tags(ul);
|
73
|
+
});
|
74
|
+
}
|
75
|
+
|
76
|
+
var selects = $(".smart_tag");
|
77
|
+
|
78
|
+
for (var i = selects.length - 1; i >= 0; i--) {
|
79
|
+
smart_tag($(selects[i]));
|
80
|
+
}
|
81
|
+
|
82
|
+
});
|
83
|
+
}(window.jQuery));
|
@@ -0,0 +1 @@
|
|
1
|
+
(function($){$(document).ready(function(){function smart_tag(select){function in_array(array,value){for(var i=array.length-1;i>=0;i--){if(array[i]==value){return true}}return false}function get_options_text(options){var options_text=[];for(var i=options.length-1;i>=0;i--){var text=$(options[i]).text();if(!in_array(options_text,text)){options_text.push(text)}}return options_text}function add_tags(ul){var selected_options_text=get_options_text(select.children('option:selected'));ul.tagit("removeAll");for(var i=selected_options_text.length-1;i>=0;i--){ul.tagit("createTag",selected_options_text[i])}}function ul_to_selected(tags){for(var i=options.length-1;i>=0;i--){var option=$(options[i]);if(in_array(tags,option.text())){option.attr("selected",true)}else{option.attr("selected",false)}}}var options=select.children('option');var all_options_text=get_options_text(options);var ul=$('<ul class="'+select.attr('id')+'_smart_tag"></ul>');select.before(ul);ul.css({'margin-left':'0px','width':'488px'});ul.tagit({availableTags:all_options_text,afterTagAdded:function(event,ui){ul_to_selected(ul.tagit("assignedTags"))},afterTagRemoved:function(event,ui){ul_to_selected(ul.tagit("assignedTags"))}});add_tags(ul);select.change(function(){add_tags(ul)})}var selects=$(".smart_tag");for(var i=selects.length-1;i>=0;i--){smart_tag($(selects[i]))}})}(window.jQuery));
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_tag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
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: 2013-04-
|
12
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jquery-ui-rails
|
@@ -44,6 +44,8 @@ files:
|
|
44
44
|
- lib/smart_tag/helper.rb
|
45
45
|
- lib/smart_tag/version.rb
|
46
46
|
- smart_tag.gemspec
|
47
|
+
- vendor/assets/javascripts/smart_tag/smart_tag.js
|
48
|
+
- vendor/assets/javascripts/smart_tag/smart_tag.min.js
|
47
49
|
- vendor/assets/javascripts/smart_tag/tag-it.min.js
|
48
50
|
- vendor/assets/stylesheets/smart_tag/jquery.tagit.css
|
49
51
|
homepage: https://github.com/tuliang/smart_tag
|