image-picker-rails 0.1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1f0f04d7a4aef9ceebddd7dedd0d70bcca36c3d2
4
+ data.tar.gz: 5d855563e234c3bbe99ffe51776b092edf4e92cf
5
+ SHA512:
6
+ metadata.gz: 41e8359c1fc7dccb777ca1996910b5856ef866dc8ab51bc1ca78543a7dba568871744fb5f6190c51a7911ddebf6b51a45afce8b1d9f87aca9295c8e87146d3bf
7
+ data.tar.gz: 6afe24bea1a73a81be3dbeaa1950eb59d32acb321771d80a34dea17235e0d6f263a45a0e8fbaf69c9e387867a442781a6d268a810f5c8d9ca84db2f97f8bc0a2
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in image-picker-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Airat Shigapov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Image Picker for Rails
2
+
3
+ Image Picker is a simple jQuery plugin that transforms a select element into a more user friendly graphical interface.
4
+
5
+ https://github.com/rvera/image-picker originally authored by [Rodrigo Vera](http://rvera.github.io/)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'image-picker-rails'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install image-picker-rails
20
+
21
+ ## Usage
22
+
23
+ Add this line to app/assets/stylesheets/application.css
24
+
25
+ ``` css
26
+ *= require image-picker
27
+ ```
28
+
29
+ Add this line to app/assets/javascripts/application.js
30
+
31
+ ``` javascript
32
+ //= require image-picker
33
+ ```
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'image-picker-rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "image-picker-rails"
8
+ spec.version = Image::Picker::Rails::VERSION
9
+ spec.authors = ["Airat Shigapov"]
10
+ spec.email = ["airat@shigapov.me"]
11
+ spec.description = "Image Picker is a simple jQuery plugin that transforms a select element into a more user friendly graphical interface."
12
+ spec.summary = spec.description
13
+ spec.homepage = "https://github.com/airatshigapov/image-picker-rails"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "railties", ">= 3.0"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,8 @@
1
+ require "image-picker-rails/version"
2
+
3
+ module ImagePickerRails
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Image
2
+ module Picker
3
+ module Rails
4
+ VERSION = "0.1.4.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,257 @@
1
+ // Image Picker
2
+ // by Rodrigo Vera
3
+ //
4
+ // Version 0.1.4
5
+ // Full source at https://github.com/rvera/image-picker
6
+ // MIT License, https://github.com/rvera/image-picker/blob/master/LICENSE
7
+ // Generated by CoffeeScript 1.4.0
8
+ (function() {
9
+ var ImagePicker, ImagePickerOption, both_array_are_equal, sanitized_options,
10
+ __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
+ jQuery.fn.extend({
13
+ imagepicker: function(opts) {
14
+ if (opts == null) {
15
+ opts = {};
16
+ }
17
+ return this.each(function() {
18
+ var select;
19
+ select = jQuery(this);
20
+ select.next("ul.image_picker_selector").remove();
21
+ select.data("picker", new ImagePicker(this, sanitized_options(opts)));
22
+ if (opts.initialized != null) {
23
+ return opts.initialized();
24
+ }
25
+ });
26
+ }
27
+ });
28
+
29
+ sanitized_options = function(opts) {
30
+ var default_options;
31
+ default_options = {
32
+ hide_select: true,
33
+ show_label: false,
34
+ initialized: void 0,
35
+ changed: void 0,
36
+ clicked: void 0,
37
+ selected: void 0,
38
+ limit: void 0,
39
+ limit_reached: void 0
40
+ };
41
+ return jQuery.extend(default_options, opts);
42
+ };
43
+
44
+ both_array_are_equal = function(a, b) {
45
+ return jQuery(a).not(b).length === 0 && jQuery(b).not(a).length === 0;
46
+ };
47
+
48
+ ImagePicker = (function() {
49
+
50
+ function ImagePicker(select_element, opts) {
51
+ this.opts = opts != null ? opts : {};
52
+ this.select = jQuery(select_element);
53
+ this.multiple = this.select.attr("multiple") === "multiple";
54
+ if (this.select.data("limit") != null) {
55
+ this.opts.limit = parseInt(this.select.data("limit"));
56
+ }
57
+ this.build_and_append_picker();
58
+ }
59
+
60
+ ImagePicker.prototype.build_and_append_picker = function() {
61
+ if (this.opts.hide_select) {
62
+ this.select.hide();
63
+ }
64
+ this.select.change({
65
+ picker: this
66
+ }, function(event) {
67
+ return event.data.picker.sync_picker_with_select();
68
+ });
69
+ if (this.picker != null) {
70
+ this.picker.remove();
71
+ }
72
+ this.create_picker();
73
+ this.select.after(this.picker);
74
+ return this.sync_picker_with_select();
75
+ };
76
+
77
+ ImagePicker.prototype.sync_picker_with_select = function() {
78
+ var option, _i, _len, _ref, _results;
79
+ _ref = this.picker_options;
80
+ _results = [];
81
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
82
+ option = _ref[_i];
83
+ if (option.is_selected()) {
84
+ _results.push(option.mark_as_selected());
85
+ } else {
86
+ _results.push(option.unmark_as_selected());
87
+ }
88
+ }
89
+ return _results;
90
+ };
91
+
92
+ ImagePicker.prototype.create_picker = function() {
93
+ var option, _i, _len, _ref;
94
+ this.picker = jQuery("<ul class='thumbnails image_picker_selector'></ul>");
95
+ this.picker_options = (function() {
96
+ var _i, _len, _ref, _results;
97
+ _ref = this.select.find("option");
98
+ _results = [];
99
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
100
+ option = _ref[_i];
101
+ _results.push(new ImagePickerOption(option, this, this.opts));
102
+ }
103
+ return _results;
104
+ }).call(this);
105
+ _ref = this.picker_options;
106
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
107
+ option = _ref[_i];
108
+ if (!option.has_image()) {
109
+ continue;
110
+ }
111
+ this.picker.append(option.node);
112
+ }
113
+ return this.picker;
114
+ };
115
+
116
+ ImagePicker.prototype.has_implicit_blanks = function() {
117
+ var option;
118
+ return ((function() {
119
+ var _i, _len, _ref, _results;
120
+ _ref = this.picker_options;
121
+ _results = [];
122
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
123
+ option = _ref[_i];
124
+ if (option.is_blank() && !option.has_image()) {
125
+ _results.push(option);
126
+ }
127
+ }
128
+ return _results;
129
+ }).call(this)).length > 0;
130
+ };
131
+
132
+ ImagePicker.prototype.selected_values = function() {
133
+ if (this.multiple) {
134
+ return this.select.val() || [];
135
+ } else {
136
+ return [this.select.val()];
137
+ }
138
+ };
139
+
140
+ ImagePicker.prototype.toggle = function(imagepicker_option) {
141
+ var new_values, old_values, _ref;
142
+ old_values = this.selected_values();
143
+ if (this.multiple) {
144
+ if (_ref = imagepicker_option.value(), __indexOf.call(this.selected_values(), _ref) >= 0) {
145
+ imagepicker_option.option.prop("selected", false);
146
+ } else {
147
+ if (this.opts.limit != null) {
148
+ if (this.selected_values().length < this.opts.limit) {
149
+ imagepicker_option.option.prop("selected", true);
150
+ } else if (this.opts.limit_reached != null) {
151
+ this.opts.limit_reached();
152
+ }
153
+ } else {
154
+ imagepicker_option.option.prop("selected", true);
155
+ }
156
+ }
157
+ } else {
158
+ if (this.has_implicit_blanks() && imagepicker_option.is_selected()) {
159
+ this.select.val("");
160
+ } else {
161
+ this.select.val(imagepicker_option.value());
162
+ }
163
+ }
164
+ new_values = this.selected_values();
165
+ if (!both_array_are_equal(old_values, new_values)) {
166
+ this.select.change();
167
+ if (this.opts.changed != null) {
168
+ return this.opts.changed();
169
+ }
170
+ }
171
+ };
172
+
173
+ return ImagePicker;
174
+
175
+ })();
176
+
177
+ ImagePickerOption = (function() {
178
+
179
+ function ImagePickerOption(option_element, picker, opts) {
180
+ this.picker = picker;
181
+ this.opts = opts != null ? opts : {};
182
+ this.option = jQuery(option_element);
183
+ this.create_node();
184
+ }
185
+
186
+ ImagePickerOption.prototype.has_image = function() {
187
+ return this.option.data("img-src") != null;
188
+ };
189
+
190
+ ImagePickerOption.prototype.is_blank = function() {
191
+ return !((this.value() != null) && this.value() !== "");
192
+ };
193
+
194
+ ImagePickerOption.prototype.is_selected = function() {
195
+ var select_value;
196
+ select_value = this.picker.select.val();
197
+ if (this.picker.multiple) {
198
+ return jQuery.inArray(this.value(), select_value) >= 0;
199
+ } else {
200
+ return this.value() === select_value;
201
+ }
202
+ };
203
+
204
+ ImagePickerOption.prototype.mark_as_selected = function() {
205
+ return this.node.find(".thumbnail").addClass("selected");
206
+ };
207
+
208
+ ImagePickerOption.prototype.unmark_as_selected = function() {
209
+ return this.node.find(".thumbnail").removeClass("selected");
210
+ };
211
+
212
+ ImagePickerOption.prototype.value = function() {
213
+ return this.option.val();
214
+ };
215
+
216
+ ImagePickerOption.prototype.label = function() {
217
+ if (this.option.data("img-label")) {
218
+ return this.option.data("img-label");
219
+ } else {
220
+ return this.option.text();
221
+ }
222
+ };
223
+
224
+ ImagePickerOption.prototype.clicked = function() {
225
+ this.picker.toggle(this);
226
+ if (this.opts.clicked != null) {
227
+ this.opts.clicked();
228
+ }
229
+ if ((this.opts.selected != null) && this.is_selected()) {
230
+ return this.opts.selected();
231
+ }
232
+ };
233
+
234
+ ImagePickerOption.prototype.create_node = function() {
235
+ var image, thumbnail;
236
+ this.node = jQuery("<li/>");
237
+ image = jQuery("<img class='image_picker_image'/>");
238
+ image.attr("src", this.option.data("img-src"));
239
+ thumbnail = jQuery("<div class='thumbnail'>");
240
+ thumbnail.click({
241
+ option: this
242
+ }, function(event) {
243
+ return event.data.option.clicked();
244
+ });
245
+ thumbnail.append(image);
246
+ if (this.opts.show_label) {
247
+ thumbnail.append(jQuery("<p/>").html(this.label()));
248
+ }
249
+ this.node.append(thumbnail);
250
+ return this.node;
251
+ };
252
+
253
+ return ImagePickerOption;
254
+
255
+ })();
256
+
257
+ }).call(this);
@@ -0,0 +1,15 @@
1
+ ul.thumbnails.image_picker_selector {
2
+ overflow: auto;
3
+ list-style-image: none;
4
+ list-style-position: outside;
5
+ list-style-type: none;
6
+ padding: 0px;
7
+ margin: 0px; }
8
+ ul.thumbnails.image_picker_selector li {
9
+ margin: 0px 12px 12px 0px;
10
+ float: left; }
11
+ ul.thumbnails.image_picker_selector li .thumbnail {
12
+ padding: 6px;
13
+ border: 1px solid #dddddd; }
14
+ ul.thumbnails.image_picker_selector li .thumbnail.selected {
15
+ background: #0088cc; }
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: image-picker-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4.1
5
+ platform: ruby
6
+ authors:
7
+ - Airat Shigapov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Image Picker is a simple jQuery plugin that transforms a select element
56
+ into a more user friendly graphical interface.
57
+ email:
58
+ - airat@shigapov.me
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - image-picker-rails.gemspec
69
+ - lib/image-picker-rails.rb
70
+ - lib/image-picker-rails/version.rb
71
+ - vendor/assets/javascripts/image-picker.js
72
+ - vendor/assets/stylesheets/image-picker.css
73
+ homepage: https://github.com/airatshigapov/image-picker-rails
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.0.3
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Image Picker is a simple jQuery plugin that transforms a select element into
97
+ a more user friendly graphical interface.
98
+ test_files: []