smart_tag 0.4.2 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,22 +8,20 @@ module SmartTag
8
8
  # output << text_area_tag(name, content, input_html)
9
9
  # end
10
10
 
11
- def smart_tag(name)
12
- name
13
- # input_html = (options.delete(:input_html) || {})
14
- # hash = input_html.stringify_keys
15
- # instance_tag = ActionView::Base::FormBuilder.new(name, method, self, options.delete(:object))
16
- # instance_tag.send(:add_default_name_and_id, hash)
17
- # output_buffer = ActiveSupport::SafeBuffer.new
18
- # output_buffer << instance_tag.to_text_area_tag(input_html)
19
-
11
+ def smart_tag(name, method, options = {})
12
+ input_html = (options.delete(:input_html) || {})
13
+ hash = input_html.stringify_keys
14
+ instance_tag = ActionView::Base::FormBuilder.new(name, method, self, options.delete(:object))
15
+ instance_tag.send(:add_default_name_and_id, hash)
16
+ output_buffer = ActiveSupport::SafeBuffer.new
17
+ output_buffer << instance_tag.to_text_area_tag(input_html)
20
18
  end
21
19
 
22
20
  end
23
21
 
24
- # module Builder
25
- # def smart_tag(method, options = {})
26
- # @template.send("smart_tag", @object_name, method, objectify_options(options))
27
- # end
28
- # end
22
+ module Builder
23
+ def smart_tag(method, options = {})
24
+ @template.send("smart_tag", @object_name, method, objectify_options(options))
25
+ end
26
+ end
29
27
  end
@@ -1,3 +1,3 @@
1
1
  module SmartTag
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.4"
3
3
  end
