jquery.fileupload-rails 0.0.1

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.
@@ -0,0 +1,156 @@
1
+ /*
2
+ * jQuery Iframe Transport Plugin 1.2.5
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2011, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://creativecommons.org/licenses/MIT/
10
+ */
11
+
12
+ /*jslint unparam: true, nomen: true */
13
+ /*global jQuery, document */
14
+
15
+ (function ($) {
16
+ 'use strict';
17
+
18
+ // Helper variable to create unique names for the transport iframes:
19
+ var counter = 0;
20
+
21
+ // The iframe transport accepts three additional options:
22
+ // options.fileInput: a jQuery collection of file input fields
23
+ // options.paramName: the parameter name for the file form data,
24
+ // overrides the name property of the file input field(s)
25
+ // options.formData: an array of objects with name and value properties,
26
+ // equivalent to the return data of .serializeArray(), e.g.:
27
+ // [{name: 'a', value: 1}, {name: 'b', value: 2}]
28
+ $.ajaxTransport('iframe', function (options) {
29
+ if (options.async && (options.type === 'POST' || options.type === 'GET')) {
30
+ var form,
31
+ iframe;
32
+ return {
33
+ send: function (_, completeCallback) {
34
+ form = $('<form style="display:none;"></form>');
35
+ // javascript:false as initial iframe src
36
+ // prevents warning popups on HTTPS in IE6.
37
+ // IE versions below IE8 cannot set the name property of
38
+ // elements that have already been added to the DOM,
39
+ // so we set the name along with the iframe HTML markup:
40
+ iframe = $(
41
+ '<iframe src="javascript:false;" name="iframe-transport-' +
42
+ (counter += 1) + '"></iframe>'
43
+ ).bind('load', function () {
44
+ var fileInputClones;
45
+ iframe
46
+ .unbind('load')
47
+ .bind('load', function () {
48
+ var response;
49
+ // Wrap in a try/catch block to catch exceptions thrown
50
+ // when trying to access cross-domain iframe contents:
51
+ try {
52
+ response = iframe.contents();
53
+ // Google Chrome and Firefox do not throw an
54
+ // exception when calling iframe.contents() on
55
+ // cross-domain requests, so we unify the response:
56
+ if (!response.length || !response[0].firstChild) {
57
+ throw new Error();
58
+ }
59
+ } catch (e) {
60
+ response = undefined;
61
+ }
62
+ // The complete callback returns the
63
+ // iframe content document as response object:
64
+ completeCallback(
65
+ 200,
66
+ 'success',
67
+ {'iframe': response}
68
+ );
69
+ // Fix for IE endless progress bar activity bug
70
+ // (happens on form submits to iframe targets):
71
+ $('<iframe src="javascript:false;"></iframe>')
72
+ .appendTo(form);
73
+ form.remove();
74
+ });
75
+ form
76
+ .prop('target', iframe.prop('name'))
77
+ .prop('action', options.url)
78
+ .prop('method', options.type);
79
+ if (options.formData) {
80
+ $.each(options.formData, function (index, field) {
81
+ $('<input type="hidden"/>')
82
+ .prop('name', field.name)
83
+ .val(field.value)
84
+ .appendTo(form);
85
+ });
86
+ }
87
+ if (options.fileInput && options.fileInput.length &&
88
+ options.type === 'POST') {
89
+ fileInputClones = options.fileInput.clone();
90
+ // Insert a clone for each file input field:
91
+ options.fileInput.after(function (index) {
92
+ return fileInputClones[index];
93
+ });
94
+ if (options.paramName) {
95
+ options.fileInput.each(function () {
96
+ $(this).prop('name', options.paramName);
97
+ });
98
+ }
99
+ // Appending the file input fields to the hidden form
100
+ // removes them from their original location:
101
+ form
102
+ .append(options.fileInput)
103
+ .prop('enctype', 'multipart/form-data')
104
+ // enctype must be set as encoding for IE:
105
+ .prop('encoding', 'multipart/form-data');
106
+ }
107
+ form.submit();
108
+ // Insert the file input fields at their original location
109
+ // by replacing the clones with the originals:
110
+ if (fileInputClones && fileInputClones.length) {
111
+ options.fileInput.each(function (index, input) {
112
+ var clone = $(fileInputClones[index]);
113
+ $(input).prop('name', clone.prop('name'));
114
+ clone.replaceWith(input);
115
+ });
116
+ }
117
+ });
118
+ form.append(iframe).appendTo(document.body);
119
+ },
120
+ abort: function () {
121
+ if (iframe) {
122
+ // javascript:false as iframe src aborts the request
123
+ // and prevents warning popups on HTTPS in IE6.
124
+ // concat is used to avoid the "Script URL" JSLint error:
125
+ iframe
126
+ .unbind('load')
127
+ .prop('src', 'javascript'.concat(':false;'));
128
+ }
129
+ if (form) {
130
+ form.remove();
131
+ }
132
+ }
133
+ };
134
+ }
135
+ });
136
+
137
+ // The iframe transport returns the iframe content document as response.
138
+ // The following adds converters from iframe to text, json, html, and script:
139
+ $.ajaxSetup({
140
+ converters: {
141
+ 'iframe text': function (iframe) {
142
+ return $(iframe[0].body).text();
143
+ },
144
+ 'iframe json': function (iframe) {
145
+ return $.parseJSON($(iframe[0].body).text());
146
+ },
147
+ 'iframe html': function (iframe) {
148
+ return $(iframe[0].body).html();
149
+ },
150
+ 'iframe script': function (iframe) {
151
+ return $.globalEval($(iframe[0].body).text());
152
+ }
153
+ }
154
+ });
155
+
156
+ }(jQuery));
@@ -0,0 +1,108 @@
1
+ /*
2
+ * jQuery postMessage Transport Plugin 1.0
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2011, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://creativecommons.org/licenses/MIT/
10
+ */
11
+
12
+ /*jslint unparam: true, nomen: true */
13
+ /*global jQuery, window, document */
14
+
15
+ (function ($) {
16
+ 'use strict';
17
+
18
+ var counter = 0,
19
+ names = [
20
+ 'accepts',
21
+ 'cache',
22
+ 'contents',
23
+ 'contentType',
24
+ 'crossDomain',
25
+ 'data',
26
+ 'dataType',
27
+ 'headers',
28
+ 'ifModified',
29
+ 'mimeType',
30
+ 'password',
31
+ 'processData',
32
+ 'timeout',
33
+ 'traditional',
34
+ 'type',
35
+ 'url',
36
+ 'username'
37
+ ],
38
+ convert = function (p) {
39
+ return p;
40
+ };
41
+
42
+ $.ajaxSetup({
43
+ converters: {
44
+ 'postmessage text': convert,
45
+ 'postmessage json': convert,
46
+ 'postmessage html': convert
47
+ }
48
+ });
49
+
50
+ $.ajaxTransport('postmessage', function (options) {
51
+ if (options.postMessage && window.postMessage) {
52
+ var iframe,
53
+ loc = $('<a>').prop('href', options.postMessage)[0],
54
+ target = loc.protocol + '//' + loc.host,
55
+ xhrUpload = options.xhr().upload;
56
+ return {
57
+ send: function (_, completeCallback) {
58
+ var message = {
59
+ id: 'postmessage-transport-' + (counter += 1)
60
+ },
61
+ eventName = 'message.' + message.id;
62
+ iframe = $(
63
+ '<iframe style="display:none;" src="' +
64
+ options.postMessage + '" name="' +
65
+ message.id + '"></iframe>'
66
+ ).bind('load', function () {
67
+ $.each(names, function (i, name) {
68
+ message[name] = options[name];
69
+ });
70
+ message.dataType = message.dataType.replace('postmessage ', '');
71
+ $(window).bind(eventName, function (e) {
72
+ e = e.originalEvent;
73
+ var data = e.data,
74
+ ev;
75
+ if (e.origin === target && data.id === message.id) {
76
+ if (data.type === 'progress') {
77
+ ev = document.createEvent('Event');
78
+ ev.initEvent(data.type, false, true);
79
+ $.extend(ev, data);
80
+ xhrUpload.dispatchEvent(ev);
81
+ } else {
82
+ completeCallback(
83
+ data.status,
84
+ data.statusText,
85
+ {postmessage: data.result},
86
+ data.headers
87
+ );
88
+ iframe.remove();
89
+ $(window).unbind(eventName);
90
+ }
91
+ }
92
+ });
93
+ iframe[0].contentWindow.postMessage(
94
+ message,
95
+ target
96
+ );
97
+ }).appendTo(document.body);
98
+ },
99
+ abort: function () {
100
+ if (iframe) {
101
+ iframe.remove();
102
+ }
103
+ }
104
+ };
105
+ }
106
+ });
107
+
108
+ }(jQuery));
@@ -0,0 +1,76 @@
1
+ /*
2
+ * jQuery XDomainRequest Transport Plugin 1.0.1
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2011, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://creativecommons.org/licenses/MIT/
10
+ *
11
+ * Based on Julian Aubourg's ajaxHooks xdr.js:
12
+ * https://github.com/jaubourg/ajaxHooks/
13
+ */
14
+
15
+ /*jslint unparam: true */
16
+ /*global jQuery, window, XDomainRequest */
17
+
18
+ (function ($) {
19
+ 'use strict';
20
+ if (window.XDomainRequest) {
21
+ jQuery.ajaxTransport(function (s) {
22
+ if (s.crossDomain && s.async) {
23
+ if (s.timeout) {
24
+ s.xdrTimeout = s.timeout;
25
+ delete s.timeout;
26
+ }
27
+ var xdr;
28
+ return {
29
+ send: function (headers, completeCallback) {
30
+ function callback(status, statusText, responses, responseHeaders) {
31
+ xdr.onload = xdr.onerror = xdr.ontimeout = jQuery.noop;
32
+ xdr = null;
33
+ completeCallback(status, statusText, responses, responseHeaders);
34
+ }
35
+ xdr = new XDomainRequest();
36
+ // XDomainRequest only supports GET and POST:
37
+ if (s.type === 'DELETE') {
38
+ s.url = s.url + (/\?/.test(s.url) ? '&' : '?') +
39
+ '_method=DELETE';
40
+ s.type = 'POST';
41
+ } else if (s.type === 'PUT') {
42
+ s.url = s.url + (/\?/.test(s.url) ? '&' : '?') +
43
+ '_method=PUT';
44
+ s.type = 'POST';
45
+ }
46
+ xdr.open(s.type, s.url);
47
+ xdr.onload = function () {
48
+ callback(
49
+ 200,
50
+ 'OK',
51
+ {text: xdr.responseText},
52
+ 'Content-Type: ' + xdr.contentType
53
+ );
54
+ };
55
+ xdr.onerror = function () {
56
+ callback(404, 'Not Found');
57
+ };
58
+ if (s.xdrTimeout) {
59
+ xdr.ontimeout = function () {
60
+ callback(0, 'timeout');
61
+ };
62
+ xdr.timeout = s.xdrTimeout;
63
+ }
64
+ xdr.send((s.hasContent && s.data) || null);
65
+ },
66
+ abort: function () {
67
+ if (xdr) {
68
+ xdr.onerror = jQuery.noop();
69
+ xdr.abort();
70
+ }
71
+ }
72
+ };
73
+ }
74
+ });
75
+ }
76
+ }(jQuery));
@@ -0,0 +1,100 @@
1
+ @charset 'UTF-8';
2
+ /*
3
+ * jQuery File Upload UI Plugin CSS 5.0.6
4
+ * https://github.com/blueimp/jQuery-File-Upload
5
+ *
6
+ * Copyright 2010, Sebastian Tschan
7
+ * https://blueimp.net
8
+ *
9
+ * Licensed under the MIT license:
10
+ * http://creativecommons.org/licenses/MIT/
11
+ */
12
+
13
+ .fileupload-buttonbar .ui-button input {
14
+ position: absolute;
15
+ top: 0;
16
+ right: 0;
17
+ margin: 0;
18
+ border: solid transparent;
19
+ border-width: 0 0 100px 200px;
20
+ opacity: 0;
21
+ filter: alpha(opacity=0);
22
+ -o-transform: translate(250px, -50px) scale(1);
23
+ -moz-transform: translate(-300px, 0) scale(4);
24
+ direction: ltr;
25
+ cursor: pointer;
26
+ }
27
+
28
+ .fileinput-button {
29
+ overflow: hidden;
30
+ }
31
+
32
+ /* Fix for IE 6: */
33
+ *html .fileinput-button {
34
+ padding: 2px 0;
35
+ }
36
+
37
+ /* Fix for IE 7: */
38
+ *+html .fileinput-button {
39
+ padding: 2px 0;
40
+ }
41
+
42
+ .fileupload-buttonbar {
43
+ padding: 0.2em 0.4em;
44
+ }
45
+
46
+ .fileupload-buttonbar .ui-button {
47
+ vertical-align: middle;
48
+ }
49
+
50
+ .fileupload-content {
51
+ padding: 0.2em 0.4em;
52
+ border-top-width: 0;
53
+ }
54
+
55
+ .fileupload-content .ui-progressbar {
56
+ width: 200px;
57
+ height: 20px;
58
+ }
59
+
60
+ .fileupload-content .ui-progressbar-value {
61
+ background: url(pbar-ani.gif);
62
+ }
63
+
64
+ .fileupload-content .fileupload-progressbar {
65
+ width: 400px;
66
+ margin: 10px 0;
67
+ }
68
+
69
+ .files {
70
+ margin: 10px 0;
71
+ border-collapse: collapse;
72
+ }
73
+
74
+ .files td {
75
+ padding: 5px;
76
+ border-spacing: 5px;
77
+ }
78
+
79
+ .files img {
80
+ border: none;
81
+ }
82
+
83
+ .files .name {
84
+ padding: 0 10px;
85
+ }
86
+
87
+ .files .size {
88
+ padding: 0 10px 0 0;
89
+ text-align: right;
90
+ white-space: nowrap;
91
+ }
92
+
93
+ .ui-state-disabled .ui-state-disabled {
94
+ opacity: 1;
95
+ filter: alpha(opacity=100);
96
+ }
97
+
98
+ .ui-state-disabled input {
99
+ cursor: default;
100
+ }
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery.fileupload-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Semyon Perepelitsa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-08 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: This gem packages jQuery File Upload plugin and it's dependencies for
15
+ Rails asset pipeline.
16
+ email:
17
+ - sema@sema.in
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - Rakefile
25
+ - jquery.fileupload-rails.gemspec
26
+ - lib/jquery.fileupload-rails.rb
27
+ - lib/jquery.fileupload-rails/version.rb
28
+ - vendor/assets/javascripts/jquery.fileupload-ui.js
29
+ - vendor/assets/javascripts/jquery.fileupload.js
30
+ - vendor/assets/javascripts/jquery.iframe-transport.js
31
+ - vendor/assets/javascripts/jquery.postmessage-transport.js
32
+ - vendor/assets/javascripts/jquery.xdr-transport.js
33
+ - vendor/assets/stylesheets/jquery.fileupload-ui.css
34
+ homepage: https://github.com/semaperepelitsa/jquery.fileupload-rails
35
+ licenses: []
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project: jquery.fileupload-rails
54
+ rubygems_version: 1.8.11
55
+ signing_key:
56
+ specification_version: 3
57
+ summary: Use jQuery File Upload plugin with Rails 3
58
+ test_files: []
59
+ has_rdoc: