avatars_for_rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +138 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +91 -0
- data/Rakefile +29 -0
- data/app/controllers/avatars_controller.rb +109 -0
- data/app/models/avatar.rb +138 -0
- data/app/views/avatars/_errors.html.erb +6 -0
- data/app/views/avatars/_form.html.erb +128 -0
- data/app/views/avatars/_includes.html.erb +14 -0
- data/app/views/avatars/_list.html.erb +39 -0
- data/app/views/avatars/_new.html.erb +15 -0
- data/app/views/avatars/_precrop.html.erb +38 -0
- data/app/views/avatars/destroy.js.erb +2 -0
- data/app/views/avatars/edit.html.erb +8 -0
- data/app/views/avatars/index.html.erb +4 -0
- data/app/views/avatars/new.html.erb +1 -0
- data/app/views/avatars/show.html.erb +8 -0
- data/app/views/avatars/update.js.erb +6 -0
- data/avatars_for_rails.gemspec +40 -0
- data/config/locales/en.yml +28 -0
- data/config/routes.rb +6 -0
- data/lib/avatars_for_rails/avatars_controller_config.rb +4 -0
- data/lib/avatars_for_rails.rb +27 -0
- data/lib/generators/avatars_for_rails/install_generator.rb +28 -0
- data/lib/generators/avatars_for_rails/templates/initializer.rb +11 -0
- data/lib/generators/avatars_for_rails/templates/migration.rb +20 -0
- data/lib/generators/avatars_for_rails/templates/public/images/Jcrop.gif +0 -0
- data/lib/generators/avatars_for_rails/templates/public/images/cancel.png +0 -0
- data/lib/generators/avatars_for_rails/templates/public/images/pbar-ani.gif +0 -0
- data/lib/generators/avatars_for_rails/templates/public/images/rails.png +0 -0
- data/lib/generators/avatars_for_rails/templates/public/javascripts/application.js +2 -0
- data/lib/generators/avatars_for_rails/templates/public/javascripts/avatars.js +8 -0
- data/lib/generators/avatars_for_rails/templates/public/javascripts/controls.js +965 -0
- data/lib/generators/avatars_for_rails/templates/public/javascripts/dragdrop.js +974 -0
- data/lib/generators/avatars_for_rails/templates/public/javascripts/effects.js +1123 -0
- data/lib/generators/avatars_for_rails/templates/public/javascripts/jquery-ui.min.js +401 -0
- data/lib/generators/avatars_for_rails/templates/public/javascripts/jquery.Jcrop.min.js +163 -0
- data/lib/generators/avatars_for_rails/templates/public/javascripts/jquery.fileupload-ui.js +259 -0
- data/lib/generators/avatars_for_rails/templates/public/javascripts/jquery.fileupload.js +475 -0
- data/lib/generators/avatars_for_rails/templates/public/javascripts/jquery.form.js +815 -0
- data/lib/generators/avatars_for_rails/templates/public/javascripts/jquery.js +7179 -0
- data/lib/generators/avatars_for_rails/templates/public/javascripts/prototype.js +6001 -0
- data/lib/generators/avatars_for_rails/templates/public/javascripts/rails.js +158 -0
- data/lib/generators/avatars_for_rails/templates/public/stylesheets/.gitkeep +0 -0
- data/lib/generators/avatars_for_rails/templates/public/stylesheets/avatars.css +115 -0
- data/lib/generators/avatars_for_rails/templates/public/stylesheets/jquery.Jcrop.css +35 -0
- data/lib/generators/avatars_for_rails/templates/public/stylesheets/jquery.fileupload-ui.css +70 -0
- data/spec/avatars_for_rails_spec.rb +7 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/actor.rb +7 -0
- data/spec/dummy/app/views/layouts/application.html.erb +20 -0
- data/spec/dummy/config/application.rb +46 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +26 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +35 -0
- data/spec/dummy/config/initializers/avatars_for_rails.rb +6 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +60 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20110411073237_create_actors.rb +13 -0
- data/spec/dummy/db/migrate/20110411073238_create_avatars.rb +21 -0
- data/spec/dummy/db/schema.rb +32 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/images/Jcrop.gif +0 -0
- data/spec/dummy/public/images/cancel.png +0 -0
- data/spec/dummy/public/images/pbar-ani.gif +0 -0
- data/spec/dummy/public/images/rails.png +0 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/javascripts/avatars.js +8 -0
- data/spec/dummy/public/javascripts/controls.js +965 -0
- data/spec/dummy/public/javascripts/dragdrop.js +974 -0
- data/spec/dummy/public/javascripts/effects.js +1123 -0
- data/spec/dummy/public/javascripts/jquery-ui.min.js +401 -0
- data/spec/dummy/public/javascripts/jquery.Jcrop.min.js +163 -0
- data/spec/dummy/public/javascripts/jquery.fileupload-ui.js +259 -0
- data/spec/dummy/public/javascripts/jquery.fileupload.js +475 -0
- data/spec/dummy/public/javascripts/jquery.form.js +815 -0
- data/spec/dummy/public/javascripts/jquery.js +7179 -0
- data/spec/dummy/public/javascripts/prototype.js +6001 -0
- data/spec/dummy/public/javascripts/rails.js +158 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/public/stylesheets/avatars.css +115 -0
- data/spec/dummy/public/stylesheets/jquery.Jcrop.css +35 -0
- data/spec/dummy/public/stylesheets/jquery.fileupload-ui.css +70 -0
- data/spec/dummy/public/system/logos/1/actor/stream20110411-3539-1e9l1hn-0.jpg +0 -0
- data/spec/dummy/public/system/logos/1/original/stream20110411-3539-1e9l1hn-0.jpg +0 -0
- data/spec/dummy/public/system/logos/1/profile/stream20110411-3539-1e9l1hn-0.jpg +0 -0
- data/spec/dummy/public/system/logos/1/representation/stream20110411-3539-1e9l1hn-0.jpg +0 -0
- data/spec/dummy/public/system/logos/1/tie/stream20110411-3539-1e9l1hn-0.jpg +0 -0
- data/spec/dummy/public/system/logos/2/actor/stream20110411-3539-1hlzauh-0.jpeg +0 -0
- data/spec/dummy/public/system/logos/2/original/stream20110411-3539-1hlzauh-0.jpeg +0 -0
- data/spec/dummy/public/system/logos/2/profile/stream20110411-3539-1hlzauh-0.jpeg +0 -0
- data/spec/dummy/public/system/logos/2/representation/stream20110411-3539-1hlzauh-0.jpeg +0 -0
- data/spec/dummy/public/system/logos/2/tie/stream20110411-3539-1hlzauh-0.jpeg +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/integration/navigation_spec.rb +9 -0
- data/spec/spec_helper.rb +33 -0
- metadata +333 -0
@@ -0,0 +1,475 @@
|
|
1
|
+
/*
|
2
|
+
* jQuery File Upload Plugin 3.4
|
3
|
+
*
|
4
|
+
* Copyright 2010, Sebastian Tschan, AQUANTUM
|
5
|
+
* Licensed under the MIT license:
|
6
|
+
* http://creativecommons.org/licenses/MIT/
|
7
|
+
*
|
8
|
+
* https://blueimp.net
|
9
|
+
* http://www.aquantum.de
|
10
|
+
*/
|
11
|
+
|
12
|
+
/*jslint browser: true */
|
13
|
+
/*global File, FileReader, FormData, unescape, jQuery */
|
14
|
+
|
15
|
+
(function ($) {
|
16
|
+
|
17
|
+
var FileUpload,
|
18
|
+
methods;
|
19
|
+
|
20
|
+
FileUpload = function (container) {
|
21
|
+
var fileUpload = this,
|
22
|
+
uploadForm = (container.is('form') ? container : container.find('form').first()),
|
23
|
+
fileInput = uploadForm.find('input:file').first(),
|
24
|
+
settings = {
|
25
|
+
namespace: 'file_upload',
|
26
|
+
cssClass: 'file_upload',
|
27
|
+
dragDropSupport: true,
|
28
|
+
dropZone: container,
|
29
|
+
url: uploadForm.attr('action'),
|
30
|
+
method: uploadForm.attr('method'),
|
31
|
+
fieldName: fileInput.attr('name'),
|
32
|
+
multipart: true,
|
33
|
+
multiFileRequest: false,
|
34
|
+
formData: function () {
|
35
|
+
return uploadForm.serializeArray();
|
36
|
+
},
|
37
|
+
withCredentials: false,
|
38
|
+
forceIframeUpload: false
|
39
|
+
},
|
40
|
+
documentListeners = {},
|
41
|
+
dropZoneListeners = {},
|
42
|
+
fileInputListeners = {},
|
43
|
+
undef = 'undefined',
|
44
|
+
func = 'function',
|
45
|
+
num = 'number',
|
46
|
+
protocolRegExp = /^http(s)?:\/\//,
|
47
|
+
|
48
|
+
MultiLoader = function (callBack, numberComplete) {
|
49
|
+
var loaded = 0;
|
50
|
+
this.complete = function () {
|
51
|
+
loaded += 1;
|
52
|
+
if (loaded === numberComplete) {
|
53
|
+
callBack();
|
54
|
+
}
|
55
|
+
};
|
56
|
+
},
|
57
|
+
|
58
|
+
isXHRUploadCapable = function () {
|
59
|
+
return typeof XMLHttpRequest !== undef && typeof File !== undef && (
|
60
|
+
!settings.multipart || typeof FormData !== undef || typeof FileReader !== undef
|
61
|
+
);
|
62
|
+
},
|
63
|
+
|
64
|
+
initEventHandlers = function () {
|
65
|
+
if (settings.dragDropSupport) {
|
66
|
+
if (typeof settings.onDocumentDragEnter === func) {
|
67
|
+
documentListeners['dragenter.' + settings.namespace] = settings.onDocumentDragEnter;
|
68
|
+
}
|
69
|
+
if (typeof settings.onDocumentDragLeave === func) {
|
70
|
+
documentListeners['dragleave.' + settings.namespace] = settings.onDocumentDragLeave;
|
71
|
+
}
|
72
|
+
documentListeners['dragover.' + settings.namespace] = fileUpload.onDocumentDragOver;
|
73
|
+
documentListeners['drop.' + settings.namespace] = fileUpload.onDocumentDrop;
|
74
|
+
$(document).bind(documentListeners);
|
75
|
+
if (typeof settings.onDragEnter === func) {
|
76
|
+
dropZoneListeners['dragenter.' + settings.namespace] = settings.onDragEnter;
|
77
|
+
}
|
78
|
+
if (typeof settings.onDragLeave === func) {
|
79
|
+
dropZoneListeners['dragleave.' + settings.namespace] = settings.onDragLeave;
|
80
|
+
}
|
81
|
+
dropZoneListeners['dragover.' + settings.namespace] = fileUpload.onDragOver;
|
82
|
+
dropZoneListeners['drop.' + settings.namespace] = fileUpload.onDrop;
|
83
|
+
settings.dropZone.bind(dropZoneListeners);
|
84
|
+
}
|
85
|
+
fileInputListeners['change.' + settings.namespace] = fileUpload.onChange;
|
86
|
+
fileInput.bind(fileInputListeners);
|
87
|
+
},
|
88
|
+
|
89
|
+
removeEventHandlers = function () {
|
90
|
+
$.each(documentListeners, function (key, value) {
|
91
|
+
$(document).unbind(key, value);
|
92
|
+
});
|
93
|
+
$.each(dropZoneListeners, function (key, value) {
|
94
|
+
settings.dropZone.unbind(key, value);
|
95
|
+
});
|
96
|
+
$.each(fileInputListeners, function (key, value) {
|
97
|
+
fileInput.unbind(key, value);
|
98
|
+
});
|
99
|
+
},
|
100
|
+
|
101
|
+
initUploadEventHandlers = function (files, index, xhr, settings) {
|
102
|
+
if (typeof settings.onProgress === func) {
|
103
|
+
xhr.upload.onprogress = function (e) {
|
104
|
+
settings.onProgress(e, files, index, xhr, settings);
|
105
|
+
};
|
106
|
+
}
|
107
|
+
if (typeof settings.onLoad === func) {
|
108
|
+
xhr.onload = function (e) {
|
109
|
+
settings.onLoad(e, files, index, xhr, settings);
|
110
|
+
};
|
111
|
+
}
|
112
|
+
if (typeof settings.onAbort === func) {
|
113
|
+
xhr.onabort = function (e) {
|
114
|
+
settings.onAbort(e, files, index, xhr, settings);
|
115
|
+
};
|
116
|
+
}
|
117
|
+
if (typeof settings.onError === func) {
|
118
|
+
xhr.onerror = function (e) {
|
119
|
+
settings.onError(e, files, index, xhr, settings);
|
120
|
+
};
|
121
|
+
}
|
122
|
+
},
|
123
|
+
|
124
|
+
getFormData = function (settings) {
|
125
|
+
if (typeof settings.formData === func) {
|
126
|
+
return settings.formData();
|
127
|
+
} else if ($.isArray(settings.formData)) {
|
128
|
+
return settings.formData;
|
129
|
+
} else if (settings.formData) {
|
130
|
+
var formData = [];
|
131
|
+
$.each(settings.formData, function (name, value) {
|
132
|
+
formData.push({name: name, value: value});
|
133
|
+
});
|
134
|
+
return formData;
|
135
|
+
}
|
136
|
+
return [];
|
137
|
+
},
|
138
|
+
|
139
|
+
isSameDomain = function (url) {
|
140
|
+
if (protocolRegExp.test(url)) {
|
141
|
+
var host = location.host,
|
142
|
+
indexStart = location.protocol.length + 2,
|
143
|
+
index = url.indexOf(host, indexStart),
|
144
|
+
pathIndex = index + host.length;
|
145
|
+
if ((index === indexStart || index === url.indexOf('@', indexStart) + 1) &&
|
146
|
+
(url.length === pathIndex || $.inArray(url.charAt(pathIndex), ['/', '?', '#']) !== -1)) {
|
147
|
+
return true;
|
148
|
+
}
|
149
|
+
return false;
|
150
|
+
}
|
151
|
+
return true;
|
152
|
+
},
|
153
|
+
|
154
|
+
nonMultipartUpload = function (file, xhr, sameDomain) {
|
155
|
+
if (sameDomain) {
|
156
|
+
xhr.setRequestHeader('X-File-Name', unescape(encodeURIComponent(file.name)));
|
157
|
+
}
|
158
|
+
xhr.setRequestHeader('Content-Type', file.type);
|
159
|
+
xhr.send(file);
|
160
|
+
},
|
161
|
+
|
162
|
+
formDataUpload = function (files, xhr, settings) {
|
163
|
+
var formData = new FormData(),
|
164
|
+
i;
|
165
|
+
$.each(getFormData(settings), function (index, field) {
|
166
|
+
formData.append(field.name, field.value);
|
167
|
+
});
|
168
|
+
for (i = 0; i < files.length; i += 1) {
|
169
|
+
formData.append(settings.fieldName, files[i]);
|
170
|
+
}
|
171
|
+
xhr.send(formData);
|
172
|
+
},
|
173
|
+
|
174
|
+
loadFileContent = function (file, callBack) {
|
175
|
+
var fileReader = new FileReader();
|
176
|
+
fileReader.onload = function (e) {
|
177
|
+
file.content = e.target.result;
|
178
|
+
callBack();
|
179
|
+
};
|
180
|
+
fileReader.readAsBinaryString(file);
|
181
|
+
},
|
182
|
+
|
183
|
+
buildMultiPartFormData = function (boundary, files, fields) {
|
184
|
+
var doubleDash = '--',
|
185
|
+
crlf = '\r\n',
|
186
|
+
formData = '';
|
187
|
+
$.each(fields, function (index, field) {
|
188
|
+
formData += doubleDash + boundary + crlf +
|
189
|
+
'Content-Disposition: form-data; name="' +
|
190
|
+
unescape(encodeURIComponent(field.name)) +
|
191
|
+
'"' + crlf + crlf +
|
192
|
+
unescape(encodeURIComponent(field.value)) + crlf;
|
193
|
+
});
|
194
|
+
$.each(files, function (index, file) {
|
195
|
+
formData += doubleDash + boundary + crlf +
|
196
|
+
'Content-Disposition: form-data; name="' +
|
197
|
+
unescape(encodeURIComponent(settings.fieldName)) +
|
198
|
+
'"; filename="' + unescape(encodeURIComponent(file.name)) + '"' + crlf +
|
199
|
+
'Content-Type: ' + file.type + crlf + crlf +
|
200
|
+
file.content + crlf;
|
201
|
+
});
|
202
|
+
formData += doubleDash + boundary + doubleDash + crlf;
|
203
|
+
return formData;
|
204
|
+
},
|
205
|
+
|
206
|
+
fileReaderUpload = function (files, xhr, settings) {
|
207
|
+
var boundary = '----MultiPartFormBoundary' + (new Date()).getTime(),
|
208
|
+
loader,
|
209
|
+
i;
|
210
|
+
xhr.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + boundary);
|
211
|
+
loader = new MultiLoader(function () {
|
212
|
+
xhr.sendAsBinary(buildMultiPartFormData(
|
213
|
+
boundary,
|
214
|
+
files,
|
215
|
+
getFormData(settings)
|
216
|
+
));
|
217
|
+
}, files.length);
|
218
|
+
for (i = 0; i < files.length; i += 1) {
|
219
|
+
loadFileContent(files[i], loader.complete);
|
220
|
+
}
|
221
|
+
},
|
222
|
+
|
223
|
+
upload = function (files, index, xhr, settings) {
|
224
|
+
var sameDomain = isSameDomain(settings.url),
|
225
|
+
filesToUpload;
|
226
|
+
initUploadEventHandlers(files, index, xhr, settings);
|
227
|
+
xhr.open(settings.method, settings.url, true);
|
228
|
+
if (sameDomain) {
|
229
|
+
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
230
|
+
} else if (settings.withCredentials) {
|
231
|
+
xhr.withCredentials = true;
|
232
|
+
}
|
233
|
+
if (!settings.multipart) {
|
234
|
+
nonMultipartUpload(files[index], xhr, sameDomain);
|
235
|
+
} else {
|
236
|
+
if (typeof index === num) {
|
237
|
+
filesToUpload = [files[index]];
|
238
|
+
} else {
|
239
|
+
filesToUpload = files;
|
240
|
+
}
|
241
|
+
if (typeof FormData !== undef) {
|
242
|
+
formDataUpload(filesToUpload, xhr, settings);
|
243
|
+
} else if (typeof FileReader !== undef) {
|
244
|
+
fileReaderUpload(filesToUpload, xhr, settings);
|
245
|
+
} else {
|
246
|
+
$.error('Browser does neither support FormData nor FileReader interface');
|
247
|
+
}
|
248
|
+
}
|
249
|
+
},
|
250
|
+
|
251
|
+
handleUpload = function (event, files, index) {
|
252
|
+
var xhr = new XMLHttpRequest(),
|
253
|
+
uploadSettings = $.extend({}, settings);
|
254
|
+
if (typeof settings.initUpload === func) {
|
255
|
+
settings.initUpload(
|
256
|
+
event,
|
257
|
+
files,
|
258
|
+
index,
|
259
|
+
xhr,
|
260
|
+
uploadSettings,
|
261
|
+
function () {
|
262
|
+
upload(files, index, xhr, uploadSettings);
|
263
|
+
}
|
264
|
+
);
|
265
|
+
} else {
|
266
|
+
upload(files, index, xhr, uploadSettings);
|
267
|
+
}
|
268
|
+
},
|
269
|
+
|
270
|
+
handleFiles = function (event, files) {
|
271
|
+
var i;
|
272
|
+
if (settings.multiFileRequest) {
|
273
|
+
handleUpload(event, files);
|
274
|
+
} else {
|
275
|
+
for (i = 0; i < files.length; i += 1) {
|
276
|
+
handleUpload(event, files, i);
|
277
|
+
}
|
278
|
+
}
|
279
|
+
},
|
280
|
+
|
281
|
+
legacyUploadFormDataInit = function (input, settings) {
|
282
|
+
var formData = getFormData(settings);
|
283
|
+
uploadForm.find(':input').not(':disabled')
|
284
|
+
.attr('disabled', true)
|
285
|
+
.addClass(settings.namespace + '_disabled');
|
286
|
+
$.each(formData, function (index, field) {
|
287
|
+
$('<input type="hidden"/>')
|
288
|
+
.attr('name', field.name)
|
289
|
+
.val(field.value)
|
290
|
+
.addClass(settings.namespace + '_form_data')
|
291
|
+
.insertBefore(fileInput);
|
292
|
+
});
|
293
|
+
input.insertAfter(fileInput);
|
294
|
+
},
|
295
|
+
|
296
|
+
legacyUploadFormDataReset = function (input, settings) {
|
297
|
+
input.remove();
|
298
|
+
uploadForm.find('.' + settings.namespace + '_disabled')
|
299
|
+
.removeAttr('disabled')
|
300
|
+
.removeClass(settings.namespace + '_disabled');
|
301
|
+
uploadForm.find('.' + settings.namespace + '_form_data').remove();
|
302
|
+
},
|
303
|
+
|
304
|
+
legacyUpload = function (input, iframe, settings) {
|
305
|
+
iframe
|
306
|
+
.unbind('abort')
|
307
|
+
.bind('abort', function (e) {
|
308
|
+
iframe.readyState = 0;
|
309
|
+
// javascript:false as iframe src prevents warning popups on HTTPS in IE6
|
310
|
+
// concat is used here to prevent the "Script URL" JSLint error:
|
311
|
+
iframe.unbind('load').attr('src', 'javascript'.concat(':false;'));
|
312
|
+
if (typeof settings.onAbort === func) {
|
313
|
+
settings.onAbort(e, [{name: input.val(), type: null, size: null}], 0, iframe, settings);
|
314
|
+
}
|
315
|
+
})
|
316
|
+
.unbind('load')
|
317
|
+
.bind('load', function (e) {
|
318
|
+
iframe.readyState = 4;
|
319
|
+
if (typeof settings.onLoad === func) {
|
320
|
+
settings.onLoad(e, [{name: input.val(), type: null, size: null}], 0, iframe, settings);
|
321
|
+
}
|
322
|
+
});
|
323
|
+
uploadForm
|
324
|
+
.attr('action', settings.url)
|
325
|
+
.attr('target', iframe.attr('name'));
|
326
|
+
legacyUploadFormDataInit(input, settings);
|
327
|
+
iframe.readyState = 2;
|
328
|
+
uploadForm.get(0).submit();
|
329
|
+
legacyUploadFormDataReset(input, settings);
|
330
|
+
},
|
331
|
+
|
332
|
+
handleLegacyUpload = function (event, input) {
|
333
|
+
// javascript:false as iframe src prevents warning popups on HTTPS in IE6:
|
334
|
+
var iframe = $('<iframe src="javascript:false;" style="display:none" name="iframe_' +
|
335
|
+
settings.namespace + '_' + (new Date()).getTime() + '"></iframe>'),
|
336
|
+
uploadSettings = $.extend({}, settings);
|
337
|
+
iframe.readyState = 0;
|
338
|
+
iframe.abort = function () {
|
339
|
+
iframe.trigger('abort');
|
340
|
+
};
|
341
|
+
iframe.bind('load', function () {
|
342
|
+
iframe.unbind('load');
|
343
|
+
if (typeof settings.initUpload === func) {
|
344
|
+
settings.initUpload(
|
345
|
+
event,
|
346
|
+
[{name: input.val(), type: null, size: null}],
|
347
|
+
0,
|
348
|
+
iframe,
|
349
|
+
uploadSettings,
|
350
|
+
function () {
|
351
|
+
legacyUpload(input, iframe, uploadSettings);
|
352
|
+
}
|
353
|
+
);
|
354
|
+
} else {
|
355
|
+
legacyUpload(input, iframe, uploadSettings);
|
356
|
+
}
|
357
|
+
}).appendTo(uploadForm);
|
358
|
+
},
|
359
|
+
|
360
|
+
resetFileInput = function () {
|
361
|
+
var inputClone = fileInput.clone(true);
|
362
|
+
$('<form/>').append(inputClone).get(0).reset();
|
363
|
+
fileInput.replaceWith(inputClone);
|
364
|
+
fileInput = inputClone;
|
365
|
+
};
|
366
|
+
|
367
|
+
this.onDocumentDragOver = function (e) {
|
368
|
+
if (typeof settings.onDocumentDragOver === func &&
|
369
|
+
settings.onDocumentDragOver(e) === false) {
|
370
|
+
return false;
|
371
|
+
}
|
372
|
+
e.preventDefault();
|
373
|
+
};
|
374
|
+
|
375
|
+
this.onDocumentDrop = function (e) {
|
376
|
+
if (typeof settings.onDocumentDrop === func &&
|
377
|
+
settings.onDocumentDrop(e) === false) {
|
378
|
+
return false;
|
379
|
+
}
|
380
|
+
e.preventDefault();
|
381
|
+
};
|
382
|
+
|
383
|
+
this.onDragOver = function (e) {
|
384
|
+
if (typeof settings.onDragOver === func &&
|
385
|
+
settings.onDragOver(e) === false) {
|
386
|
+
return false;
|
387
|
+
}
|
388
|
+
var dataTransfer = e.originalEvent.dataTransfer;
|
389
|
+
if (dataTransfer) {
|
390
|
+
dataTransfer.dropEffect = dataTransfer.effectAllowed = 'copy';
|
391
|
+
}
|
392
|
+
e.preventDefault();
|
393
|
+
};
|
394
|
+
|
395
|
+
this.onDrop = function (e) {
|
396
|
+
if (typeof settings.onDrop === func &&
|
397
|
+
settings.onDrop(e) === false) {
|
398
|
+
return false;
|
399
|
+
}
|
400
|
+
var dataTransfer = e.originalEvent.dataTransfer;
|
401
|
+
if (dataTransfer && dataTransfer.files && isXHRUploadCapable()) {
|
402
|
+
handleFiles(e, dataTransfer.files);
|
403
|
+
}
|
404
|
+
e.preventDefault();
|
405
|
+
};
|
406
|
+
|
407
|
+
this.onChange = function (e) {
|
408
|
+
if (typeof settings.onChange === func &&
|
409
|
+
settings.onChange(e) === false) {
|
410
|
+
return false;
|
411
|
+
}
|
412
|
+
if (!settings.forceIframeUpload && e.target.files && isXHRUploadCapable()) {
|
413
|
+
handleFiles(e, e.target.files);
|
414
|
+
} else {
|
415
|
+
handleLegacyUpload(e, $(e.target));
|
416
|
+
}
|
417
|
+
resetFileInput();
|
418
|
+
};
|
419
|
+
|
420
|
+
this.init = function (options) {
|
421
|
+
if (options) {
|
422
|
+
$.extend(settings, options);
|
423
|
+
}
|
424
|
+
if (container.data(settings.namespace)) {
|
425
|
+
$.error('FileUpload with namespace "' + settings.namespace + '" already assigned to this element');
|
426
|
+
return;
|
427
|
+
}
|
428
|
+
container
|
429
|
+
.data(settings.namespace, fileUpload)
|
430
|
+
.addClass(settings.cssClass);
|
431
|
+
settings.dropZone.addClass(settings.cssClass);
|
432
|
+
initEventHandlers();
|
433
|
+
};
|
434
|
+
|
435
|
+
this.destroy = function () {
|
436
|
+
removeEventHandlers();
|
437
|
+
container
|
438
|
+
.removeData(settings.namespace)
|
439
|
+
.removeClass(settings.cssClass);
|
440
|
+
settings.dropZone.removeClass(settings.cssClass);
|
441
|
+
};
|
442
|
+
};
|
443
|
+
|
444
|
+
methods = {
|
445
|
+
init : function (options) {
|
446
|
+
return this.each(function () {
|
447
|
+
(new FileUpload($(this))).init(options);
|
448
|
+
});
|
449
|
+
},
|
450
|
+
|
451
|
+
destroy : function (namespace) {
|
452
|
+
return this.each(function () {
|
453
|
+
namespace = namespace ? namespace : 'file_upload';
|
454
|
+
var fileUpload = $(this).data(namespace);
|
455
|
+
if (fileUpload) {
|
456
|
+
fileUpload.destroy();
|
457
|
+
} else {
|
458
|
+
$.error('No FileUpload with namespace "' + namespace + '" assigned to this element');
|
459
|
+
}
|
460
|
+
});
|
461
|
+
|
462
|
+
}
|
463
|
+
};
|
464
|
+
|
465
|
+
$.fn.fileUpload = function (method) {
|
466
|
+
if (methods[method]) {
|
467
|
+
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
468
|
+
} else if (typeof method === 'object' || !method) {
|
469
|
+
return methods.init.apply(this, arguments);
|
470
|
+
} else {
|
471
|
+
$.error('Method ' + method + ' does not exist on jQuery.fileUpload');
|
472
|
+
}
|
473
|
+
};
|
474
|
+
|
475
|
+
}(jQuery));
|