actionverb_s3_direct_upload 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,7 +35,7 @@ $.fn.S3Uploader = (options) ->
35
35
  add: (e, data) ->
36
36
  current_files.push data
37
37
  file = data.files[0]
38
- unless settings.before_add and not settings.before_add(file)
38
+ unless settings.before_add and not settings.before_add(data)
39
39
  data.context = $(tmpl("template-upload", file)) if $('#template-upload').length > 0
40
40
  settings['progress_container'].append(data.context)
41
41
  data.submit()
@@ -0,0 +1,117 @@
1
+ // Generated by CoffeeScript 1.3.3
2
+ var $;
3
+
4
+ $ = jQuery;
5
+
6
+ $.fn.S3Uploader = function(options) {
7
+ var $uploadForm, build_content_object, current_files, setUploadForm, settings;
8
+ if (this.length > 1) {
9
+ this.each(function() {
10
+ return $(this).S3Uploader(options);
11
+ });
12
+ return this;
13
+ }
14
+ $uploadForm = this;
15
+ settings = {
16
+ path: '',
17
+ additional_data: null,
18
+ before_add: null,
19
+ remove_completed_progress_bar: true,
20
+ progress_container: $uploadForm
21
+ };
22
+ $.extend(settings, options);
23
+ current_files = [];
24
+ setUploadForm = function() {
25
+ return $uploadForm.fileupload({
26
+ start: function(e) {
27
+ return $uploadForm.trigger("s3_uploads_start", [e]);
28
+ },
29
+ add: function(e, data) {
30
+ var file;
31
+ current_files.push(data);
32
+ file = data.files[0];
33
+ if (!(settings.before_add && !settings.before_add(data))) {
34
+ if ($('#template-upload').length > 0) {
35
+ data.context = $(tmpl("template-upload", file));
36
+ }
37
+ settings['progress_container'].append(data.context);
38
+ return data.submit();
39
+ }
40
+ },
41
+ progress: function(e, data) {
42
+ var progress;
43
+ if (data.context) {
44
+ progress = parseInt(data.loaded / data.total * 100, 10);
45
+ return data.context.find('.bar').css('width', progress + '%');
46
+ }
47
+ },
48
+ done: function(e, data) {
49
+ var content, to;
50
+ content = build_content_object($uploadForm, data.files[0]);
51
+ to = $uploadForm.data('post');
52
+ if (to) {
53
+ content[$uploadForm.data('as')] = content.url;
54
+ $.post(to, content);
55
+ }
56
+ if (data.context && settings.remove_completed_progress_bar) {
57
+ data.context.remove();
58
+ }
59
+ $uploadForm.trigger("s3_upload_complete", [content]);
60
+ current_files.splice($.inArray(data, current_files), 1);
61
+ if (current_files.length === 0) {
62
+ return $(document).trigger("s3_uploads_complete");
63
+ }
64
+ },
65
+ fail: function(e, data) {
66
+ var content;
67
+ content = build_content_object($uploadForm, data.files[0]);
68
+ content.error_thrown = data.errorThrown;
69
+ return $uploadForm.trigger("s3_upload_failed", [content]);
70
+ },
71
+ formData: function(form) {
72
+ var data, fileType;
73
+ data = form.serializeArray();
74
+ fileType = "";
75
+ if ("type" in this.files[0]) {
76
+ fileType = this.files[0].type;
77
+ }
78
+ data.push({
79
+ name: "Content-Type",
80
+ value: fileType
81
+ });
82
+ data[1].value = settings.path + data[1].value;
83
+ return data;
84
+ }
85
+ });
86
+ };
87
+ build_content_object = function($uploadForm, file) {
88
+ var content, domain, path;
89
+ domain = $uploadForm.attr('action');
90
+ path = settings.path + $uploadForm.find('input[name=key]').val().replace('/${filename}', '');
91
+ content = {};
92
+ content.url = domain + path + '/' + file.name;
93
+ content.filename = file.name;
94
+ content.filepath = path;
95
+ if ('size' in file) {
96
+ content.filesize = file.size;
97
+ }
98
+ if ('type' in file) {
99
+ content.filetype = file.type;
100
+ }
101
+ if (settings.additional_data) {
102
+ content = $.extend(content, settings.additional_data);
103
+ }
104
+ return content;
105
+ };
106
+ this.initialize = function() {
107
+ setUploadForm();
108
+ return this;
109
+ };
110
+ this.path = function(new_path) {
111
+ return settings.path = new_path;
112
+ };
113
+ this.additional_data = function(new_data) {
114
+ return settings.additional_data = new_data;
115
+ };
116
+ return this.initialize();
117
+ };
@@ -1,3 +1,3 @@
1
1
  module S3DirectUpload
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionverb_s3_direct_upload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-04 00:00:00.000000000 Z
12
+ date: 2013-02-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -89,6 +89,7 @@ files:
89
89
  - lib/s3_direct_upload/version.rb
90
90
  - lib/s3_direct_upload.rb
91
91
  - app/assets/javascripts/s3_direct_upload.js.coffee
92
+ - app/assets/javascripts/s3_direct_upload.js.js
92
93
  - app/assets/stylesheets/s3_direct_upload_progress_bars.css.scss
93
94
  - LICENSE
94
95
  - README.md
@@ -112,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
113
  version: '0'
113
114
  requirements: []
114
115
  rubyforge_project:
115
- rubygems_version: 1.8.24
116
+ rubygems_version: 1.8.23
116
117
  signing_key:
117
118
  specification_version: 3
118
119
  summary: Gives a form helper for Rails which allows direct uploads to s3. Based on