awesome_nested_fields 0.6.2 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock
CHANGED
@@ -1,37 +1,37 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
awesome_nested_fields (0.6.
|
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
|
-
actionpack (= 3.2.
|
10
|
+
actionmailer (3.2.12)
|
11
|
+
actionpack (= 3.2.12)
|
12
12
|
mail (~> 2.4.4)
|
13
|
-
actionpack (3.2.
|
14
|
-
activemodel (= 3.2.
|
15
|
-
activesupport (= 3.2.
|
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.
|
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.
|
24
|
-
activesupport (= 3.2.
|
23
|
+
activemodel (3.2.12)
|
24
|
+
activesupport (= 3.2.12)
|
25
25
|
builder (~> 3.0.0)
|
26
|
-
activerecord (3.2.
|
27
|
-
activemodel (= 3.2.
|
28
|
-
activesupport (= 3.2.
|
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.
|
32
|
-
activemodel (= 3.2.
|
33
|
-
activesupport (= 3.2.
|
34
|
-
activesupport (3.2.
|
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.
|
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.
|
51
|
-
multi_json (1.
|
50
|
+
mime-types (1.21)
|
51
|
+
multi_json (1.6.1)
|
52
52
|
polyglot (0.3.3)
|
53
|
-
rack (1.4.
|
53
|
+
rack (1.4.5)
|
54
54
|
rack-cache (1.2)
|
55
55
|
rack (>= 0.4)
|
56
|
-
rack-ssl (1.3.
|
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.
|
61
|
-
actionmailer (= 3.2.
|
62
|
-
actionpack (= 3.2.
|
63
|
-
activerecord (= 3.2.
|
64
|
-
activeresource (= 3.2.
|
65
|
-
activesupport (= 3.2.
|
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.
|
68
|
-
railties (3.2.
|
69
|
-
actionpack (= 3.2.
|
70
|
-
activesupport (= 3.2.
|
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.
|
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
|
-
[![
|
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,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(
|
198
|
-
|
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(
|
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.
|
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-
|
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: -
|
116
|
+
hash: -3562572014335822589
|
117
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
118
|
none: false
|
119
119
|
requirements:
|