uploadbox 0.2.0.beta2 → 0.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3295adc0d84020b0fa9a08e84ddb4d180c8c6e37
4
- data.tar.gz: 840dda8db5e411535901274306d796715a62e515
3
+ metadata.gz: aba403d9c1bac88814e1c15488432993d38693e3
4
+ data.tar.gz: 7b09672b8ca2e8f1738570137945e7b392e74563
5
5
  SHA512:
6
- metadata.gz: 608fe895c9d1c576a60537c936d5beb3c358deab7abb0d31a5cfaca589c5c62f811385842d4c5085dc4fb19004e8a157c2d12f9e309816722c5586a99882eee7
7
- data.tar.gz: e0792f3cbdb7749b1e0b66e367e80822d6de790454f820134e0e6e72360122182cfc34f00de02917af0c958825d80a86b36e6537bd8b4f6e9a9b98a4f4e21770
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
- transform: translate(-300px, 0) scale(4)
96
- font-size: 23px
98
+ font-size: 600px
97
99
  direction: ltr
98
100
  cursor: pointer
99
- width: 100%
101
+ display: block
102
+ overflow: hidden
103
+ &:active
104
+ outline: none
105
+ border: none
106
+
100
107
 
101
108
  .fileupload-exists
102
- margin-left: -9999px
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: -10px
192
+ top: 0px
188
193
  right: -10px
189
194
  z-index: 3
190
195
  padding: 0
@@ -1,41 +1,51 @@
1
- = form.fields_for :image do
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
- .uploadbox-image-uploader.uploads-many data-container="uploader" style="width: #{width}px; height: #{height}px;"
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="hidden"
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="hidden"
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
- - for image in resource.send(upload_name)
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" value="#{image.id}"
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" value="#{image.id}"
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 :image do
2
- - secure_random = SecureRandom.uuid
3
- .uploadbox-image-uploader.uploads-one data-component="ImageUploader" style="width: #{width}px; height: #{height}px;"
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="hidden" value="#{resource.send(upload_name).try :id}"
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="hidden" value="#{resource.send(upload_name).try :id}"
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
- .fileupload data-provides="fileupload" class="fileupload-#{(resource.send("#{upload_name}?") or default) ? 'exists' : 'new'}"
10
- .fileupload-preview.preview data-version="#{version}" data-width="#{width}" data-height="#{height}" style="width: #{width}px; height: #{height}px;"
11
- - if resource.send("#{upload_name}?")
12
- = img resource.send(upload_name).send(version)
13
- - elsif default
14
- = image_tag default, width: width, height: height
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
- .fileupload-actions
17
- span.btn.btn-file style="width: #{width}px; height: #{height}px;"
18
- span.fileupload-new = choose_label
19
- span.fileupload-exists = update_label
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
- 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="display: none; width: #{width}px; height: #{height}px;"
23
- input type="hidden" name="policy" value="#{s3_policy}"
24
- input type="hidden" name="signature" value="#{s3_signature}"
25
- input type="hidden" name="AWSAccessKeyId" value="#{CarrierWave::Uploader::Base.fog_credentials[:aws_access_key_id]}"
26
- input type="hidden" name="acl" value="public-read"
27
- input type="hidden" name="key" value="uploads/#{secure_random}/"
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
- input type="hidden" name="image[imageable_type]" value="#{resource.class.base_class}"
30
- input type="hidden" name="image[upload_name]" value="#{upload_name}"
31
- - if removable
32
- - if resource.send(upload_name).present?
33
- = link_to destroy_label, uploadbox.image_path(resource.send(upload_name)), class: 'btn fileupload-exists', remote: true, method: :delete
34
- - else
35
- = link_to destroy_label, '#', class: 'btn fileupload-exists', remote: true, method: :delete
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
 
@@ -9,6 +9,7 @@ require 'jbuilder'
9
9
  require 'resque'
10
10
  require 'heroku_resque_auto_scale'
11
11
  require 'dotenv-rails'
12
+ require 'browser'
12
13
 
13
14
  # Allows redirects from https to http as facebook does
14
15
  module OpenURI
@@ -56,9 +56,13 @@ module Uploadbox
56
56
  end
57
57
 
58
58
  # @post.picture=(id)
59
- define_method("#{upload_name}=") do |upload_id|
60
- if upload_id.present?
61
- self.send("#{upload_name}_upload=", upload_class.find(upload_id))
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
- self.send(upload_name).send('replace', [])
167
- for id in ids.select(&:present?)
168
- self.send(upload_name).send('<<', upload_class.find(id))
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
 
@@ -1,3 +1,3 @@
1
1
  module Uploadbox
2
- VERSION = "0.2.0.beta2"
2
+ VERSION = "0.2.0.rc1"
3
3
  end
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.beta2
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-23 00:00:00.000000000 Z
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