image-picker-rails 0.1.4.1 → 0.2.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.
- checksums.yaml +4 -4
- data/lib/image-picker-rails/version.rb +1 -1
- data/vendor/assets/javascripts/image-picker.js +77 -37
- metadata +13 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f2d3e87dda1bfb153afc39eec11db1d708abe83
|
4
|
+
data.tar.gz: 6b2639122db2e69bca7e04928b5dd3e411e5622d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c46720348a0949ce06211b50c8abef1d2fb3b686effc3a4a67b4155eb170ab3eec68fc634cb4281dd9c6ee0ea4f5f3d01f85cdb346eed4f7dffa2a2a636c55e8
|
7
|
+
data.tar.gz: 0b955d6c04da03e1ba455a725fb76968d34ead8f0063d888979435fa2b59b69ba4e7c74cf39762ac9476d79facc4a2b1c79249d15f17701c6ed3b1ba5f2b8337
|
@@ -1,12 +1,13 @@
|
|
1
1
|
// Image Picker
|
2
2
|
// by Rodrigo Vera
|
3
3
|
//
|
4
|
-
// Version 0.
|
4
|
+
// Version 0.2.4
|
5
5
|
// Full source at https://github.com/rvera/image-picker
|
6
6
|
// MIT License, https://github.com/rvera/image-picker/blob/master/LICENSE
|
7
7
|
// Generated by CoffeeScript 1.4.0
|
8
8
|
(function() {
|
9
9
|
var ImagePicker, ImagePickerOption, both_array_are_equal, sanitized_options,
|
10
|
+
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
10
11
|
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
11
12
|
|
12
13
|
jQuery.fn.extend({
|
@@ -17,10 +18,12 @@
|
|
17
18
|
return this.each(function() {
|
18
19
|
var select;
|
19
20
|
select = jQuery(this);
|
20
|
-
select.
|
21
|
+
if (select.data("picker")) {
|
22
|
+
select.data("picker").destroy();
|
23
|
+
}
|
21
24
|
select.data("picker", new ImagePicker(this, sanitized_options(opts)));
|
22
25
|
if (opts.initialized != null) {
|
23
|
-
return opts.initialized();
|
26
|
+
return opts.initialized.call(select.data("picker"));
|
24
27
|
}
|
25
28
|
});
|
26
29
|
}
|
@@ -49,6 +52,8 @@
|
|
49
52
|
|
50
53
|
function ImagePicker(select_element, opts) {
|
51
54
|
this.opts = opts != null ? opts : {};
|
55
|
+
this.sync_picker_with_select = __bind(this.sync_picker_with_select, this);
|
56
|
+
|
52
57
|
this.select = jQuery(select_element);
|
53
58
|
this.multiple = this.select.attr("multiple") === "multiple";
|
54
59
|
if (this.select.data("limit") != null) {
|
@@ -57,14 +62,26 @@
|
|
57
62
|
this.build_and_append_picker();
|
58
63
|
}
|
59
64
|
|
65
|
+
ImagePicker.prototype.destroy = function() {
|
66
|
+
var option, _i, _len, _ref;
|
67
|
+
_ref = this.picker_options;
|
68
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
69
|
+
option = _ref[_i];
|
70
|
+
option.destroy();
|
71
|
+
}
|
72
|
+
this.picker.remove();
|
73
|
+
this.select.unbind("change");
|
74
|
+
this.select.removeData("picker");
|
75
|
+
return this.select.show();
|
76
|
+
};
|
77
|
+
|
60
78
|
ImagePicker.prototype.build_and_append_picker = function() {
|
79
|
+
var _this = this;
|
61
80
|
if (this.opts.hide_select) {
|
62
81
|
this.select.hide();
|
63
82
|
}
|
64
|
-
this.select.change({
|
65
|
-
|
66
|
-
}, function(event) {
|
67
|
-
return event.data.picker.sync_picker_with_select();
|
83
|
+
this.select.change(function() {
|
84
|
+
return _this.sync_picker_with_select();
|
68
85
|
});
|
69
86
|
if (this.picker != null) {
|
70
87
|
this.picker.remove();
|
@@ -90,27 +107,43 @@
|
|
90
107
|
};
|
91
108
|
|
92
109
|
ImagePicker.prototype.create_picker = function() {
|
93
|
-
var option, _i, _len, _ref;
|
94
110
|
this.picker = jQuery("<ul class='thumbnails image_picker_selector'></ul>");
|
95
|
-
this.picker_options =
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
111
|
+
this.picker_options = [];
|
112
|
+
this.recursively_parse_option_groups(this.select, this.picker);
|
113
|
+
return this.picker;
|
114
|
+
};
|
115
|
+
|
116
|
+
ImagePicker.prototype.recursively_parse_option_groups = function(scoped_dom, target_container) {
|
117
|
+
var container, option, option_group, _i, _j, _len, _len1, _ref, _ref1, _results;
|
118
|
+
_ref = scoped_dom.children("optgroup");
|
119
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
120
|
+
option_group = _ref[_i];
|
121
|
+
option_group = jQuery(option_group);
|
122
|
+
container = jQuery("<ul></ul>");
|
123
|
+
container.append(jQuery("<li class='group_title'>" + (option_group.attr("label")) + "</li>"));
|
124
|
+
target_container.append(jQuery("<li>").append(container));
|
125
|
+
this.recursively_parse_option_groups(option_group, container);
|
126
|
+
}
|
127
|
+
_ref1 = (function() {
|
128
|
+
var _k, _len1, _ref1, _results1;
|
129
|
+
_ref1 = scoped_dom.children("option");
|
130
|
+
_results1 = [];
|
131
|
+
for (_k = 0, _len1 = _ref1.length; _k < _len1; _k++) {
|
132
|
+
option = _ref1[_k];
|
133
|
+
_results1.push(new ImagePickerOption(option, this, this.opts));
|
102
134
|
}
|
103
|
-
return
|
135
|
+
return _results1;
|
104
136
|
}).call(this);
|
105
|
-
|
106
|
-
for (
|
107
|
-
option =
|
137
|
+
_results = [];
|
138
|
+
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
139
|
+
option = _ref1[_j];
|
140
|
+
this.picker_options.push(option);
|
108
141
|
if (!option.has_image()) {
|
109
142
|
continue;
|
110
143
|
}
|
111
|
-
|
144
|
+
_results.push(target_container.append(option.node));
|
112
145
|
}
|
113
|
-
return
|
146
|
+
return _results;
|
114
147
|
};
|
115
148
|
|
116
149
|
ImagePicker.prototype.has_implicit_blanks = function() {
|
@@ -138,34 +171,35 @@
|
|
138
171
|
};
|
139
172
|
|
140
173
|
ImagePicker.prototype.toggle = function(imagepicker_option) {
|
141
|
-
var new_values, old_values,
|
174
|
+
var new_values, old_values, selected_value;
|
142
175
|
old_values = this.selected_values();
|
176
|
+
selected_value = imagepicker_option.value().toString();
|
143
177
|
if (this.multiple) {
|
144
|
-
if (
|
145
|
-
|
178
|
+
if (__indexOf.call(this.selected_values(), selected_value) >= 0) {
|
179
|
+
new_values = this.selected_values();
|
180
|
+
new_values.splice(jQuery.inArray(selected_value, old_values), 1);
|
181
|
+
this.select.val([]);
|
182
|
+
this.select.val(new_values);
|
146
183
|
} else {
|
147
|
-
if (this.opts.limit != null) {
|
148
|
-
if (this.
|
149
|
-
|
150
|
-
} else if (this.opts.limit_reached != null) {
|
151
|
-
this.opts.limit_reached();
|
184
|
+
if ((this.opts.limit != null) && this.selected_values().length >= this.opts.limit) {
|
185
|
+
if (this.opts.limit_reached != null) {
|
186
|
+
this.opts.limit_reached.call(this.select);
|
152
187
|
}
|
153
188
|
} else {
|
154
|
-
|
189
|
+
this.select.val(this.selected_values().concat(selected_value));
|
155
190
|
}
|
156
191
|
}
|
157
192
|
} else {
|
158
193
|
if (this.has_implicit_blanks() && imagepicker_option.is_selected()) {
|
159
194
|
this.select.val("");
|
160
195
|
} else {
|
161
|
-
this.select.val(
|
196
|
+
this.select.val(selected_value);
|
162
197
|
}
|
163
198
|
}
|
164
|
-
|
165
|
-
if (!both_array_are_equal(old_values, new_values)) {
|
199
|
+
if (!both_array_are_equal(old_values, this.selected_values())) {
|
166
200
|
this.select.change();
|
167
201
|
if (this.opts.changed != null) {
|
168
|
-
return this.opts.changed();
|
202
|
+
return this.opts.changed.call(this.select, old_values, this.selected_values());
|
169
203
|
}
|
170
204
|
}
|
171
205
|
};
|
@@ -179,10 +213,16 @@
|
|
179
213
|
function ImagePickerOption(option_element, picker, opts) {
|
180
214
|
this.picker = picker;
|
181
215
|
this.opts = opts != null ? opts : {};
|
216
|
+
this.clicked = __bind(this.clicked, this);
|
217
|
+
|
182
218
|
this.option = jQuery(option_element);
|
183
219
|
this.create_node();
|
184
220
|
}
|
185
221
|
|
222
|
+
ImagePickerOption.prototype.destroy = function() {
|
223
|
+
return this.node.find(".thumbnail").unbind();
|
224
|
+
};
|
225
|
+
|
186
226
|
ImagePickerOption.prototype.has_image = function() {
|
187
227
|
return this.option.data("img-src") != null;
|
188
228
|
};
|
@@ -224,10 +264,10 @@
|
|
224
264
|
ImagePickerOption.prototype.clicked = function() {
|
225
265
|
this.picker.toggle(this);
|
226
266
|
if (this.opts.clicked != null) {
|
227
|
-
this.opts.clicked();
|
267
|
+
this.opts.clicked.call(this.picker.select, this);
|
228
268
|
}
|
229
269
|
if ((this.opts.selected != null) && this.is_selected()) {
|
230
|
-
return this.opts.selected();
|
270
|
+
return this.opts.selected.call(this.picker.select, this);
|
231
271
|
}
|
232
272
|
};
|
233
273
|
|
@@ -254,4 +294,4 @@
|
|
254
294
|
|
255
295
|
})();
|
256
296
|
|
257
|
-
}).call(this);
|
297
|
+
}).call(this);
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image-picker-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Airat Shigapov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: Image Picker is a simple jQuery plugin that transforms a select element
|
@@ -60,7 +60,7 @@ executables: []
|
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
-
- .gitignore
|
63
|
+
- ".gitignore"
|
64
64
|
- Gemfile
|
65
65
|
- LICENSE.txt
|
66
66
|
- README.md
|
@@ -80,19 +80,20 @@ require_paths:
|
|
80
80
|
- lib
|
81
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
82
|
requirements:
|
83
|
-
- -
|
83
|
+
- - ">="
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '0'
|
86
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- -
|
88
|
+
- - ">="
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '0'
|
91
91
|
requirements: []
|
92
92
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.
|
93
|
+
rubygems_version: 2.2.2
|
94
94
|
signing_key:
|
95
95
|
specification_version: 4
|
96
96
|
summary: Image Picker is a simple jQuery plugin that transforms a select element into
|
97
97
|
a more user friendly graphical interface.
|
98
98
|
test_files: []
|
99
|
+
has_rdoc:
|