@@ -4,6 +4,7 @@
4
4
  function Base(select) {
5
5
  var that = {};
6
6
  that.select = select;
7
+ that.is_start = false;
7
8
 
8
9
  that.inArray = function(array, value) {
9
10
  for (var i = array.length - 1; i >= 0; i--) {
@@ -94,6 +95,7 @@
94
95
 
95
96
  that.start = function() {
96
97
  that.createTags();
98
+ that.is_start = true;
97
99
  };
98
100
 
99
101
  return that;
@@ -102,6 +104,7 @@
102
104
  function SmartTag(select) {
103
105
 
104
106
  var that = Base(select);
107
+ that.is_add = that.select.attr('is_add') ? that.select.attr('is_add') : true;
105
108
 
106
109
  that.ajaxAddTag = function(add_tag) {
107
110
  var controller = that.select.attr('controller');
@@ -141,10 +144,15 @@
141
144
  var add_tag = ui.tagLabel;
142
145
  all_options = that.getOptions(that.select.children('option'));
143
146
 
147
+ that.ul.parents(".control-group").removeClass("error");
148
+
144
149
  if (that.inArray(all_options, add_tag)) {
145
150
  that.changeSelected(that.ul.tagit("assignedTags"), that.addSelected);
151
+ } else if (true === that.is_add) {
152
+ that.ajaxAddTag(add_tag);
146
153
  } else {
147
- that.ajaxAddTag(add_tag);
154
+ that.ul.tagit("removeTagByLabel", add_tag);
155
+ that.ul.parents(".control-group").addClass("error");
148
156
  }
149
157
  },
150
158
  afterTagRemoved: function(event, ui) {
@@ -184,11 +192,12 @@
184
192
  that.ul.parents(".control-group").addClass("error");
185
193
  that.ul.parents(".control-group").find('.help-inline').text("You should choice one career.");
186
194
  }
187
-
188
195
 
189
196
  if(that.ul.tagit("assignedTags").length == 1){
190
197
  that.ul.find(".ui-autocomplete-input").attr('disabled', 'disabled');
191
- that.select.focus();
198
+ if (true === that.is_start) {
199
+ that.select.focus();
200
+ }
192
201
  }
193
202
  },
194
203
  afterTagRemoved: function(event, ui) {
@@ -1,7 +1,7 @@
1
- (function(f){f(document).ready(function(){function k(e){var a={};a.select=e;a.inArray=function(a,c){for(var b=a.length-1;0<=b;b--)if(a[b]==c)return!0;return!1};a.clearText=function(a){return a.replace(/^\s+|\s+$/g,"")};a.getOptions=function(d){for(var c=[],b=d.length-1;0<=b;b--){var e=a.clearText(f(d[b]).text());a.inArray(c,e)||c.push(e)}return c};a.createTags=function(){for(var d=a.selected_options.length-1;0<=d;d--)a.ul.tagit("createTag",a.selected_options[d])};a.changeTags=function(){for(var d=
1
+ (function(f){f(document).ready(function(){function k(e){var a={};a.select=e;a.is_start=!1;a.inArray=function(a,c){for(var b=a.length-1;0<=b;b--)if(a[b]==c)return!0;return!1};a.clearText=function(a){return a.replace(/^\s+|\s+$/g,"")};a.getOptions=function(d){for(var c=[],b=d.length-1;0<=b;b--){var e=a.clearText(f(d[b]).text());a.inArray(c,e)||c.push(e)}return c};a.createTags=function(){for(var d=a.selected_options.length-1;0<=d;d--)a.ul.tagit("createTag",a.selected_options[d])};a.changeTags=function(){for(var d=
2
2
  a.getOptions(a.select.children("option:selected")),c=a.ul.tagit("assignedTags"),b=c.length-1;0<=b;b--)a.inArray(d,c[b])||a.ul.tagit("removeTagByLabel",c[b]);for(b=d.length-1;0<=b;b--)a.inArray(c,d[b])||a.ul.tagit("createTag",d[b])};a.addSelected=function(d,c){a.inArray(d,a.clearText(c.text()))&&c.attr("selected",!0)};a.removeSelected=function(d,c){a.inArray(d,a.clearText(c.text()))||c.attr("selected",!1)};a.changeSelected=function(d,c){for(var b=a.select.children("option"),e=b.length-1;0<=e;e--)c(d,
3
- f(b[e]))};a.all_options=a.getOptions(e.children("option"));a.selected_options=a.getOptions(e.children("option:selected"));a.ul=f("<ul></ul>");e.before(a.ul);a.ul.css({"margin-left":"0px",width:"488px"});a.select.change(function(){a.changeTags()});a.start=function(){a.createTags()};return a}function l(e){var a=k(e);a.ajaxAddTag=function(d){var c=a.select.attr("controller");if(c){var b=a.select.attr("action")?a.select.attr("action"):"create",g=a.select.attr("param")?a.select.attr("param"):"title",b=
4
- "/"+(a.select.attr("controllers")?a.select.attr("controllers"):c+"s")+"/"+b,h={};h[c+"["+g+"]"]=d;f.ajax({url:b,dataType:"json",type:"POST",data:h,success:function(a){a?e.prepend('<option selected="selected" value="'+a.id+'">'+d+"</option>"):console.log("josn is null")}})}else console.log("select's controller param is null")};a.ul.tagit({allowSpaces:!0,availableTags:a.all_options,afterTagAdded:function(d,c){var b=c.tagLabel;all_options=a.getOptions(a.select.children("option"));a.inArray(all_options,
5
- b)?a.changeSelected(a.ul.tagit("assignedTags"),a.addSelected):a.ajaxAddTag(b)},afterTagRemoved:function(){a.changeSelected(a.ul.tagit("assignedTags"),a.removeSelected)}});return a}function m(e){var a=k(e);a.ul.tagit({allowSpaces:!0,availableTags:a.all_options,tagLimit:1,afterTagAdded:function(d,c){var b=c.tagLabel;all_options=a.getOptions(a.select.children("option"));a.inArray(all_options,b)?(a.changeSelected(a.ul.tagit("assignedTags"),a.addSelected),a.ul.parents(".control-group").removeClass("error"),
6
- a.ul.parents(".control-group").addClass("success"),a.ul.parents(".control-group").find(".help-inline").text("Success!")):(a.ul.tagit("removeAll"),a.ul.parents(".control-group").removeClass("success"),a.ul.parents(".control-group").addClass("error"),a.ul.parents(".control-group").find(".help-inline").text("You should choice one career."));1==a.ul.tagit("assignedTags").length&&(a.ul.find(".ui-autocomplete-input").attr("disabled","disabled"),a.select.focus())},afterTagRemoved:function(){a.changeSelected(a.ul.tagit("assignedTags"),
7
- a.removeSelected);1>a.ul.tagit("assignedTags").length&&a.ul.find(".ui-autocomplete-input").removeAttr("disabled")}});return a}for(var h=f(".smart_tag"),g=h.length-1;0<=g;g--){var j=l(f(h[g]));j.start()}h=f(".single_choice");for(g=h.length-1;0<=g;g--)j=m(f(h[g])),j.start()})})(window.jQuery);
3
+ f(b[e]))};a.all_options=a.getOptions(e.children("option"));a.selected_options=a.getOptions(e.children("option:selected"));a.ul=f("<ul></ul>");e.before(a.ul);a.ul.css({"margin-left":"0px",width:"488px"});a.select.change(function(){a.changeTags()});a.start=function(){a.createTags();a.is_start=!0};return a}function l(e){var a=k(e);a.is_add=a.select.attr("is_add")?a.select.attr("is_add"):!0;a.ajaxAddTag=function(d){var c=a.select.attr("controller");if(c){var b=a.select.attr("action")?a.select.attr("action"):
4
+ "create",g=a.select.attr("param")?a.select.attr("param"):"title",b="/"+(a.select.attr("controllers")?a.select.attr("controllers"):c+"s")+"/"+b,h={};h[c+"["+g+"]"]=d;f.ajax({url:b,dataType:"json",type:"POST",data:h,success:function(a){a?e.prepend('<option selected="selected" value="'+a.id+'">'+d+"</option>"):console.log("josn is null")}})}else console.log("select's controller param is null")};a.ul.tagit({allowSpaces:!0,availableTags:a.all_options,afterTagAdded:function(d,c){var b=c.tagLabel;all_options=
5
+ a.getOptions(a.select.children("option"));a.ul.parents(".control-group").removeClass("error");a.inArray(all_options,b)?a.changeSelected(a.ul.tagit("assignedTags"),a.addSelected):!0===a.is_add?a.ajaxAddTag(b):(a.ul.tagit("removeTagByLabel",b),a.ul.parents(".control-group").addClass("error"))},afterTagRemoved:function(){a.changeSelected(a.ul.tagit("assignedTags"),a.removeSelected)}});return a}function m(e){var a=k(e);a.ul.tagit({allowSpaces:!0,availableTags:a.all_options,tagLimit:1,afterTagAdded:function(d,
6
+ c){var b=c.tagLabel;all_options=a.getOptions(a.select.children("option"));a.inArray(all_options,b)?(a.changeSelected(a.ul.tagit("assignedTags"),a.addSelected),a.ul.parents(".control-group").removeClass("error"),a.ul.parents(".control-group").addClass("success"),a.ul.parents(".control-group").find(".help-inline").text("Success!")):(a.ul.tagit("removeAll"),a.ul.parents(".control-group").removeClass("success"),a.ul.parents(".control-group").addClass("error"),a.ul.parents(".control-group").find(".help-inline").text("You should choice one career."));
7
+ 1==a.ul.tagit("assignedTags").length&&(a.ul.find(".ui-autocomplete-input").attr("disabled","disabled"),!0===a.is_start&&a.select.focus())},afterTagRemoved:function(){a.changeSelected(a.ul.tagit("assignedTags"),a.removeSelected);1>a.ul.tagit("assignedTags").length&&a.ul.find(".ui-autocomplete-input").removeAttr("disabled")}});return a}for(var h=f(".smart_tag"),g=h.length-1;0<=g;g--){var j=l(f(h[g]));j.start()}h=f(".single_choice");for(g=h.length-1;0<=g;g--)j=m(f(h[g])),j.start()})})(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.4.2
4
+ version: 0.5.4
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-05-07 00:00:00.000000000 Z
12
+ date: 2013-05-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jquery-ui-rails