upload_kit-rails 0.5.0 → 0.6.0

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.rdoc CHANGED
@@ -15,13 +15,62 @@ Ensure that you have A copy of Twitter's Bootstrap CSS in your asset pipeline. F
15
15
  After running bundle install to install the gem, you need to run the upload_kit install generator. T
16
16
 
17
17
  rails g upload_kit:install
18
+
19
+ == Usage
20
+
21
+ You can use the following markup for creating a uploader for a single file. The URL has to be to a restful interface of uploading files:
22
+
23
+ <%= f.file_field :attachment, :class => "uk-input", :data => { :upload_url => './', :max_file_size => "10mb" } %>
24
+
25
+ This is the HTML generated:
26
+
27
+ <!-- Single-file uploader -->
28
+ <input type="file" class="uk-input" name="attachment" data-upload-url="./" data-max-file-size="10mb"/>
29
+
30
+ == Listening for events
31
+
32
+ Upload kit allows you to listen for events that occur during the lifecycle of the upload. Below is an example:
33
+
34
+ <!DOCTYPE html>
35
+ <html lang="en">
36
+ <head>
37
+ <meta charset="utf-8" />
38
+ <title>UploadKit Demo</title>
39
+ <link rel="stylesheet" type="text/css" href="externals/bootstrap/docs/assets/css/bootstrap.css"/>
40
+ <link rel="stylesheet" type="text/css" href="uploadkit.css"/>
41
+ <script type="text/javascript" src="jquery-1.7.1.js"></script>
42
+ <script type="text/javascript" src="externals/plupload/js/plupload.full.js"></script>
43
+ <script type="text/javascript" src="uploadkit.js"></script>
44
+
45
+ <script type="text/javascript">
46
+ $(function() {
47
+ $('.uk-input').bind(UKEventType.FileUploaded, function(evt) {
48
+ console.log(evt.response);
49
+ });
50
+ });
51
+ </script>
52
+ </head>
53
+ <body>
54
+ <form method="post" action="#">
55
+ <!-- Multi-file uploader -->
56
+ <input type="file" class="uk-input" name="attachments" multiple="multiple" data-upload-url="./" data-max-file-size="100mb"/>
57
+ <!-- Single-file uploader -->
58
+ <input type="file" class="uk-input" name="avatar" data-upload-url="./" data-max-file-size="10mb"/>
59
+ </form>
60
+ </body>
61
+ </html>
18
62
 
19
63
  == Change Log
20
64
 
65
+ == Version 1.1.0
66
+
67
+ * Added custom events for file upload completion and upload errors so that application-specific code can listen for these events and handle server responses and errors.
68
+
69
+
21
70
  === Version 1.0.0
22
71
 
23
- * Adds CSS and Javascript files to ensure that UploadKit works properly
24
- * Created generator to place necessary references in application.js and application.css
72
+ * Adds CSS and Javascript files to ensure that UploadKit works properly
73
+ * Created generator to place necessary references in application.js and application.css
25
74
 
26
75
  == License
27
76
 
@@ -1,5 +1,5 @@
1
1
  module UploadKit
2
2
  module Rails
3
- VERSION = "0.5.0"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
@@ -1,5 +1,7 @@
1
1
  var UKEventType = {
2
- UploadComplete: 'UKUploadComplete'
2
+ FileUploaded: 'UKFileUploaded',
3
+ UploadComplete: 'UKUploadComplete',
4
+ UploadError: 'UKUploadError'
3
5
  };
4
6
 
5
7
  var UploadKit = function(input) {
@@ -14,15 +16,15 @@ var UploadKit = function(input) {
14
16
  var id = (Date['now']) ? Date.now() : +new Date(); // TODO: Verify this failover works in IE.
15
17
  var baseUrl = '';
16
18
  $('script').each(function(index, element) {
17
- var src = $(element).attr('src');
18
- var endIndex = (src) ? src.indexOf('uploadkit.js') : -1;
19
+ var src = $(element).attr('src') || '';
20
+ var endIndex = src.indexOf('uploadkit.js');
19
21
  if (endIndex !== -1) baseUrl = (endIndex === 0) ? './' : src.substring(0, endIndex);
20
22
  });
21
23
 
22
24
  var self = this;
23
25
  var name = this.name = $input.attr('name');
24
26
  var isMultiple = this.isMultiple = !!$input.attr('multiple');
25
- var uploadUrl = this.uploadUrl = $input.data('uploadUrl');
27
+ var uploadUrl = this.uploadUrl = $input.data('uploadUrl') || $form.attr('action');
26
28
  var maxFileSize = this.maxFileSize = $input.data('maxFileSize') || this.maxFileSize;
27
29
  var classes = ($input.attr('class') + '').replace(/uk-input/g, '');
28
30
 
@@ -130,10 +132,16 @@ var UploadKit = function(input) {
130
132
  $bar.html('Done');
131
133
 
132
134
  responses.push(response);
135
+
136
+ $input.trigger($.Event(UKEventType.FileUploaded, {
137
+ uploader: uploader,
138
+ file: file,
139
+ response: response
140
+ }));
133
141
  });
134
142
 
135
143
  uploader.bind('UploadComplete', function(uploader, files) {
136
- $element.trigger(jQuery.Event(UKEventType.UploadComplete, {
144
+ $input.trigger($.Event(UKEventType.UploadComplete, {
137
145
  uploader: uploader,
138
146
  files: files,
139
147
  responses: responses
@@ -157,6 +165,11 @@ var UploadKit = function(input) {
157
165
  $td.html(message);
158
166
 
159
167
  if (uploader.files.length === 0) $uploadButton.addClass('disabled');
168
+
169
+ $input.trigger($.Event(UKEventType.UploadError, {
170
+ uploader: uploader,
171
+ error: error
172
+ }));
160
173
  });
161
174
 
162
175
  $tbody.delegate('a.close', 'click', function(evt) {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upload_kit-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-21 00:00:00.000000000Z
12
+ date: 2012-03-28 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70311140971080 !ruby/object:Gem::Requirement
16
+ requirement: &70108005523180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70311140971080
24
+ version_requirements: *70108005523180
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &70311140970660 !ruby/object:Gem::Requirement
27
+ requirement: &70108005522760 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70311140970660
35
+ version_requirements: *70108005522760
36
36
  description: Packages the UploadKit JavaScript UI components in to a Ruby gem
37
37
  email:
38
38
  - nick@entropi.co
@@ -50,7 +50,7 @@ files:
50
50
  - vendor/assets/UploadKit/uploadkit.js
51
51
  - vendor/assets/UploadKit/uploadkit.css
52
52
  - vendor/assets/UploadKit/externals/plupload/js/plupload.full.js
53
- homepage: http://github.com/entropillc/upload_kit-rails
53
+ homepage: https://github.com/entropillc/UploadKit-Rails
54
54
  licenses: []
55
55
  post_install_message:
56
56
  rdoc_options: []