uploadbox 0.2.0.beta2 → 0.2.0.rc1
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/app/assets/javascripts/_gallery_uploader.coffee +8 -0
- data/app/assets/javascripts/_image_uploader.coffee +10 -2
- data/app/assets/javascripts/_uploader_preview.coffee +7 -0
- data/app/assets/stylesheets/uploadbox.sass +12 -7
- data/app/views/uploadbox/images/_uploads_many.slim +42 -32
- data/app/views/uploadbox/images/_uploads_one.slim +38 -28
- data/lib/uploadbox/engine.rb +1 -0
- data/lib/uploadbox/image_uploader.rb +18 -6
- data/lib/uploadbox/version.rb +1 -1
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aba403d9c1bac88814e1c15488432993d38693e3
|
4
|
+
data.tar.gz: 7b09672b8ca2e8f1738570137945e7b392e74563
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 181f7a868b0afedd60a112b8e6ac8a92bda233d45fca23b113d0e722a88bcf957b476bf7c2ef3f05184e7db42fb37f4bf183c9da48ce48dc1c9f0199e05ca20d
|
7
|
+
data.tar.gz: f851aabf4f2e79ba4d7f1460a1914c001cc528faf6c06b0d63aa62d5739fefb91090bf936497e10ca0de1b65766545fc63f5f43f1065cf84c48599415bfd03a9
|
@@ -15,6 +15,8 @@ class @GalleryUploader
|
|
15
15
|
done: @done
|
16
16
|
fail: @fail
|
17
17
|
|
18
|
+
@setupLabel()
|
19
|
+
|
18
20
|
add: (e, data) =>
|
19
21
|
if @loader
|
20
22
|
@loader.detach()
|
@@ -63,3 +65,9 @@ class @GalleryUploader
|
|
63
65
|
key = Object.keys(@previews)[@currentIndex]
|
64
66
|
@currentIndex++
|
65
67
|
@previews[key]
|
68
|
+
|
69
|
+
setupLabel: =>
|
70
|
+
labels = @container.find('.fileupload-actions .fileupload-new, .fileupload-actions .fileupload-exists')
|
71
|
+
labels.each (index, label) ->
|
72
|
+
$(label).css({marginLeft: $(label).outerWidth() * -0.5, marginTop: $(label).outerHeight() * -0.5})
|
73
|
+
|
@@ -8,8 +8,11 @@ class @ImageUploader
|
|
8
8
|
@container.find('a.btn.fileupload-exists').bind('ajax:success', @delete)
|
9
9
|
@thumbContainer = @container.find('.fileupload-preview.preview')
|
10
10
|
|
11
|
+
@setupLabel()
|
12
|
+
|
11
13
|
@fileInput.show()
|
12
14
|
|
15
|
+
|
13
16
|
@fileInput.fileupload
|
14
17
|
type: 'POST'
|
15
18
|
dataType: 'xml'
|
@@ -22,14 +25,13 @@ class @ImageUploader
|
|
22
25
|
|
23
26
|
add: (e, data) =>
|
24
27
|
@file = data.files[0]
|
25
|
-
|
26
28
|
if @loader
|
27
29
|
@loader.detach()
|
28
30
|
|
29
31
|
if @verifyProcessingInterval
|
30
32
|
clearInterval(@verifyProcessingInterval)
|
31
33
|
|
32
|
-
if @file.type.match /gif|jpe?g|png/
|
34
|
+
if @file.type and @file.type.match /gif|jpe?g|png/
|
33
35
|
loadImage @file, @appendThumb, {
|
34
36
|
maxWidth: @thumbContainer.data('width'),
|
35
37
|
maxHeight: @thumbContainer.data('height'),
|
@@ -136,3 +138,9 @@ class @ImageUploader
|
|
136
138
|
@container.find('.fileupload').removeClass('fileupload-new').addClass('fileupload-exists')
|
137
139
|
@container.find('.fileupload').removeClass('uploading').removeClass('processing')
|
138
140
|
@container.closest('form').find('[type=submit]').attr("disabled", false)
|
141
|
+
|
142
|
+
setupLabel: =>
|
143
|
+
labels = @container.find('.fileupload-actions .fileupload-new, .fileupload-actions .fileupload-exists')
|
144
|
+
labels.each (index, label) ->
|
145
|
+
$(label).css({marginLeft: $(label).outerWidth() * -0.5, marginTop: $(label).outerHeight() * -0.5})
|
146
|
+
|
@@ -26,6 +26,8 @@ class @UploaderPreview
|
|
26
26
|
@idInput = @container.find('[data-item="id"]')
|
27
27
|
@thumbContainer = @container.find('.fileupload-preview.thumbnail')
|
28
28
|
|
29
|
+
@setupLabel()
|
30
|
+
|
29
31
|
startLoader: =>
|
30
32
|
loadImage @file, @appendThumb, {
|
31
33
|
maxWidth: @thumbContainer.data('width'),
|
@@ -147,3 +149,8 @@ class @UploaderPreview
|
|
147
149
|
@idInput.val('')
|
148
150
|
@container.detach()
|
149
151
|
|
152
|
+
setupLabel: =>
|
153
|
+
labels = @container.find('.fileupload-actions .fileupload-new, .fileupload-actions .fileupload-exists')
|
154
|
+
labels.each (index, label) ->
|
155
|
+
$(label).css({marginLeft: $(label).outerWidth() * -0.5, marginTop: $(label).outerHeight() * -0.5})
|
156
|
+
|
@@ -3,6 +3,8 @@
|
|
3
3
|
.uploadbox-image-container
|
4
4
|
background: #eee
|
5
5
|
display: inline-block
|
6
|
+
// input[type="file"]
|
7
|
+
// display: none
|
6
8
|
img, canvas
|
7
9
|
display: inline-block
|
8
10
|
vertical-align: bottom
|
@@ -90,23 +92,26 @@
|
|
90
92
|
top: 0
|
91
93
|
right: 0
|
92
94
|
margin: 0
|
95
|
+
background: yellow
|
93
96
|
opacity: 0
|
94
97
|
filter: alpha(opacity = 0)
|
95
|
-
|
96
|
-
font-size: 23px
|
98
|
+
font-size: 600px
|
97
99
|
direction: ltr
|
98
100
|
cursor: pointer
|
99
|
-
|
101
|
+
display: block
|
102
|
+
overflow: hidden
|
103
|
+
&:active
|
104
|
+
outline: none
|
105
|
+
border: none
|
106
|
+
|
100
107
|
|
101
108
|
.fileupload-exists
|
102
|
-
|
109
|
+
display: none
|
103
110
|
|
104
111
|
.fileupload-new
|
105
112
|
position: absolute
|
106
113
|
top: 50%
|
107
114
|
left: 50%
|
108
|
-
margin-top: -14px
|
109
|
-
margin-left: -39px
|
110
115
|
display: inline-block
|
111
116
|
background: #e5e5e5
|
112
117
|
font-size: 11px
|
@@ -184,7 +189,7 @@
|
|
184
189
|
|
185
190
|
.btn.fileupload-exists
|
186
191
|
position: absolute
|
187
|
-
top:
|
192
|
+
top: 0px
|
188
193
|
right: -10px
|
189
194
|
z-index: 3
|
190
195
|
padding: 0
|
@@ -1,41 +1,51 @@
|
|
1
|
-
= form.fields_for
|
1
|
+
= form.fields_for upload_name do |f|
|
2
|
+
/ forces multipart/form-data
|
3
|
+
= f.file_field :temp, style: 'display: none'
|
4
|
+
|
2
5
|
div data-component="GalleryUploader"
|
3
|
-
|
6
|
+
- if browser.ie? and browser.version.to_i <= 9
|
4
7
|
- if namespace
|
5
|
-
input name="[#{resource.class.name.underscore}][#{namespace}]#{upload_name}[]" data-item="id" type="
|
8
|
+
input name="[#{resource.class.name.underscore}][#{namespace}]#{upload_name}[]" data-item="id" type="file"
|
6
9
|
- else
|
7
|
-
input name="[#{resource.class.name.underscore}]#{upload_name}[]" data-item="id" type="
|
8
|
-
|
9
|
-
.fileupload data-provides="fileupload" class="fileupload-new"
|
10
|
-
.fileupload-preview.thumbnail data-version="#{version}" data-width="#{width}" data-height="#{height}" style="width: #{width}px; height: #{height}px;"
|
11
|
-
|
12
|
-
.fileupload-actions
|
13
|
-
span.btn.btn-file style="width: #{width}px; height: #{height}px;"
|
14
|
-
span.fileupload-new = choose_label
|
15
|
-
span.fileupload-exists = update_label
|
16
|
-
i.icon.icon-plus-1 style="line-height: #{height}px; font-size: #{(width * 0.4).to_i}px"
|
17
|
-
|
18
|
-
input type="file" name="image[file]" data-callback-url="#{uploadbox.images_path}" data-find-url="#{uploadbox.find_images_path(format: :json)}" data-url="https://#{CarrierWave::Uploader::Base.fog_directory}.s3.amazonaws.com/" accept="image/png image/x-png, image/gif, image/jpeg" style="display: none; width: #{width}px; height: #{height}px;" multiple="true"
|
19
|
-
input type="hidden" name="policy" value="#{s3_policy}"
|
20
|
-
input type="hidden" name="signature" value="#{s3_signature}"
|
21
|
-
input type="hidden" name="AWSAccessKeyId" value="#{CarrierWave::Uploader::Base.fog_credentials[:aws_access_key_id]}"
|
22
|
-
input type="hidden" name="acl" value="public-read"
|
23
|
-
input type="hidden" name="key"
|
24
|
-
|
25
|
-
input type="hidden" name="image[imageable_type]" value="#{resource.class.base_class}"
|
26
|
-
input type="hidden" name="image[upload_name]" value="#{upload_name}"
|
27
|
-
- if removable
|
28
|
-
- if resource.send(upload_name).present?
|
29
|
-
= link_to destroy_label, uploadbox.image_path(resource.send(upload_name)), class: 'btn fileupload-exists', remote: true, method: :delete
|
30
|
-
- else
|
31
|
-
= link_to destroy_label, '#', class: 'btn fileupload-exists', remote: true, method: :delete
|
10
|
+
input name="[#{resource.class.name.underscore}]#{upload_name}[]" data-item="id" type="file"
|
11
|
+
- else
|
32
12
|
|
33
|
-
|
34
|
-
.uploadbox-image-uploader.uploads-many data-component="UploaderPreview" data-container="uploader" style="width: #{width}px; height: #{height}px;"
|
13
|
+
.uploadbox-image-uploader.uploads-many data-container="uploader" style="width: #{width}px; height: #{height}px;"
|
35
14
|
- if namespace
|
36
|
-
input name="[#{resource.class.name.underscore}][#{namespace}]#{upload_name}[]" data-item="id" type="hidden"
|
15
|
+
input name="[#{resource.class.name.underscore}][#{namespace}]#{upload_name}[]" data-item="id" type="hidden"
|
37
16
|
- else
|
38
|
-
input name="[#{resource.class.name.underscore}]#{upload_name}[]" data-item="id" type="hidden"
|
17
|
+
input name="[#{resource.class.name.underscore}]#{upload_name}[]" data-item="id" type="hidden"
|
18
|
+
|
19
|
+
.fileupload data-provides="fileupload" class="fileupload-new"
|
20
|
+
.fileupload-preview.thumbnail data-version="#{version}" data-width="#{width}" data-height="#{height}" style="width: #{width}px; height: #{height}px;"
|
21
|
+
|
22
|
+
.fileupload-actions
|
23
|
+
span.btn.btn-file style="width: #{width}px; height: #{height}px;"
|
24
|
+
span.fileupload-new = choose_label
|
25
|
+
span.fileupload-exists = update_label
|
26
|
+
|
27
|
+
input type="file" name="image[file]" data-callback-url="#{uploadbox.images_path}" data-find-url="#{uploadbox.find_images_path(format: :json)}" data-url="https://#{CarrierWave::Uploader::Base.fog_directory}.s3.amazonaws.com/" accept="image/png image/x-png, image/gif, image/jpeg" style="display: none; width: #{width}px; height: #{height}px;" multiple="true"
|
28
|
+
input type="hidden" name="policy" value="#{s3_policy}"
|
29
|
+
input type="hidden" name="signature" value="#{s3_signature}"
|
30
|
+
input type="hidden" name="AWSAccessKeyId" value="#{CarrierWave::Uploader::Base.fog_credentials[:aws_access_key_id]}"
|
31
|
+
input type="hidden" name="acl" value="public-read"
|
32
|
+
input type="hidden" name="key"
|
33
|
+
|
34
|
+
input type="hidden" name="image[imageable_type]" value="#{resource.class.base_class}"
|
35
|
+
input type="hidden" name="image[upload_name]" value="#{upload_name}"
|
36
|
+
- if removable
|
37
|
+
- if resource.send(upload_name).present?
|
38
|
+
= link_to destroy_label, uploadbox.image_path(resource.send(upload_name)), class: 'btn fileupload-exists', remote: true, method: :delete
|
39
|
+
- else
|
40
|
+
= link_to destroy_label, '#', class: 'btn fileupload-exists', remote: true, method: :delete
|
41
|
+
|
42
|
+
- for image in resource.send(upload_name)
|
43
|
+
.uploadbox-image-uploader.uploads-many data-component="UploaderPreview" data-container="uploader" style="width: #{width}px; height: #{height}px;"
|
44
|
+
- unless browser.ie? and browser.version.to_i <= 9
|
45
|
+
- if namespace
|
46
|
+
input name="[#{resource.class.name.underscore}][#{namespace}]#{upload_name}[]" data-item="id" type="hidden" value="#{image.id}"
|
47
|
+
- else
|
48
|
+
input name="[#{resource.class.name.underscore}]#{upload_name}[]" data-item="id" type="hidden" value="#{image.id}"
|
39
49
|
|
40
50
|
.fileupload data-provides="fileupload" class="fileupload-exists"
|
41
51
|
.fileupload-preview.thumbnail data-version="#{version}" data-width="#{width}" data-height="#{height}" style="width: #{width}px; height: #{height}px;"
|
@@ -1,36 +1,46 @@
|
|
1
|
-
= form.fields_for
|
2
|
-
|
3
|
-
.
|
1
|
+
= form.fields_for upload_name do |f|
|
2
|
+
/ forces multipart/form-data
|
3
|
+
= f.file_field :temp, style: 'display: none'
|
4
|
+
|
5
|
+
/ old browsers
|
6
|
+
- if browser.ie? and browser.version.to_i <= 9
|
4
7
|
- if namespace
|
5
|
-
input name="[#{resource.class.name.underscore}][#{namespace}]#{upload_name}" data-item="id" type="
|
8
|
+
input name="[#{resource.class.name.underscore}][#{namespace}]#{upload_name}" data-item="id" type="file" accept="image/jpg,image/png"
|
6
9
|
- else
|
7
|
-
input name="[#{resource.class.name.underscore}]#{upload_name}" data-item="id" type="
|
10
|
+
input name="[#{resource.class.name.underscore}]#{upload_name}" data-item="id" type="file" accept="image/jpg,image/png"
|
11
|
+
- else
|
12
|
+
- secure_random = SecureRandom.uuid
|
13
|
+
.uploadbox-image-uploader.uploads-one data-component="ImageUploader" style="width: #{width}px; height: #{height}px;"
|
14
|
+
- if namespace
|
15
|
+
input name="[#{resource.class.name.underscore}][#{namespace}]#{upload_name}" data-item="id" type="hidden" value="#{resource.send(upload_name).try :id}"
|
16
|
+
- else
|
17
|
+
input name="[#{resource.class.name.underscore}]#{upload_name}" data-item="id" type="hidden" value="#{resource.send(upload_name).try :id}"
|
8
18
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
19
|
+
.fileupload data-provides="fileupload" class="fileupload-#{(resource.send("#{upload_name}?") or default) ? 'exists' : 'new'}"
|
20
|
+
.fileupload-preview.preview data-version="#{version}" data-width="#{width}" data-height="#{height}" style="width: #{width}px; height: #{height}px;"
|
21
|
+
- if resource.send("#{upload_name}?")
|
22
|
+
= img resource.send(upload_name).send(version)
|
23
|
+
- elsif default
|
24
|
+
= image_tag default, width: width, height: height
|
15
25
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
26
|
+
.fileupload-actions
|
27
|
+
span.btn.btn-file style="width: #{width}px; height: #{height}px;"
|
28
|
+
span.fileupload-new = choose_label
|
29
|
+
span.fileupload-exists = update_label
|
20
30
|
|
21
31
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
32
|
+
input type="file" name="image[file]" data-callback-url="#{uploadbox.images_path}" data-find-url="#{uploadbox.find_images_path(format: :json)}" data-url="https://#{CarrierWave::Uploader::Base.fog_directory}.s3.amazonaws.com/" data-secure-random="#{secure_random}" accept="image/*" style="width: #{width}px; height: #{height}px;"
|
33
|
+
input type="hidden" name="policy" value="#{s3_policy}"
|
34
|
+
input type="hidden" name="signature" value="#{s3_signature}"
|
35
|
+
input type="hidden" name="AWSAccessKeyId" value="#{CarrierWave::Uploader::Base.fog_credentials[:aws_access_key_id]}"
|
36
|
+
input type="hidden" name="acl" value="public-read"
|
37
|
+
input type="hidden" name="key" value="uploads/#{secure_random}/"
|
28
38
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
39
|
+
input type="hidden" name="image[imageable_type]" value="#{resource.class.base_class}"
|
40
|
+
input type="hidden" name="image[upload_name]" value="#{upload_name}"
|
41
|
+
- if removable
|
42
|
+
- if resource.send(upload_name).present?
|
43
|
+
= link_to destroy_label, uploadbox.image_path(resource.send(upload_name)), class: 'btn fileupload-exists', remote: true, method: :delete
|
44
|
+
- else
|
45
|
+
= link_to destroy_label, '#', class: 'btn fileupload-exists', remote: true, method: :delete
|
36
46
|
|
data/lib/uploadbox/engine.rb
CHANGED
@@ -56,9 +56,13 @@ module Uploadbox
|
|
56
56
|
end
|
57
57
|
|
58
58
|
# @post.picture=(id)
|
59
|
-
define_method("#{upload_name}=") do |
|
60
|
-
|
61
|
-
|
59
|
+
define_method("#{upload_name}=") do |upload_or_id|
|
60
|
+
# deals with ie8 and ie9
|
61
|
+
if upload_or_id.is_a? ActionDispatch::Http::UploadedFile
|
62
|
+
upload = upload_class.create(file: upload_or_id)
|
63
|
+
self.send("#{upload_name}_upload=", upload)
|
64
|
+
elsif upload_or_id.present?
|
65
|
+
self.send("#{upload_name}_upload=", upload_class.find(upload_or_id))
|
62
66
|
end
|
63
67
|
end
|
64
68
|
|
@@ -163,9 +167,17 @@ module Uploadbox
|
|
163
167
|
|
164
168
|
# @post.images=([id, id])
|
165
169
|
define_method("#{upload_name}=") do |ids|
|
166
|
-
|
167
|
-
|
168
|
-
|
170
|
+
|
171
|
+
|
172
|
+
# deals with ie8 and ie9
|
173
|
+
if ids[0].is_a? ActionDispatch::Http::UploadedFile
|
174
|
+
upload = upload_class.create(file: ids[0])
|
175
|
+
self.send(upload_name).send('<<', upload)
|
176
|
+
else
|
177
|
+
self.send(upload_name).send('replace', [])
|
178
|
+
for id in ids.select(&:present?)
|
179
|
+
self.send(upload_name).send('<<', upload_class.find(id))
|
180
|
+
end
|
169
181
|
end
|
170
182
|
end
|
171
183
|
|
data/lib/uploadbox/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uploadbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.0.
|
4
|
+
version: 0.2.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julio Protzek
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -211,6 +211,26 @@ dependencies:
|
|
211
211
|
- - '>='
|
212
212
|
- !ruby/object:Gem::Version
|
213
213
|
version: 0.10.0
|
214
|
+
- !ruby/object:Gem::Dependency
|
215
|
+
name: browser
|
216
|
+
requirement: !ruby/object:Gem::Requirement
|
217
|
+
requirements:
|
218
|
+
- - ~>
|
219
|
+
- !ruby/object:Gem::Version
|
220
|
+
version: '0.4'
|
221
|
+
- - '>='
|
222
|
+
- !ruby/object:Gem::Version
|
223
|
+
version: 0.4.1
|
224
|
+
type: :runtime
|
225
|
+
prerelease: false
|
226
|
+
version_requirements: !ruby/object:Gem::Requirement
|
227
|
+
requirements:
|
228
|
+
- - ~>
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
version: '0.4'
|
231
|
+
- - '>='
|
232
|
+
- !ruby/object:Gem::Version
|
233
|
+
version: 0.4.1
|
214
234
|
- !ruby/object:Gem::Dependency
|
215
235
|
name: jquery-rails
|
216
236
|
requirement: !ruby/object:Gem::Requirement
|