Skip to content

Commit 57a67b8

Browse files
committed
Merge branch 'master' of github.com:ET-CS/django-jquery-file-upload
2 parents e76eff5 + 569279b commit 57a67b8

9 files changed

+1189
-450
lines changed

fileupload/models.py

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def save(self, *args, **kwargs):
2222
self.slug = self.file.name
2323
super(Picture, self).save(*args, **kwargs)
2424

25+
# remove to leave file.
2526
def delete(self, *args, **kwargs):
2627
self.file.delete(False)
2728
super(Picture, self).delete(*args, **kwargs)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* jQuery postMessage Transport Plugin 1.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://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+
var counter = 0,
28+
names = [
29+
'accepts',
30+
'cache',
31+
'contents',
32+
'contentType',
33+
'crossDomain',
34+
'data',
35+
'dataType',
36+
'headers',
37+
'ifModified',
38+
'mimeType',
39+
'password',
40+
'processData',
41+
'timeout',
42+
'traditional',
43+
'type',
44+
'url',
45+
'username'
46+
],
47+
convert = function (p) {
48+
return p;
49+
};
50+
51+
$.ajaxSetup({
52+
converters: {
53+
'postmessage text': convert,
54+
'postmessage json': convert,
55+
'postmessage html': convert
56+
}
57+
});
58+
59+
$.ajaxTransport('postmessage', function (options) {
60+
if (options.postMessage && window.postMessage) {
61+
var iframe,
62+
loc = $('<a>').prop('href', options.postMessage)[0],
63+
target = loc.protocol + '//' + loc.host,
64+
xhrUpload = options.xhr().upload;
65+
return {
66+
send: function (_, completeCallback) {
67+
var message = {
68+
id: 'postmessage-transport-' + (counter += 1)
69+
},
70+
eventName = 'message.' + message.id;
71+
iframe = $(
72+
'<iframe style="display:none;" src="' +
73+
options.postMessage + '" name="' +
74+
message.id + '"></iframe>'
75+
).bind('load', function () {
76+
$.each(names, function (i, name) {
77+
message[name] = options[name];
78+
});
79+
message.dataType = message.dataType.replace('postmessage ', '');
80+
$(window).bind(eventName, function (e) {
81+
e = e.originalEvent;
82+
var data = e.data,
83+
ev;
84+
if (e.origin === target && data.id === message.id) {
85+
if (data.type === 'progress') {
86+
ev = document.createEvent('Event');
87+
ev.initEvent(data.type, false, true);
88+
$.extend(ev, data);
89+
xhrUpload.dispatchEvent(ev);
90+
} else {
91+
completeCallback(
92+
data.status,
93+
data.statusText,
94+
{postmessage: data.result},
95+
data.headers
96+
);
97+
iframe.remove();
98+
$(window).unbind(eventName);
99+
}
100+
}
101+
});
102+
iframe[0].contentWindow.postMessage(
103+
message,
104+
target
105+
);
106+
}).appendTo(document.body);
107+
},
108+
abort: function () {
109+
if (iframe) {
110+
iframe.remove();
111+
}
112+
}
113+
};
114+
}
115+
});
116+
117+
}));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* jQuery XDomainRequest Transport Plugin 1.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+
* Based on Julian Aubourg's ajaxHooks xdr.js:
12+
* https://github.com/jaubourg/ajaxHooks/
13+
*/
14+
15+
/*jslint unparam: true */
16+
/*global define, window, XDomainRequest */
17+
18+
(function (factory) {
19+
'use strict';
20+
if (typeof define === 'function' && define.amd) {
21+
// Register as an anonymous AMD module:
22+
define(['jquery'], factory);
23+
} else {
24+
// Browser globals:
25+
factory(window.jQuery);
26+
}
27+
}(function ($) {
28+
'use strict';
29+
if (window.XDomainRequest && !$.support.cors) {
30+
$.ajaxTransport(function (s) {
31+
if (s.crossDomain && s.async) {
32+
if (s.timeout) {
33+
s.xdrTimeout = s.timeout;
34+
delete s.timeout;
35+
}
36+
var xdr;
37+
return {
38+
send: function (headers, completeCallback) {
39+
var addParamChar = /\?/.test(s.url) ? '&' : '?';
40+
function callback(status, statusText, responses, responseHeaders) {
41+
xdr.onload = xdr.onerror = xdr.ontimeout = $.noop;
42+
xdr = null;
43+
completeCallback(status, statusText, responses, responseHeaders);
44+
}
45+
xdr = new XDomainRequest();
46+
// XDomainRequest only supports GET and POST:
47+
if (s.type === 'DELETE') {
48+
s.url = s.url + addParamChar + '_method=DELETE';
49+
s.type = 'POST';
50+
} else if (s.type === 'PUT') {
51+
s.url = s.url + addParamChar + '_method=PUT';
52+
s.type = 'POST';
53+
} else if (s.type === 'PATCH') {
54+
s.url = s.url + addParamChar + '_method=PATCH';
55+
s.type = 'POST';
56+
}
57+
xdr.open(s.type, s.url);
58+
xdr.onload = function () {
59+
callback(
60+
200,
61+
'OK',
62+
{text: xdr.responseText},
63+
'Content-Type: ' + xdr.contentType
64+
);
65+
};
66+
xdr.onerror = function () {
67+
callback(404, 'Not Found');
68+
};
69+
if (s.xdrTimeout) {
70+
xdr.ontimeout = function () {
71+
callback(0, 'timeout');
72+
};
73+
xdr.timeout = s.xdrTimeout;
74+
}
75+
xdr.send((s.hasContent && s.data) || null);
76+
},
77+
abort: function () {
78+
if (xdr) {
79+
xdr.onerror = $.noop();
80+
xdr.abort();
81+
}
82+
}
83+
};
84+
}
85+
});
86+
}
87+
}));

fileupload/static/js/jquery.fileupload-fp.js

+21-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload File Processing Plugin 1.0
2+
* jQuery File Upload File Processing Plugin 1.2.1
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2012, Sebastian Tschan
@@ -32,9 +32,9 @@
3232
}(function ($, loadImage) {
3333
'use strict';
3434

35-
// The File Upload IP version extends the basic fileupload widget
35+
// The File Upload FP version extends the fileupload widget
3636
// with file processing functionality:
37-
$.widget('blueimpFP.fileupload', $.blueimp.fileupload, {
37+
$.widget('blueimp.fileupload', $.blueimp.fileupload, {
3838

3939
options: {
4040
// The list of file processing actions:
@@ -70,7 +70,7 @@
7070

7171
processActions: {
7272
// Loads the image given via data.files and data.index
73-
// as canvas element.
73+
// as img element if the browser supports canvas.
7474
// Accepts the options fileTypes (regular expression)
7575
// and maxFileSize (integer) to limit the files to load:
7676
load: function (data, options) {
@@ -85,28 +85,32 @@
8585
options.fileTypes.test(file.type))) {
8686
loadImage(
8787
file,
88-
function (canvas) {
89-
data.canvas = canvas;
88+
function (img) {
89+
if (!img.src) {
90+
return dfd.rejectWith(that, [data]);
91+
}
92+
data.img = img;
9093
dfd.resolveWith(that, [data]);
91-
},
92-
{canvas: true}
94+
}
9395
);
9496
} else {
9597
dfd.rejectWith(that, [data]);
9698
}
9799
return dfd.promise();
98100
},
99-
// Resizes the image given as data.canvas and updates
100-
// data.canvas with the resized image.
101+
// Resizes the image given as data.img and updates
102+
// data.canvas with the resized image as canvas element.
101103
// Accepts the options maxWidth, maxHeight, minWidth and
102104
// minHeight to scale the given image:
103105
resize: function (data, options) {
104-
if (data.canvas) {
105-
var canvas = loadImage.scale(data.canvas, options);
106-
if (canvas.width !== data.canvas.width ||
107-
canvas.height !== data.canvas.height) {
106+
var img = data.img,
107+
canvas;
108+
options = $.extend({canvas: true}, options);
109+
if (img) {
110+
canvas = loadImage.scale(img, options);
111+
if (canvas.width !== img.width ||
112+
canvas.height !== img.height) {
108113
data.canvas = canvas;
109-
data.processed = true;
110114
}
111115
}
112116
return data;
@@ -115,7 +119,7 @@
115119
// inplace at data.index of data.files:
116120
save: function (data, options) {
117121
// Do nothing if no processing has happened:
118-
if (!data.canvas || !data.processed) {
122+
if (!data.canvas) {
119123
return data;
120124
}
121125
var that = this,
@@ -208,7 +212,7 @@
208212
},
209213

210214
_create: function () {
211-
$.blueimp.fileupload.prototype._create.call(this);
215+
this._super();
212216
this._processing = 0;
213217
this._processingQueue = $.Deferred().resolveWith(this)
214218
.promise();

0 commit comments

Comments
 (0)