awesome_nested_fields 0.6.2 → 0.6.4

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.
@@ -1,37 +1,37 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- awesome_nested_fields (0.6.2)
4
+ awesome_nested_fields (0.6.4)
5
5
  rails (>= 3.0.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- actionmailer (3.2.11)
11
- actionpack (= 3.2.11)
10
+ actionmailer (3.2.12)
11
+ actionpack (= 3.2.12)
12
12
  mail (~> 2.4.4)
13
- actionpack (3.2.11)
14
- activemodel (= 3.2.11)
15
- activesupport (= 3.2.11)
13
+ actionpack (3.2.12)
14
+ activemodel (= 3.2.12)
15
+ activesupport (= 3.2.12)
16
16
  builder (~> 3.0.0)
17
17
  erubis (~> 2.7.0)
18
18
  journey (~> 1.0.4)
19
- rack (~> 1.4.0)
19
+ rack (~> 1.4.5)
20
20
  rack-cache (~> 1.2)
21
21
  rack-test (~> 0.6.1)
22
22
  sprockets (~> 2.2.1)
23
- activemodel (3.2.11)
24
- activesupport (= 3.2.11)
23
+ activemodel (3.2.12)
24
+ activesupport (= 3.2.12)
25
25
  builder (~> 3.0.0)
26
- activerecord (3.2.11)
27
- activemodel (= 3.2.11)
28
- activesupport (= 3.2.11)
26
+ activerecord (3.2.12)
27
+ activemodel (= 3.2.12)
28
+ activesupport (= 3.2.12)
29
29
  arel (~> 3.0.2)
30
30
  tzinfo (~> 0.3.29)
31
- activeresource (3.2.11)
32
- activemodel (= 3.2.11)
33
- activesupport (= 3.2.11)
34
- activesupport (3.2.11)
31
+ activeresource (3.2.12)
32
+ activemodel (= 3.2.12)
33
+ activesupport (= 3.2.12)
34
+ activesupport (3.2.12)
35
35
  i18n (~> 0.6)
36
36
  multi_json (~> 1.0)
37
37
  ansi (1.4.1)
@@ -42,38 +42,38 @@ GEM
42
42
  hike (1.2.1)
43
43
  i18n (0.6.1)
44
44
  journey (1.0.4)
45
- json (1.7.6)
45
+ json (1.7.7)
46
46
  mail (2.4.4)
47
47
  i18n (>= 0.4.0)
48
48
  mime-types (~> 1.16)
49
49
  treetop (~> 1.4.8)
50
- mime-types (1.19)
51
- multi_json (1.5.0)
50
+ mime-types (1.21)
51
+ multi_json (1.6.1)
52
52
  polyglot (0.3.3)
53
- rack (1.4.3)
53
+ rack (1.4.5)
54
54
  rack-cache (1.2)
55
55
  rack (>= 0.4)
56
- rack-ssl (1.3.2)
56
+ rack-ssl (1.3.3)
57
57
  rack
58
58
  rack-test (0.6.2)
59
59
  rack (>= 1.0)
60
- rails (3.2.11)
61
- actionmailer (= 3.2.11)
62
- actionpack (= 3.2.11)
63
- activerecord (= 3.2.11)
64
- activeresource (= 3.2.11)
65
- activesupport (= 3.2.11)
60
+ rails (3.2.12)
61
+ actionmailer (= 3.2.12)
62
+ actionpack (= 3.2.12)
63
+ activerecord (= 3.2.12)
64
+ activeresource (= 3.2.12)
65
+ activesupport (= 3.2.12)
66
66
  bundler (~> 1.0)
67
- railties (= 3.2.11)
68
- railties (3.2.11)
69
- actionpack (= 3.2.11)
70
- activesupport (= 3.2.11)
67
+ railties (= 3.2.12)
68
+ railties (3.2.12)
69
+ actionpack (= 3.2.12)
70
+ activesupport (= 3.2.12)
71
71
  rack-ssl (~> 1.3.2)
72
72
  rake (>= 0.8.7)
73
73
  rdoc (~> 3.4)
74
74
  thor (>= 0.14.6, < 2.0)
75
75
  rake (10.0.3)
76
- rdoc (3.12)
76
+ rdoc (3.12.1)
77
77
  json (~> 1.4)
78
78
  rspec (2.7.0)
79
79
  rspec-core (~> 2.7.0)
@@ -88,7 +88,7 @@ GEM
88
88
  multi_json (~> 1.0)
89
89
  rack (~> 1.0)
90
90
  tilt (~> 1.1, != 1.3.0)
91
- thor (0.16.0)
91
+ thor (0.17.0)
92
92
  tilt (1.3.3)
93
93
  treetop (1.4.12)
94
94
  polyglot
data/README.md CHANGED
@@ -254,8 +254,7 @@ TODO
254
254
 
255
255
  Donation
256
256
  --------
257
- [![Pledgie](https://www.pledgie.com/campaigns/18414.png)][pledgie]
258
- [pledgie]: http://www.pledgie.com/campaigns/18414
257
+ [![Paypal Donation](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RK546KAJQ539U)
259
258
 
260
259
  Copyleft
261
260
  --------
@@ -1,3 +1,3 @@
1
1
  module AwesomeNestedFields
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.4"
3
3
  end
@@ -1,4 +1,6 @@
1
1
  (function($) {
2
+ 'use strict';
3
+
2
4
  /**
3
5
  *
4
6
  * Awesome Nested Fields
@@ -7,7 +9,7 @@
7
9
  * https://github.com/lailsonbm/awesome_nested_fields
8
10
  *
9
11
  */
10
-
12
+
11
13
  var defaultSettings = {
12
14
  beforeInsert: function(item, callback) { callback() },
13
15
  afterInsert: function(item) {},
@@ -23,11 +25,11 @@
23
25
  newItemIndex: 'new_nested_item',
24
26
  unescapeTemplate: true
25
27
  };
26
-
28
+
27
29
  // PUBLIC API
28
30
  var methods = {
29
31
  init: function(options) {
30
- return this.each(function() {
32
+ return this.each(function() {
31
33
  var $this = $(this);
32
34
  if($this.data('nested-fields.options')) {
33
35
  log('Nested fields already defined for this element. If you want to redefine options, destroy it and init again.');
@@ -39,40 +41,40 @@
39
41
  options.emptyTemplate = $(options.emptyTemplateSelector, $this);
40
42
  options.container = $(options.containerSelector, $this);
41
43
  options.add = $(options.addSelector, $this);
42
- $this.data('nested-fields.options', options);
44
+ $this.data('nested-fields.options', options);
43
45
 
44
46
  bindInsertToAdd(options);
45
47
  bindRemoveToItems(options, $this);
46
48
  });
47
49
  },
48
-
50
+
49
51
  insert: function(callback, options) {
50
52
  options = $.extend({}, getOptions(this), options);
51
53
  return insertItemWithCallbacks(callback, options);
52
54
  },
53
-
55
+
54
56
  remove: function(element, options) {
55
57
  options = $.extend({}, getOptions(this), options);
56
58
  return removeItemWithCallbacks(element, options);
57
59
  },
58
-
60
+
59
61
  removeAll: function(options) {
60
62
  options = $.extend({}, getOptions(this), options);
61
63
  $(methods.items.apply(this)).each(function(i, el) {
62
64
  methods.remove(el, options);
63
65
  });
64
66
  },
65
-
67
+
66
68
  items: function() {
67
69
  return findItems(getOptions(this));
68
70
  },
69
-
71
+
70
72
  destroy: function() {
71
73
  $(this).removeData('nested-fields.options');
72
74
  $('*', this).unbind('.nested-fields');
73
75
  }
74
76
  };
75
-
77
+
76
78
  $.fn.nestedFields = function(method) {
77
79
  if (methods[method]) {
78
80
  return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
@@ -82,9 +84,9 @@
82
84
  $.error('Method ' + method + ' does not exist on jQuery.nestedFields');
83
85
  }
84
86
  };
85
-
87
+
86
88
  // Initialization functions
87
-
89
+
88
90
  function getOptions(element) {
89
91
  var $element = $(element);
90
92
  while($element.length > 0) {
@@ -97,26 +99,26 @@
97
99
  }
98
100
  return null;
99
101
  }
100
-
102
+
101
103
  function bindInsertToAdd(options) {
102
104
  options.add.bind('click.nested-fields', function(e) {
103
105
  e.preventDefault();
104
106
  insertItemWithCallbacks(null, options);
105
107
  });
106
108
  }
107
-
109
+
108
110
  function bindRemoveToItems(options, $this) {
109
111
  $(options.itemSelector, $this).each(function(i, item) {
110
112
  bindRemoveToItem(item, options);
111
113
  });
112
114
  }
113
-
115
+
114
116
  // Insertion functions
115
-
117
+
116
118
  function prepareTemplate(options) {
117
119
  var regexp = new RegExp(options.newItemIndex, 'g');
118
120
  var newId = new Date().getTime();
119
-
121
+
120
122
  var contents = options.itemTemplate.html();
121
123
  if(options['unescapeTemplate']) {
122
124
  contents = unescape_html_tags(contents);
@@ -124,15 +126,15 @@
124
126
  var newItem = $(contents.replace(regexp, newId));
125
127
  newItem.attr('data-new-record', true);
126
128
  newItem.attr('data-record-id', newId);
127
-
129
+
128
130
  bindRemoveToItem(newItem, options);
129
-
131
+
130
132
  return newItem;
131
133
  }
132
-
133
- function insertItemWithCallbacks(onInsertCallback, options) {
134
+
135
+ function insertItemWithCallbacks(onInsertCallback, options) {
134
136
  var newItem = prepareTemplate(options);
135
-
137
+
136
138
  function insert() {
137
139
  if(onInsertCallback) {
138
140
  onInsertCallback(newItem);
@@ -140,8 +142,8 @@
140
142
  removeEmpty(options);
141
143
  options.container.append(newItem);
142
144
  }
143
-
144
- if(!options.skipBefore) {
145
+
146
+ if(!options.skipBefore) {
145
147
  options.beforeInsert(newItem, insert);
146
148
  if(options.beforeInsert.length <= 1) {
147
149
  insert();
@@ -149,20 +151,20 @@
149
151
  } else {
150
152
  insert();
151
153
  }
152
-
154
+
153
155
  if(!options.skipAfter) {
154
156
  options.afterInsert(newItem);
155
157
  }
156
-
158
+
157
159
  return newItem;
158
160
  }
159
-
161
+
160
162
  function removeEmpty(options) {
161
163
  findEmpty(options).remove();
162
164
  }
163
-
165
+
164
166
  // Removal functions
165
-
167
+
166
168
  function removeItemWithCallbacks(element, options) {
167
169
  function remove() {
168
170
  if($element.attr('data-new-record')) { // record is new
@@ -173,7 +175,7 @@
173
175
  }
174
176
  insertEmpty(options);
175
177
  }
176
-
178
+
177
179
  var $element = $(element);
178
180
  if(!options.skipBefore) {
179
181
  options.beforeRemove($element, remove);
@@ -183,28 +185,30 @@
183
185
  } else {
184
186
  remove();
185
187
  }
186
-
188
+
187
189
  if(!options.skipAfter) {
188
190
  options.afterRemove($element);
189
191
  }
190
-
192
+
191
193
  return $element;
192
194
  }
193
-
195
+
194
196
  function insertEmpty(options) {
195
197
  if(findItems(options).length === 0) {
196
198
  var contents = options.emptyTemplate.html();
197
- if(options['unescapeTemplate']) {
198
- contents = unescape_html_tags(contents);
199
+ if(contents) {
200
+ if(options['unescapeTemplate']) {
201
+ contents = unescape_html_tags(contents);
202
+ }
203
+ options.container.append(contents);
199
204
  }
200
- options.container.append(contents);
201
205
  }
202
206
  }
203
-
207
+
204
208
  function bindRemoveToItem(item, options) {
205
209
  var removeHandler = $(item).find(options.removeSelector);
206
210
  var needsConfirmation = removeHandler.attr('data-confirm');
207
-
211
+
208
212
  var event = needsConfirmation ? 'confirm:complete' : 'click';
209
213
  removeHandler.bind(event + '.nested-fields', function(e, confirmed) {
210
214
  e.preventDefault();
@@ -214,29 +218,29 @@
214
218
  return false;
215
219
  });
216
220
  }
217
-
221
+
218
222
  // Find functions
219
-
223
+
220
224
  function findItems(options) {
221
225
  return options.container.find(options.itemSelector + ':visible');
222
226
  }
223
-
227
+
224
228
  function findEmpty(options) {
225
229
  return options.container.find(options.emptySelector);
226
230
  }
227
-
231
+
228
232
  // Utility functions
229
-
233
+
230
234
  function unescape_html_tags(html) {
231
235
  var e = document.createElement('div');
232
236
  e.innerHTML = html;
233
237
  return e.childNodes.length === 0 ? "" : jQuery.trim(e.childNodes[0].nodeValue);
234
238
  }
235
-
239
+
236
240
  function log(msg) {
237
241
  if(console && console.log) {
238
242
  console.log(msg);
239
243
  }
240
244
  }
241
-
245
+
242
246
  })(jQuery);
@@ -4,4 +4,4 @@
4
4
  * Requires jquery-ujs adapter.
5
5
  * https://github.com/lailsonbm/awesome_nested_fields
6
6
  */
7
- (function(h){var i={beforeInsert:function(q,r){r()},afterInsert:function(q){},beforeRemove:function(q,r){r()},afterRemove:function(q){},itemTemplateSelector:".item.template",emptyTemplateSelector:".empty.template",containerSelector:".items, .container",itemSelector:".item",emptySelector:".empty",addSelector:".add",removeSelector:".remove",newItemIndex:"new_nested_item",unescapeTemplate:true};var d={init:function(q){return this.each(function(){var r=h(this);if(r.data("nested-fields.options")){g("Nested fields already defined for this element. If you want to redefine options, destroy it and init again.");return r}q=h.extend({},i,q);q.itemTemplate=h(q.itemTemplateSelector,r);q.emptyTemplate=h(q.emptyTemplateSelector,r);q.container=h(q.containerSelector,r);q.add=h(q.addSelector,r);r.data("nested-fields.options",q);l(q);b(q,r)})},insert:function(r,q){q=h.extend({},j(this),q);return f(r,q)},remove:function(r,q){q=h.extend({},j(this),q);return e(r,q)},removeAll:function(q){q=h.extend({},j(this),q);h(d.items.apply(this)).each(function(r,s){d.remove(s,q)})},items:function(){return c(j(this))},destroy:function(){h(this).removeData("nested-fields.options");h("*",this).unbind(".nested-fields")}};h.fn.nestedFields=function(q){if(d[q]){return d[q].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof q==="object"||!q){return d.init.apply(this,arguments)}else{h.error("Method "+q+" does not exist on jQuery.nestedFields")}}};function j(r){var q=h(r);while(q.length>0){var s=q.data("nested-fields.options");if(s){return s}else{q=q.parent()}}return null}function l(q){q.add.bind("click.nested-fields",function(r){r.preventDefault();f(null,q)})}function b(q,r){h(q.itemSelector,r).each(function(s,t){k(t,q)})}function m(r){var u=new RegExp(r.newItemIndex,"g");var q=new Date().getTime();var t=r.itemTemplate.html();if(r.unescapeTemplate){t=o(t)}var s=h(t.replace(u,q));s.attr("data-new-record",true);s.attr("data-record-id",q);k(s,r);return s}function f(q,r){var s=m(r);function t(){if(q){q(s)}a(r);r.container.append(s)}if(!r.skipBefore){r.beforeInsert(s,t);if(r.beforeInsert.length<=1){t()}}else{t()}if(!r.skipAfter){r.afterInsert(s)}return s}function a(q){p(q).remove()}function e(t,s){function q(){if(r.attr("data-new-record")){r.remove()}else{r.find("INPUT[name$='[_destroy]']").val("true");r.hide()}n(s)}var r=h(t);if(!s.skipBefore){s.beforeRemove(r,q);if(s.beforeRemove.length<=1){q()}}else{q()}if(!s.skipAfter){s.afterRemove(r)}return r}function n(q){if(c(q).length===0){var r=q.emptyTemplate.html();if(q.unescapeTemplate){r=o(r)}q.container.append(r)}}function k(t,r){var q=h(t).find(r.removeSelector);var u=q.attr("data-confirm");var s=u?"confirm:complete":"click";q.bind(s+".nested-fields",function(v,w){v.preventDefault();if(w===undefined||w===true){e(t,r)}})}function c(q){return q.container.find(q.itemSelector+":visible")}function p(q){return q.container.find(q.emptySelector)}function o(q){var r=document.createElement("div");r.innerHTML=q;return r.childNodes.length===0?"":jQuery.trim(r.childNodes[0].nodeValue)}function g(q){if(console&&console.log){console.log(q)}}})(jQuery);
7
+ (function($){"use strict";var defaultSettings={beforeInsert:function(item,callback){callback()},afterInsert:function(item){},beforeRemove:function(item,callback){callback()},afterRemove:function(item){},itemTemplateSelector:".item.template",emptyTemplateSelector:".empty.template",containerSelector:".items, .container",itemSelector:".item",emptySelector:".empty",addSelector:".add",removeSelector:".remove",newItemIndex:"new_nested_item",unescapeTemplate:true};var methods={init:function(options){return this.each(function(){var $this=$(this);if($this.data("nested-fields.options")){log("Nested fields already defined for this element. If you want to redefine options, destroy it and init again.");return $this}options=$.extend({},defaultSettings,options);options.itemTemplate=$(options.itemTemplateSelector,$this);options.emptyTemplate=$(options.emptyTemplateSelector,$this);options.container=$(options.containerSelector,$this);options.add=$(options.addSelector,$this);$this.data("nested-fields.options",options);bindInsertToAdd(options);bindRemoveToItems(options,$this)})},insert:function(callback,options){options=$.extend({},getOptions(this),options);return insertItemWithCallbacks(callback,options)},remove:function(element,options){options=$.extend({},getOptions(this),options);return removeItemWithCallbacks(element,options)},removeAll:function(options){options=$.extend({},getOptions(this),options);$(methods.items.apply(this)).each(function(i,el){methods.remove(el,options)})},items:function(){return findItems(getOptions(this))},destroy:function(){$(this).removeData("nested-fields.options");$("*",this).unbind(".nested-fields")}};$.fn.nestedFields=function(method){if(methods[method]){return methods[method].apply(this,Array.prototype.slice.call(arguments,1))}else if(typeof method==="object"||!method){return methods.init.apply(this,arguments)}else{$.error("Method "+method+" does not exist on jQuery.nestedFields")}};function getOptions(element){var $element=$(element);while($element.length>0){var data=$element.data("nested-fields.options");if(data){return data}else{$element=$element.parent()}}return null}function bindInsertToAdd(options){options.add.bind("click.nested-fields",function(e){e.preventDefault();insertItemWithCallbacks(null,options)})}function bindRemoveToItems(options,$this){$(options.itemSelector,$this).each(function(i,item){bindRemoveToItem(item,options)})}function prepareTemplate(options){var regexp=new RegExp(options.newItemIndex,"g");var newId=(new Date).getTime();var contents=options.itemTemplate.html();if(options["unescapeTemplate"]){contents=unescape_html_tags(contents)}var newItem=$(contents.replace(regexp,newId));newItem.attr("data-new-record",true);newItem.attr("data-record-id",newId);bindRemoveToItem(newItem,options);return newItem}function insertItemWithCallbacks(onInsertCallback,options){var newItem=prepareTemplate(options);function insert(){if(onInsertCallback){onInsertCallback(newItem)}removeEmpty(options);options.container.append(newItem)}if(!options.skipBefore){options.beforeInsert(newItem,insert);if(options.beforeInsert.length<=1){insert()}}else{insert()}if(!options.skipAfter){options.afterInsert(newItem)}return newItem}function removeEmpty(options){findEmpty(options).remove()}function removeItemWithCallbacks(element,options){function remove(){if($element.attr("data-new-record")){$element.remove()}else{$element.find("INPUT[name$='[_destroy]']").val("true");$element.hide()}insertEmpty(options)}var $element=$(element);if(!options.skipBefore){options.beforeRemove($element,remove);if(options.beforeRemove.length<=1){remove()}}else{remove()}if(!options.skipAfter){options.afterRemove($element)}return $element}function insertEmpty(options){if(findItems(options).length===0){var contents=options.emptyTemplate.html();if(contents){if(options["unescapeTemplate"]){contents=unescape_html_tags(contents)}options.container.append(contents)}}}function bindRemoveToItem(item,options){var removeHandler=$(item).find(options.removeSelector);var needsConfirmation=removeHandler.attr("data-confirm");var event=needsConfirmation?"confirm:complete":"click";removeHandler.bind(event+".nested-fields",function(e,confirmed){e.preventDefault();if(confirmed===undefined||confirmed===true){removeItemWithCallbacks(item,options)}return false})}function findItems(options){return options.container.find(options.itemSelector+":visible")}function findEmpty(options){return options.container.find(options.emptySelector)}function unescape_html_tags(html){var e=document.createElement("div");e.innerHTML=html;return e.childNodes.length===0?"":jQuery.trim(e.childNodes[0].nodeValue)}function log(msg){if(console&&console.log){console.log(msg)}}})(jQuery);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awesome_nested_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.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-02-03 00:00:00.000000000 Z
12
+ date: 2013-02-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -113,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
113
  version: '0'
114
114
  segments:
115
115
  - 0
116
- hash: -2541328998417105626
116
+ hash: -3562572014335822589
117
117
  required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  none: false
119
119
  requirements: