cocooned 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +76 -14
- data/app/assets/javascripts/cocoon.js +1 -0
- data/app/assets/javascripts/cocooned.js +449 -3
- data/app/assets/stylesheets/cocoon.css +2 -0
- data/cocooned.gemspec +3 -1
- data/lib/cocooned/version.rb +1 -1
- metadata +2 -18
- data/.gitignore +0 -15
- data/.rspec +0 -2
- data/.travis.yml +0 -14
- data/Gemfile +0 -16
- data/Gemfile.lock +0 -194
- data/app/assets/javascripts/cocooned/core.js +0 -284
- data/app/assets/javascripts/cocooned/jquery/onload.js +0 -10
- data/app/assets/javascripts/cocooned/jquery/plugin.js +0 -20
- data/app/assets/javascripts/cocooned/plugins/limit.js +0 -22
- data/app/assets/javascripts/cocooned/plugins/reorderable.js +0 -101
- data/config/linters/js.json +0 -50
- data/config/linters/ruby.yml +0 -16
- data/gemfiles/Gemfile.rails-4 +0 -8
- data/gemfiles/Gemfile.rails-5 +0 -8
- data/package.json +0 -24
- data/yarn.lock +0 -1052
data/cocooned.gemspec
CHANGED
@@ -23,7 +23,9 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.require_paths = ['lib']
|
25
25
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
-
f.match(%r{^(
|
26
|
+
f.match(%r{^(config|gemfiles|npm|spec)/}) ||
|
27
|
+
%w[.gitignore .rspec .travis.yml].include?(f) ||
|
28
|
+
%w[Gemfile Gemfile.lock package.json yarn.lock].include?(f)
|
27
29
|
end
|
28
30
|
|
29
31
|
spec.add_dependency 'rails', '>= 4.0', '<= 6.0'
|
data/lib/cocooned/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cocooned
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gaël-Ian Havard
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-08-
|
12
|
+
date: 2018-08-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -123,29 +123,15 @@ executables: []
|
|
123
123
|
extensions: []
|
124
124
|
extra_rdoc_files: []
|
125
125
|
files:
|
126
|
-
- ".gitignore"
|
127
|
-
- ".rspec"
|
128
|
-
- ".travis.yml"
|
129
|
-
- Gemfile
|
130
|
-
- Gemfile.lock
|
131
126
|
- History.md
|
132
127
|
- LICENSE
|
133
128
|
- README.md
|
134
129
|
- Rakefile
|
135
130
|
- app/assets/javascripts/cocoon.js
|
136
131
|
- app/assets/javascripts/cocooned.js
|
137
|
-
- app/assets/javascripts/cocooned/core.js
|
138
|
-
- app/assets/javascripts/cocooned/jquery/onload.js
|
139
|
-
- app/assets/javascripts/cocooned/jquery/plugin.js
|
140
|
-
- app/assets/javascripts/cocooned/plugins/limit.js
|
141
|
-
- app/assets/javascripts/cocooned/plugins/reorderable.js
|
142
132
|
- app/assets/stylesheets/cocoon.css
|
143
133
|
- app/assets/stylesheets/cocooned.css
|
144
134
|
- cocooned.gemspec
|
145
|
-
- config/linters/js.json
|
146
|
-
- config/linters/ruby.yml
|
147
|
-
- gemfiles/Gemfile.rails-4
|
148
|
-
- gemfiles/Gemfile.rails-5
|
149
135
|
- lib/cocooned.rb
|
150
136
|
- lib/cocooned/association_builder.rb
|
151
137
|
- lib/cocooned/helpers.rb
|
@@ -153,8 +139,6 @@ files:
|
|
153
139
|
- lib/cocooned/helpers/deprecate.rb
|
154
140
|
- lib/cocooned/railtie.rb
|
155
141
|
- lib/cocooned/version.rb
|
156
|
-
- package.json
|
157
|
-
- yarn.lock
|
158
142
|
homepage: http://github.com/notus-sh/cocooned
|
159
143
|
licenses:
|
160
144
|
- Apache-2.0
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source 'http://rubygems.org'
|
4
|
-
|
5
|
-
# Specify your gem's dependencies in cocooned.gemspec
|
6
|
-
gemspec
|
7
|
-
|
8
|
-
group :development, :test do
|
9
|
-
# Dummy app dependencies
|
10
|
-
gem 'jquery-rails'
|
11
|
-
gem 'rails', '~> 5.0'
|
12
|
-
gem 'sqlite3'
|
13
|
-
|
14
|
-
gem 'nokogiri'
|
15
|
-
gem 'simplecov', require: false
|
16
|
-
end
|
data/Gemfile.lock
DELETED
@@ -1,194 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
cocooned (1.3.0)
|
5
|
-
rails (>= 4.0, <= 6.0)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: http://rubygems.org/
|
9
|
-
specs:
|
10
|
-
actioncable (5.2.1)
|
11
|
-
actionpack (= 5.2.1)
|
12
|
-
nio4r (~> 2.0)
|
13
|
-
websocket-driver (>= 0.6.1)
|
14
|
-
actionmailer (5.2.1)
|
15
|
-
actionpack (= 5.2.1)
|
16
|
-
actionview (= 5.2.1)
|
17
|
-
activejob (= 5.2.1)
|
18
|
-
mail (~> 2.5, >= 2.5.4)
|
19
|
-
rails-dom-testing (~> 2.0)
|
20
|
-
actionpack (5.2.1)
|
21
|
-
actionview (= 5.2.1)
|
22
|
-
activesupport (= 5.2.1)
|
23
|
-
rack (~> 2.0)
|
24
|
-
rack-test (>= 0.6.3)
|
25
|
-
rails-dom-testing (~> 2.0)
|
26
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
27
|
-
actionview (5.2.1)
|
28
|
-
activesupport (= 5.2.1)
|
29
|
-
builder (~> 3.1)
|
30
|
-
erubi (~> 1.4)
|
31
|
-
rails-dom-testing (~> 2.0)
|
32
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
33
|
-
activejob (5.2.1)
|
34
|
-
activesupport (= 5.2.1)
|
35
|
-
globalid (>= 0.3.6)
|
36
|
-
activemodel (5.2.1)
|
37
|
-
activesupport (= 5.2.1)
|
38
|
-
activerecord (5.2.1)
|
39
|
-
activemodel (= 5.2.1)
|
40
|
-
activesupport (= 5.2.1)
|
41
|
-
arel (>= 9.0)
|
42
|
-
activestorage (5.2.1)
|
43
|
-
actionpack (= 5.2.1)
|
44
|
-
activerecord (= 5.2.1)
|
45
|
-
marcel (~> 0.3.1)
|
46
|
-
activesupport (5.2.1)
|
47
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
48
|
-
i18n (>= 0.7, < 2)
|
49
|
-
minitest (~> 5.1)
|
50
|
-
tzinfo (~> 1.1)
|
51
|
-
arel (9.0.0)
|
52
|
-
ast (2.4.0)
|
53
|
-
builder (3.2.3)
|
54
|
-
concurrent-ruby (1.0.5)
|
55
|
-
crass (1.0.4)
|
56
|
-
diff-lcs (1.3)
|
57
|
-
docile (1.3.1)
|
58
|
-
erubi (1.7.1)
|
59
|
-
globalid (0.4.1)
|
60
|
-
activesupport (>= 4.2.0)
|
61
|
-
i18n (1.1.0)
|
62
|
-
concurrent-ruby (~> 1.0)
|
63
|
-
jaro_winkler (1.5.1)
|
64
|
-
jasmine (3.2.0)
|
65
|
-
jasmine-core (= 3.2.0)
|
66
|
-
phantomjs
|
67
|
-
rack (>= 1.2.1)
|
68
|
-
rake
|
69
|
-
jasmine-core (3.2.0)
|
70
|
-
jquery-rails (4.3.3)
|
71
|
-
rails-dom-testing (>= 1, < 3)
|
72
|
-
railties (>= 4.2.0)
|
73
|
-
thor (>= 0.14, < 2.0)
|
74
|
-
json (2.1.0)
|
75
|
-
loofah (2.2.2)
|
76
|
-
crass (~> 1.0.2)
|
77
|
-
nokogiri (>= 1.5.9)
|
78
|
-
mail (2.7.0)
|
79
|
-
mini_mime (>= 0.1.1)
|
80
|
-
marcel (0.3.2)
|
81
|
-
mimemagic (~> 0.3.2)
|
82
|
-
method_source (0.9.0)
|
83
|
-
mimemagic (0.3.2)
|
84
|
-
mini_mime (1.0.1)
|
85
|
-
mini_portile2 (2.3.0)
|
86
|
-
minitest (5.11.3)
|
87
|
-
nio4r (2.3.1)
|
88
|
-
nokogiri (1.8.4)
|
89
|
-
mini_portile2 (~> 2.3.0)
|
90
|
-
parallel (1.12.1)
|
91
|
-
parser (2.5.1.2)
|
92
|
-
ast (~> 2.4.0)
|
93
|
-
phantomjs (2.1.1.0)
|
94
|
-
powerpack (0.1.2)
|
95
|
-
rack (2.0.5)
|
96
|
-
rack-test (1.1.0)
|
97
|
-
rack (>= 1.0, < 3)
|
98
|
-
rails (5.2.1)
|
99
|
-
actioncable (= 5.2.1)
|
100
|
-
actionmailer (= 5.2.1)
|
101
|
-
actionpack (= 5.2.1)
|
102
|
-
actionview (= 5.2.1)
|
103
|
-
activejob (= 5.2.1)
|
104
|
-
activemodel (= 5.2.1)
|
105
|
-
activerecord (= 5.2.1)
|
106
|
-
activestorage (= 5.2.1)
|
107
|
-
activesupport (= 5.2.1)
|
108
|
-
bundler (>= 1.3.0)
|
109
|
-
railties (= 5.2.1)
|
110
|
-
sprockets-rails (>= 2.0.0)
|
111
|
-
rails-dom-testing (2.0.3)
|
112
|
-
activesupport (>= 4.2.0)
|
113
|
-
nokogiri (>= 1.6)
|
114
|
-
rails-html-sanitizer (1.0.4)
|
115
|
-
loofah (~> 2.2, >= 2.2.2)
|
116
|
-
railties (5.2.1)
|
117
|
-
actionpack (= 5.2.1)
|
118
|
-
activesupport (= 5.2.1)
|
119
|
-
method_source
|
120
|
-
rake (>= 0.8.7)
|
121
|
-
thor (>= 0.19.0, < 2.0)
|
122
|
-
rainbow (3.0.0)
|
123
|
-
rake (12.3.1)
|
124
|
-
rspec (3.8.0)
|
125
|
-
rspec-core (~> 3.8.0)
|
126
|
-
rspec-expectations (~> 3.8.0)
|
127
|
-
rspec-mocks (~> 3.8.0)
|
128
|
-
rspec-core (3.8.0)
|
129
|
-
rspec-support (~> 3.8.0)
|
130
|
-
rspec-expectations (3.8.1)
|
131
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
132
|
-
rspec-support (~> 3.8.0)
|
133
|
-
rspec-mocks (3.8.0)
|
134
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
135
|
-
rspec-support (~> 3.8.0)
|
136
|
-
rspec-rails (3.8.0)
|
137
|
-
actionpack (>= 3.0)
|
138
|
-
activesupport (>= 3.0)
|
139
|
-
railties (>= 3.0)
|
140
|
-
rspec-core (~> 3.8.0)
|
141
|
-
rspec-expectations (~> 3.8.0)
|
142
|
-
rspec-mocks (~> 3.8.0)
|
143
|
-
rspec-support (~> 3.8.0)
|
144
|
-
rspec-support (3.8.0)
|
145
|
-
rubocop (0.58.2)
|
146
|
-
jaro_winkler (~> 1.5.1)
|
147
|
-
parallel (~> 1.10)
|
148
|
-
parser (>= 2.5, != 2.5.1.1)
|
149
|
-
powerpack (~> 0.1)
|
150
|
-
rainbow (>= 2.2.2, < 4.0)
|
151
|
-
ruby-progressbar (~> 1.7)
|
152
|
-
unicode-display_width (~> 1.0, >= 1.0.1)
|
153
|
-
ruby-progressbar (1.10.0)
|
154
|
-
simplecov (0.16.1)
|
155
|
-
docile (~> 1.1)
|
156
|
-
json (>= 1.8, < 3)
|
157
|
-
simplecov-html (~> 0.10.0)
|
158
|
-
simplecov-html (0.10.2)
|
159
|
-
sprockets (3.7.2)
|
160
|
-
concurrent-ruby (~> 1.0)
|
161
|
-
rack (> 1, < 3)
|
162
|
-
sprockets-rails (3.2.1)
|
163
|
-
actionpack (>= 4.0)
|
164
|
-
activesupport (>= 4.0)
|
165
|
-
sprockets (>= 3.0.0)
|
166
|
-
sqlite3 (1.3.13)
|
167
|
-
thor (0.20.0)
|
168
|
-
thread_safe (0.3.6)
|
169
|
-
tzinfo (1.2.5)
|
170
|
-
thread_safe (~> 0.1)
|
171
|
-
unicode-display_width (1.4.0)
|
172
|
-
websocket-driver (0.7.0)
|
173
|
-
websocket-extensions (>= 0.1.0)
|
174
|
-
websocket-extensions (0.1.3)
|
175
|
-
|
176
|
-
PLATFORMS
|
177
|
-
ruby
|
178
|
-
|
179
|
-
DEPENDENCIES
|
180
|
-
bundler (~> 1.16)
|
181
|
-
cocooned!
|
182
|
-
jasmine (~> 3.2)
|
183
|
-
jquery-rails
|
184
|
-
nokogiri
|
185
|
-
rails (~> 5.0)
|
186
|
-
rake
|
187
|
-
rspec (~> 3.8.0)
|
188
|
-
rspec-rails (~> 3.8.0)
|
189
|
-
rubocop
|
190
|
-
simplecov
|
191
|
-
sqlite3
|
192
|
-
|
193
|
-
BUNDLED WITH
|
194
|
-
1.16.2
|
@@ -1,284 +0,0 @@
|
|
1
|
-
var Cocooned = function (container, options) {
|
2
|
-
this.container = jQuery(container);
|
3
|
-
this.options = jQuery.extend({}, this.defaultOptions(), (options || {}));
|
4
|
-
|
5
|
-
// Autoload plugins
|
6
|
-
for (var moduleName in Cocooned.Plugins) {
|
7
|
-
if (Cocooned.Plugins.hasOwnProperty(moduleName)) {
|
8
|
-
var module = Cocooned.Plugins[moduleName];
|
9
|
-
var optionName = moduleName.charAt(0).toLowerCase() + moduleName.slice(1);
|
10
|
-
|
11
|
-
if (this.options[optionName]) {
|
12
|
-
for (var method in module) {
|
13
|
-
if (module.hasOwnProperty(method) && typeof module[method] === 'function') {
|
14
|
-
this[method] = module[method];
|
15
|
-
}
|
16
|
-
}
|
17
|
-
}
|
18
|
-
}
|
19
|
-
}
|
20
|
-
|
21
|
-
this.init();
|
22
|
-
};
|
23
|
-
|
24
|
-
Cocooned.Plugins = {};
|
25
|
-
Cocooned.prototype = {
|
26
|
-
|
27
|
-
elementsCounter: 0,
|
28
|
-
|
29
|
-
// Compatibility with Cocoon
|
30
|
-
// TODO: Remove in 2.0 (Only Cocoon namespaces).
|
31
|
-
namespaces: {
|
32
|
-
events: ['cocooned', 'cocoon']
|
33
|
-
},
|
34
|
-
|
35
|
-
// Compatibility with Cocoon
|
36
|
-
// TODO: Remove in 2.0 (Only Cocoon class names).
|
37
|
-
classes: {
|
38
|
-
// Actions link
|
39
|
-
add: ['cocooned-add', 'add_fields'],
|
40
|
-
remove: ['cocooned-remove', 'remove_fields'],
|
41
|
-
up: ['cocooned-move-up'],
|
42
|
-
down: ['cocooned-move-down'],
|
43
|
-
// Containers
|
44
|
-
container: ['cocooned-container'],
|
45
|
-
item: ['cocooned-item', 'nested-fields'],
|
46
|
-
},
|
47
|
-
|
48
|
-
defaultOptions: function () {
|
49
|
-
var options = {};
|
50
|
-
|
51
|
-
for (var moduleName in Cocooned.Plugins) {
|
52
|
-
if (Cocooned.Plugins.hasOwnProperty(moduleName)) {
|
53
|
-
var module = Cocooned.Plugins[moduleName];
|
54
|
-
var optionName = moduleName.charAt(0).toLowerCase() + moduleName.slice(1);
|
55
|
-
|
56
|
-
options[optionName] = module.defaultOptionValue;
|
57
|
-
}
|
58
|
-
}
|
59
|
-
|
60
|
-
return options;
|
61
|
-
},
|
62
|
-
|
63
|
-
notify: function (node, eventType, eventData) {
|
64
|
-
return !(this.namespaces.events.some(function(namespace) {
|
65
|
-
var namespacedEventType = [namespace, eventType].join(':');
|
66
|
-
var event = jQuery.Event(namespacedEventType, eventData);
|
67
|
-
|
68
|
-
node.trigger(event, [eventData.node, eventData.cocooned]);
|
69
|
-
|
70
|
-
return (event.isPropagationStopped() || event.isDefaultPrevented());
|
71
|
-
}));
|
72
|
-
},
|
73
|
-
|
74
|
-
selector: function (type, selector) {
|
75
|
-
var s = selector || '&';
|
76
|
-
return this.classes[type].map(function(klass) { return s.replace(/&/, '.' + klass); }).join(', ');
|
77
|
-
},
|
78
|
-
|
79
|
-
namespacedNativeEvents: function (type) {
|
80
|
-
var namespaces = this.namespaces.events.map(function(ns) { return '.' + ns; });
|
81
|
-
namespaces.unshift(type);
|
82
|
-
return namespaces.join('');
|
83
|
-
},
|
84
|
-
|
85
|
-
buildId: function () {
|
86
|
-
return (new Date().getTime() + this.elementsCounter++);
|
87
|
-
},
|
88
|
-
|
89
|
-
buildContentNode: function (content) {
|
90
|
-
var id = this.buildId();
|
91
|
-
var html = (content || this.content);
|
92
|
-
var braced = '[' + id + ']';
|
93
|
-
var underscored = '_' + id + '_';
|
94
|
-
|
95
|
-
['associations', 'association'].forEach(function (a) {
|
96
|
-
html = html.replace(this.regexps[a]['braced'], braced + '$1');
|
97
|
-
html = html.replace(this.regexps[a]['underscored'], underscored + '$1');
|
98
|
-
}, this);
|
99
|
-
|
100
|
-
return $(html);
|
101
|
-
},
|
102
|
-
|
103
|
-
getInsertionNode: function (adder) {
|
104
|
-
var $adder = $(adder);
|
105
|
-
var insertionNode = $adder.data('association-insertion-node');
|
106
|
-
var insertionTraversal = $adder.data('association-insertion-traversal');
|
107
|
-
|
108
|
-
if (!insertionNode) {
|
109
|
-
return $adder.parent();
|
110
|
-
}
|
111
|
-
|
112
|
-
if (typeof insertionNode === 'function') {
|
113
|
-
return insertionNode($adder);
|
114
|
-
}
|
115
|
-
|
116
|
-
if (insertionTraversal) {
|
117
|
-
return $adder[insertionTraversal](insertionNode);
|
118
|
-
}
|
119
|
-
|
120
|
-
return insertionNode === 'this' ? $adder : $(insertionNode);
|
121
|
-
},
|
122
|
-
|
123
|
-
getInsertionMethod: function (adder) {
|
124
|
-
var $adder = $(adder);
|
125
|
-
return $adder.data('association-insertion-method') || 'before';
|
126
|
-
},
|
127
|
-
|
128
|
-
getItems: function (selector) {
|
129
|
-
selector = selector || '';
|
130
|
-
var self = this;
|
131
|
-
return $(this.selector('item', selector), this.container).filter(function () {
|
132
|
-
return ($(this).closest(self.selector('container')).get(0) === self.container.get(0));
|
133
|
-
});
|
134
|
-
},
|
135
|
-
|
136
|
-
findContainer: function (addLink) {
|
137
|
-
var $adder = $(addLink);
|
138
|
-
var insertionNode = this.getInsertionNode($adder);
|
139
|
-
var insertionMethod = this.getInsertionMethod($adder);
|
140
|
-
|
141
|
-
switch (insertionMethod) {
|
142
|
-
case 'before':
|
143
|
-
case 'after':
|
144
|
-
case 'replaceWith':
|
145
|
-
return insertionNode.parent();
|
146
|
-
|
147
|
-
case 'append':
|
148
|
-
case 'prepend':
|
149
|
-
default:
|
150
|
-
return insertionNode;
|
151
|
-
}
|
152
|
-
},
|
153
|
-
|
154
|
-
findItem: function (removeLink) {
|
155
|
-
return $(removeLink).closest(this.selector('item'));
|
156
|
-
},
|
157
|
-
|
158
|
-
init: function () {
|
159
|
-
var self = this;
|
160
|
-
|
161
|
-
this.addLinks = $(this.selector('add')).filter(function () {
|
162
|
-
var container = self.findContainer(this);
|
163
|
-
return (container.get(0) === self.container.get(0));
|
164
|
-
});
|
165
|
-
|
166
|
-
var addLink = $(this.addLinks.get(0));
|
167
|
-
|
168
|
-
this.content = addLink.data('association-insertion-template');
|
169
|
-
this.regexps = {
|
170
|
-
association: {
|
171
|
-
braced: new RegExp('\\[new_' + addLink.data('association') + '\\](.*?\\s)', 'g'),
|
172
|
-
underscored: new RegExp('_new_' + addLink.data('association') + '_(\\w*)', 'g')
|
173
|
-
},
|
174
|
-
associations: {
|
175
|
-
braced: new RegExp('\\[new_' + addLink.data('associations') + '\\](.*?\\s)', 'g'),
|
176
|
-
underscored: new RegExp('_new_' + addLink.data('associations') + '_(\\w*)', 'g')
|
177
|
-
}
|
178
|
-
};
|
179
|
-
|
180
|
-
this.initUi();
|
181
|
-
this.bindEvents();
|
182
|
-
},
|
183
|
-
|
184
|
-
initUi: function () {
|
185
|
-
var self = this;
|
186
|
-
|
187
|
-
if (!this.container.attr('id')) {
|
188
|
-
this.container.attr('id', this.buildId());
|
189
|
-
}
|
190
|
-
this.container.addClass(this.classes['container'].join(' '));
|
191
|
-
|
192
|
-
$(function () { self.hideMarkedForDestruction(); });
|
193
|
-
$(document).on('page:load turbolinks:load', function () { self.hideMarkedForDestruction(); });
|
194
|
-
},
|
195
|
-
|
196
|
-
bindEvents: function () {
|
197
|
-
var self = this;
|
198
|
-
|
199
|
-
// Bind add links
|
200
|
-
this.addLinks.on(
|
201
|
-
this.namespacedNativeEvents('click'),
|
202
|
-
function (e) {
|
203
|
-
e.preventDefault();
|
204
|
-
self.add(this);
|
205
|
-
});
|
206
|
-
|
207
|
-
// Bind remove links
|
208
|
-
// (Binded on document instead of container to not bypass click handler defined in jquery_ujs)
|
209
|
-
$(document).on(
|
210
|
-
this.namespacedNativeEvents('click'),
|
211
|
-
this.selector('remove', '#' + this.container.attr('id') + ' &'),
|
212
|
-
function (e) {
|
213
|
-
e.preventDefault();
|
214
|
-
self.remove(this);
|
215
|
-
});
|
216
|
-
|
217
|
-
// Bind options events
|
218
|
-
$.each(this.options, function (name, value) {
|
219
|
-
var bindMethod = 'bind' + name.charAt(0).toUpperCase() + name.slice(1);
|
220
|
-
if (value && self[bindMethod]) {
|
221
|
-
self[bindMethod]();
|
222
|
-
}
|
223
|
-
});
|
224
|
-
},
|
225
|
-
|
226
|
-
add: function (adder) {
|
227
|
-
var $adder = $(adder);
|
228
|
-
var insertionMethod = this.getInsertionMethod($adder);
|
229
|
-
var insertionNode = this.getInsertionNode($adder);
|
230
|
-
var contentTemplate = $adder.data('association-insertion-template');
|
231
|
-
var count = parseInt($adder.data('count'), 10) || 1;
|
232
|
-
|
233
|
-
for (var i = 0; i < count; i++) {
|
234
|
-
var contentNode = this.buildContentNode(contentTemplate);
|
235
|
-
var eventData = { link: $adder, node: contentNode, cocooned: this };
|
236
|
-
var afterNode = (insertionMethod === 'replaceWith' ? contentNode : insertionNode);
|
237
|
-
|
238
|
-
// Insertion can be prevented through a 'cocooned:before-insert' event handler
|
239
|
-
if (!this.notify(insertionNode, 'before-insert', eventData)) {
|
240
|
-
return false;
|
241
|
-
}
|
242
|
-
|
243
|
-
insertionNode[insertionMethod](contentNode);
|
244
|
-
|
245
|
-
this.notify(afterNode, 'after-insert', eventData);
|
246
|
-
}
|
247
|
-
},
|
248
|
-
|
249
|
-
remove: function (remover) {
|
250
|
-
var self = this;
|
251
|
-
var $remover = $(remover);
|
252
|
-
var nodeToDelete = this.findItem($remover);
|
253
|
-
var triggerNode = nodeToDelete.parent();
|
254
|
-
var eventData = { link: $remover, node: nodeToDelete, cocooned: this };
|
255
|
-
|
256
|
-
// Deletion can be prevented through a 'cocooned:before-remove' event handler
|
257
|
-
if (!this.notify(triggerNode, 'before-remove', eventData)) {
|
258
|
-
return false;
|
259
|
-
}
|
260
|
-
|
261
|
-
var timeout = triggerNode.data('remove-timeout') || 0;
|
262
|
-
|
263
|
-
setTimeout(function () {
|
264
|
-
if ($remover.hasClass('dynamic')) {
|
265
|
-
nodeToDelete.remove();
|
266
|
-
} else {
|
267
|
-
nodeToDelete.find('input[required], select[required]').each(function (index, element) {
|
268
|
-
$(element).removeAttr('required');
|
269
|
-
});
|
270
|
-
$remover.siblings('input[type=hidden][name$="[_destroy]"]').val('true');
|
271
|
-
nodeToDelete.hide();
|
272
|
-
}
|
273
|
-
self.notify(triggerNode, 'after-remove', eventData);
|
274
|
-
}, timeout);
|
275
|
-
},
|
276
|
-
|
277
|
-
hideMarkedForDestruction: function () {
|
278
|
-
var self = this;
|
279
|
-
$(this.selector('remove', '&.existing.destroyed'), this.container).each(function (i, removeLink) {
|
280
|
-
var node = self.findItem(removeLink);
|
281
|
-
node.hide();
|
282
|
-
});
|
283
|
-
}
|
284
|
-
};
|