s3_direct_upload 0.0.2 → 0.0.3

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.
data/README.md CHANGED
@@ -140,7 +140,7 @@ jQuery ->
140
140
  v = $("#myS3Uploader").S3Uploader()
141
141
  ...
142
142
  v.path("new/path/")
143
- v.exta_data("newdata")
143
+ v.additional_data("newdata")
144
144
 
145
145
  ### Global Event Hooks
146
146
 
@@ -1,94 +1,94 @@
1
1
  #= require jquery-fileupload/basic
2
2
  #= require jquery-fileupload/vendor/tmpl
3
3
 
4
- (($) ->
5
- $.fn.S3Uploader = (options) ->
6
-
7
- # support multiple elements
8
- if @length > 1
9
- @each ->
10
- $(this).S3Upleader options
11
-
12
- return this
13
-
14
- $uploadForm = this
15
-
16
- settings =
17
- path: ''
18
- additional_data: null
19
- before_add: null
20
-
21
- settings = $.extend settings, options
22
-
23
- current_files = []
24
-
25
- setUploadForm = ->
26
- $uploadForm.fileupload
27
-
28
- add: (e, data) ->
29
- current_files.push data
30
- file = data.files[0]
31
- unless settings.before_add and not settings.before_add(file)
32
- data.context = $(tmpl("template-upload", file))
33
- $uploadForm.append(data.context)
34
- data.submit()
35
-
36
- progress: (e, data) ->
37
- if data.context
38
- progress = parseInt(data.loaded / data.total * 100, 10)
39
- data.context.find('.bar').css('width', progress + '%')
40
-
41
- done: (e, data) ->
42
- file = data.files[0]
43
- domain = $uploadForm.attr('action')
44
- path = settings.path + $uploadForm.find('input[name=key]').val().replace('/${filename}', '')
45
- to = $uploadForm.data('post')
46
- content = {}
47
- content[$uploadForm.data('as')] = domain + path + '/' + file.name
48
- content.filename = file.name
49
- content.filepath = path
50
- if settings.additional_data
51
- content = $.extend content, settings.additional_data
52
- if 'size' of file
53
- content.file_size = file.size
54
- if 'type' of file
55
- content.file_type = file.type
56
-
57
- $.post(to, content)
58
- data.context.remove() if data.context # remove progress bar
59
-
60
- current_files.splice($.inArray(data, current_files), 1) # remove that element from the array
61
- if current_files.length == 0
62
- $(document).trigger("s3_uploads_complete")
63
-
64
- fail: (e, data) ->
65
- alert("#{data.files[0].name} failed to upload.")
66
- console.log("Upload failed:")
67
- console.log(data)
68
-
69
- formData: (form) ->
70
- data = form.serializeArray()
71
- fileType = ""
72
- if "type" of @files[0]
73
- fileType = @files[0].type
74
- data.push
75
- name: "Content-Type"
76
- value: fileType
77
-
78
- data[1].value = settings.path + data[1].value
79
-
80
- data
81
-
82
- #public methods
83
- @initialize = ->
84
- setUploadForm()
85
- this
86
-
87
- @path = (new_path) ->
88
- settings.path = new_path
89
-
90
- @additional_data = (new_data) ->
91
- settings.additional_data = additional_data
92
-
93
- @initialize()
94
- ) jQuery
4
+ $ = jQuery
5
+
6
+ $.fn.S3Uploader = (options) ->
7
+
8
+ # support multiple elements
9
+ if @length > 1
10
+ @each ->
11
+ $(this).S3Uploader options
12
+
13
+ return this
14
+
15
+ $uploadForm = this
16
+
17
+ settings =
18
+ path: ''
19
+ additional_data: null
20
+ before_add: null
21
+
22
+ $.extend settings, options
23
+
24
+ current_files = []
25
+
26
+ setUploadForm = ->
27
+ $uploadForm.fileupload
28
+
29
+ add: (e, data) ->
30
+ current_files.push data
31
+ file = data.files[0]
32
+ unless settings.before_add and not settings.before_add(file)
33
+ data.context = $(tmpl("template-upload", file))
34
+ $uploadForm.append(data.context)
35
+ data.submit()
36
+
37
+ progress: (e, data) ->
38
+ if data.context
39
+ progress = parseInt(data.loaded / data.total * 100, 10)
40
+ data.context.find('.bar').css('width', progress + '%')
41
+
42
+ done: (e, data) ->
43
+ file = data.files[0]
44
+ domain = $uploadForm.attr('action')
45
+ path = settings.path + $uploadForm.find('input[name=key]').val().replace('/${filename}', '')
46
+ to = $uploadForm.data('post')
47
+ content = {}
48
+ content[$uploadForm.data('as')] = domain + path + '/' + file.name
49
+ content.filename = file.name
50
+ content.filepath = path
51
+ if settings.additional_data
52
+ content = $.extend content, settings.additional_data
53
+ if 'size' of file
54
+ content.filesize = file.size
55
+ if 'type' of file
56
+ content.filetype = file.type
57
+
58
+ $.post(to, content)
59
+ data.context.remove() if data.context # remove progress bar
60
+
61
+ current_files.splice($.inArray(data, current_files), 1) # remove that element from the array
62
+ if current_files.length == 0
63
+ $(document).trigger("s3_uploads_complete")
64
+
65
+ fail: (e, data) ->
66
+ alert("#{data.files[0].name} failed to upload.")
67
+ console.log("Upload failed:")
68
+ console.log(data)
69
+
70
+ formData: (form) ->
71
+ data = form.serializeArray()
72
+ fileType = ""
73
+ if "type" of @files[0]
74
+ fileType = @files[0].type
75
+ data.push
76
+ name: "Content-Type"
77
+ value: fileType
78
+
79
+ data[1].value = settings.path + data[1].value
80
+
81
+ data
82
+
83
+ #public methods
84
+ @initialize = ->
85
+ setUploadForm()
86
+ this
87
+
88
+ @path = (new_path) ->
89
+ settings.path = new_path
90
+
91
+ @additional_data = (new_data) ->
92
+ settings.additional_data = new_data
93
+
94
+ @initialize()
@@ -1,3 +1,3 @@
1
1
  module S3DirectUpload
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3_direct_upload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - WayneH
8
+ - Wayne Hoover
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-09 00:00:00.000000000 Z
12
+ date: 2012-10-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -77,7 +77,7 @@ dependencies:
77
77
  version: 0.3.4
78
78
  description: Direct Upload to Amazon S3 With CORS and jquery-file-upload
79
79
  email:
80
- - wayne@blissofbeing.com
80
+ - w@waynehoover.com
81
81
  executables: []
82
82
  extensions: []
83
83
  extra_rdoc_files: []