jquery-fileupload-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,165 @@
1
+ /*
2
+ * jQuery Iframe Transport Plugin 1.3
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://www.opensource.org/licenses/MIT
10
+ */
11
+
12
+ /*jslint unparam: true, nomen: true */
13
+ /*global define, window, document */
14
+
15
+ (function (factory) {
16
+ 'use strict';
17
+ if (typeof define === 'function' && define.amd) {
18
+ // Register as an anonymous AMD module:
19
+ define(['jquery'], factory);
20
+ } else {
21
+ // Browser globals:
22
+ factory(window.jQuery);
23
+ }
24
+ }(function ($) {
25
+ 'use strict';
26
+
27
+ // Helper variable to create unique names for the transport iframes:
28
+ var counter = 0;
29
+
30
+ // The iframe transport accepts three additional options:
31
+ // options.fileInput: a jQuery collection of file input fields
32
+ // options.paramName: the parameter name for the file form data,
33
+ // overrides the name property of the file input field(s)
34
+ // options.formData: an array of objects with name and value properties,
35
+ // equivalent to the return data of .serializeArray(), e.g.:
36
+ // [{name: 'a', value: 1}, {name: 'b', value: 2}]
37
+ $.ajaxTransport('iframe', function (options) {
38
+ if (options.async && (options.type === 'POST' || options.type === 'GET')) {
39
+ var form,
40
+ iframe;
41
+ return {
42
+ send: function (_, completeCallback) {
43
+ form = $('<form style="display:none;"></form>');
44
+ // javascript:false as initial iframe src
45
+ // prevents warning popups on HTTPS in IE6.
46
+ // IE versions below IE8 cannot set the name property of
47
+ // elements that have already been added to the DOM,
48
+ // so we set the name along with the iframe HTML markup:
49
+ iframe = $(
50
+ '<iframe src="javascript:false;" name="iframe-transport-' +
51
+ (counter += 1) + '"></iframe>'
52
+ ).bind('load', function () {
53
+ var fileInputClones;
54
+ iframe
55
+ .unbind('load')
56
+ .bind('load', function () {
57
+ var response;
58
+ // Wrap in a try/catch block to catch exceptions thrown
59
+ // when trying to access cross-domain iframe contents:
60
+ try {
61
+ response = iframe.contents();
62
+ // Google Chrome and Firefox do not throw an
63
+ // exception when calling iframe.contents() on
64
+ // cross-domain requests, so we unify the response:
65
+ if (!response.length || !response[0].firstChild) {
66
+ throw new Error();
67
+ }
68
+ } catch (e) {
69
+ response = undefined;
70
+ }
71
+ // The complete callback returns the
72
+ // iframe content document as response object:
73
+ completeCallback(
74
+ 200,
75
+ 'success',
76
+ {'iframe': response}
77
+ );
78
+ // Fix for IE endless progress bar activity bug
79
+ // (happens on form submits to iframe targets):
80
+ $('<iframe src="javascript:false;"></iframe>')
81
+ .appendTo(form);
82
+ form.remove();
83
+ });
84
+ form
85
+ .prop('target', iframe.prop('name'))
86
+ .prop('action', options.url)
87
+ .prop('method', options.type);
88
+ if (options.formData) {
89
+ $.each(options.formData, function (index, field) {
90
+ $('<input type="hidden"/>')
91
+ .prop('name', field.name)
92
+ .val(field.value)
93
+ .appendTo(form);
94
+ });
95
+ }
96
+ if (options.fileInput && options.fileInput.length &&
97
+ options.type === 'POST') {
98
+ fileInputClones = options.fileInput.clone();
99
+ // Insert a clone for each file input field:
100
+ options.fileInput.after(function (index) {
101
+ return fileInputClones[index];
102
+ });
103
+ if (options.paramName) {
104
+ options.fileInput.each(function () {
105
+ $(this).prop('name', options.paramName);
106
+ });
107
+ }
108
+ // Appending the file input fields to the hidden form
109
+ // removes them from their original location:
110
+ form
111
+ .append(options.fileInput)
112
+ .prop('enctype', 'multipart/form-data')
113
+ // enctype must be set as encoding for IE:
114
+ .prop('encoding', 'multipart/form-data');
115
+ }
116
+ form.submit();
117
+ // Insert the file input fields at their original location
118
+ // by replacing the clones with the originals:
119
+ if (fileInputClones && fileInputClones.length) {
120
+ options.fileInput.each(function (index, input) {
121
+ var clone = $(fileInputClones[index]);
122
+ $(input).prop('name', clone.prop('name'));
123
+ clone.replaceWith(input);
124
+ });
125
+ }
126
+ });
127
+ form.append(iframe).appendTo(document.body);
128
+ },
129
+ abort: function () {
130
+ if (iframe) {
131
+ // javascript:false as iframe src aborts the request
132
+ // and prevents warning popups on HTTPS in IE6.
133
+ // concat is used to avoid the "Script URL" JSLint error:
134
+ iframe
135
+ .unbind('load')
136
+ .prop('src', 'javascript'.concat(':false;'));
137
+ }
138
+ if (form) {
139
+ form.remove();
140
+ }
141
+ }
142
+ };
143
+ }
144
+ });
145
+
146
+ // The iframe transport returns the iframe content document as response.
147
+ // The following adds converters from iframe to text, json, html, and script:
148
+ $.ajaxSetup({
149
+ converters: {
150
+ 'iframe text': function (iframe) {
151
+ return $(iframe[0].body).text();
152
+ },
153
+ 'iframe json': function (iframe) {
154
+ return $.parseJSON($(iframe[0].body).text());
155
+ },
156
+ 'iframe html': function (iframe) {
157
+ return $(iframe[0].body).html();
158
+ },
159
+ 'iframe script': function (iframe) {
160
+ return $.globalEval($(iframe[0].body).text());
161
+ }
162
+ }
163
+ });
164
+
165
+ }));
@@ -0,0 +1,27 @@
1
+ /*
2
+ * jQuery File Upload Plugin Localization Example 6.5
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2012, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://www.opensource.org/licenses/MIT
10
+ */
11
+
12
+ window.locale = {
13
+ "fileupload": {
14
+ "errors": {
15
+ "maxFileSize": "File is too big",
16
+ "minFileSize": "File is too small",
17
+ "acceptFileTypes": "Filetype not allowed",
18
+ "maxNumberOfFiles": "Max number of files exceeded",
19
+ "uploadedBytes": "Uploaded bytes exceed file size",
20
+ "emptyResult": "Empty file upload result"
21
+ },
22
+ "error": "Error",
23
+ "start": "Start",
24
+ "cancel": "Cancel",
25
+ "destroy": "Delete"
26
+ }
27
+ };
@@ -0,0 +1,282 @@
1
+ /*
2
+ * jQuery UI Widget 1.8.18+amd
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
6
+ * Dual licensed under the MIT or GPL Version 2 licenses.
7
+ * http://jquery.org/license
8
+ *
9
+ * http://docs.jquery.com/UI/Widget
10
+ */
11
+
12
+ (function (factory) {
13
+ if (typeof define === "function" && define.amd) {
14
+ // Register as an anonymous AMD module:
15
+ define(["jquery"], factory);
16
+ } else {
17
+ // Browser globals:
18
+ factory(jQuery);
19
+ }
20
+ }(function( $, undefined ) {
21
+
22
+ // jQuery 1.4+
23
+ if ( $.cleanData ) {
24
+ var _cleanData = $.cleanData;
25
+ $.cleanData = function( elems ) {
26
+ for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
27
+ try {
28
+ $( elem ).triggerHandler( "remove" );
29
+ // http://bugs.jquery.com/ticket/8235
30
+ } catch( e ) {}
31
+ }
32
+ _cleanData( elems );
33
+ };
34
+ } else {
35
+ var _remove = $.fn.remove;
36
+ $.fn.remove = function( selector, keepData ) {
37
+ return this.each(function() {
38
+ if ( !keepData ) {
39
+ if ( !selector || $.filter( selector, [ this ] ).length ) {
40
+ $( "*", this ).add( [ this ] ).each(function() {
41
+ try {
42
+ $( this ).triggerHandler( "remove" );
43
+ // http://bugs.jquery.com/ticket/8235
44
+ } catch( e ) {}
45
+ });
46
+ }
47
+ }
48
+ return _remove.call( $(this), selector, keepData );
49
+ });
50
+ };
51
+ }
52
+
53
+ $.widget = function( name, base, prototype ) {
54
+ var namespace = name.split( "." )[ 0 ],
55
+ fullName;
56
+ name = name.split( "." )[ 1 ];
57
+ fullName = namespace + "-" + name;
58
+
59
+ if ( !prototype ) {
60
+ prototype = base;
61
+ base = $.Widget;
62
+ }
63
+
64
+ // create selector for plugin
65
+ $.expr[ ":" ][ fullName ] = function( elem ) {
66
+ return !!$.data( elem, name );
67
+ };
68
+
69
+ $[ namespace ] = $[ namespace ] || {};
70
+ $[ namespace ][ name ] = function( options, element ) {
71
+ // allow instantiation without initializing for simple inheritance
72
+ if ( arguments.length ) {
73
+ this._createWidget( options, element );
74
+ }
75
+ };
76
+
77
+ var basePrototype = new base();
78
+ // we need to make the options hash a property directly on the new instance
79
+ // otherwise we'll modify the options hash on the prototype that we're
80
+ // inheriting from
81
+ // $.each( basePrototype, function( key, val ) {
82
+ // if ( $.isPlainObject(val) ) {
83
+ // basePrototype[ key ] = $.extend( {}, val );
84
+ // }
85
+ // });
86
+ basePrototype.options = $.extend( true, {}, basePrototype.options );
87
+ $[ namespace ][ name ].prototype = $.extend( true, basePrototype, {
88
+ namespace: namespace,
89
+ widgetName: name,
90
+ widgetEventPrefix: $[ namespace ][ name ].prototype.widgetEventPrefix || name,
91
+ widgetBaseClass: fullName
92
+ }, prototype );
93
+
94
+ $.widget.bridge( name, $[ namespace ][ name ] );
95
+ };
96
+
97
+ $.widget.bridge = function( name, object ) {
98
+ $.fn[ name ] = function( options ) {
99
+ var isMethodCall = typeof options === "string",
100
+ args = Array.prototype.slice.call( arguments, 1 ),
101
+ returnValue = this;
102
+
103
+ // allow multiple hashes to be passed on init
104
+ options = !isMethodCall && args.length ?
105
+ $.extend.apply( null, [ true, options ].concat(args) ) :
106
+ options;
107
+
108
+ // prevent calls to internal methods
109
+ if ( isMethodCall && options.charAt( 0 ) === "_" ) {
110
+ return returnValue;
111
+ }
112
+
113
+ if ( isMethodCall ) {
114
+ this.each(function() {
115
+ var instance = $.data( this, name ),
116
+ methodValue = instance && $.isFunction( instance[options] ) ?
117
+ instance[ options ].apply( instance, args ) :
118
+ instance;
119
+ // TODO: add this back in 1.9 and use $.error() (see #5972)
120
+ // if ( !instance ) {
121
+ // throw "cannot call methods on " + name + " prior to initialization; " +
122
+ // "attempted to call method '" + options + "'";
123
+ // }
124
+ // if ( !$.isFunction( instance[options] ) ) {
125
+ // throw "no such method '" + options + "' for " + name + " widget instance";
126
+ // }
127
+ // var methodValue = instance[ options ].apply( instance, args );
128
+ if ( methodValue !== instance && methodValue !== undefined ) {
129
+ returnValue = methodValue;
130
+ return false;
131
+ }
132
+ });
133
+ } else {
134
+ this.each(function() {
135
+ var instance = $.data( this, name );
136
+ if ( instance ) {
137
+ instance.option( options || {} )._init();
138
+ } else {
139
+ $.data( this, name, new object( options, this ) );
140
+ }
141
+ });
142
+ }
143
+
144
+ return returnValue;
145
+ };
146
+ };
147
+
148
+ $.Widget = function( options, element ) {
149
+ // allow instantiation without initializing for simple inheritance
150
+ if ( arguments.length ) {
151
+ this._createWidget( options, element );
152
+ }
153
+ };
154
+
155
+ $.Widget.prototype = {
156
+ widgetName: "widget",
157
+ widgetEventPrefix: "",
158
+ options: {
159
+ disabled: false
160
+ },
161
+ _createWidget: function( options, element ) {
162
+ // $.widget.bridge stores the plugin instance, but we do it anyway
163
+ // so that it's stored even before the _create function runs
164
+ $.data( element, this.widgetName, this );
165
+ this.element = $( element );
166
+ this.options = $.extend( true, {},
167
+ this.options,
168
+ this._getCreateOptions(),
169
+ options );
170
+
171
+ var self = this;
172
+ this.element.bind( "remove." + this.widgetName, function() {
173
+ self.destroy();
174
+ });
175
+
176
+ this._create();
177
+ this._trigger( "create" );
178
+ this._init();
179
+ },
180
+ _getCreateOptions: function() {
181
+ return $.metadata && $.metadata.get( this.element[0] )[ this.widgetName ];
182
+ },
183
+ _create: function() {},
184
+ _init: function() {},
185
+
186
+ destroy: function() {
187
+ this.element
188
+ .unbind( "." + this.widgetName )
189
+ .removeData( this.widgetName );
190
+ this.widget()
191
+ .unbind( "." + this.widgetName )
192
+ .removeAttr( "aria-disabled" )
193
+ .removeClass(
194
+ this.widgetBaseClass + "-disabled " +
195
+ "ui-state-disabled" );
196
+ },
197
+
198
+ widget: function() {
199
+ return this.element;
200
+ },
201
+
202
+ option: function( key, value ) {
203
+ var options = key;
204
+
205
+ if ( arguments.length === 0 ) {
206
+ // don't return a reference to the internal hash
207
+ return $.extend( {}, this.options );
208
+ }
209
+
210
+ if (typeof key === "string" ) {
211
+ if ( value === undefined ) {
212
+ return this.options[ key ];
213
+ }
214
+ options = {};
215
+ options[ key ] = value;
216
+ }
217
+
218
+ this._setOptions( options );
219
+
220
+ return this;
221
+ },
222
+ _setOptions: function( options ) {
223
+ var self = this;
224
+ $.each( options, function( key, value ) {
225
+ self._setOption( key, value );
226
+ });
227
+
228
+ return this;
229
+ },
230
+ _setOption: function( key, value ) {
231
+ this.options[ key ] = value;
232
+
233
+ if ( key === "disabled" ) {
234
+ this.widget()
235
+ [ value ? "addClass" : "removeClass"](
236
+ this.widgetBaseClass + "-disabled" + " " +
237
+ "ui-state-disabled" )
238
+ .attr( "aria-disabled", value );
239
+ }
240
+
241
+ return this;
242
+ },
243
+
244
+ enable: function() {
245
+ return this._setOption( "disabled", false );
246
+ },
247
+ disable: function() {
248
+ return this._setOption( "disabled", true );
249
+ },
250
+
251
+ _trigger: function( type, event, data ) {
252
+ var prop, orig,
253
+ callback = this.options[ type ];
254
+
255
+ data = data || {};
256
+ event = $.Event( event );
257
+ event.type = ( type === this.widgetEventPrefix ?
258
+ type :
259
+ this.widgetEventPrefix + type ).toLowerCase();
260
+ // the original event may come from any element
261
+ // so we need to reset the target on the new event
262
+ event.target = this.element[ 0 ];
263
+
264
+ // copy original event properties over to the new event
265
+ orig = event.originalEvent;
266
+ if ( orig ) {
267
+ for ( prop in orig ) {
268
+ if ( !( prop in event ) ) {
269
+ event[ prop ] = orig[ prop ];
270
+ }
271
+ }
272
+ }
273
+
274
+ this.element.trigger( event, data );
275
+
276
+ return !( $.isFunction(callback) &&
277
+ callback.call( this.element[0], event, data ) === false ||
278
+ event.isDefaultPrevented() );
279
+ }
280
+ };
281
+
282
+ }));