Skip to content

Commit 7f7028a

Browse files
committed
Added functionallity for upload pictures without title and description
1 parent ee9f461 commit 7f7028a

25 files changed

+2591
-273
lines changed
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,85 @@
1+
/*
2+
* jQuery XDomainRequest Transport Plugin 1.1.2
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+
function callback(status, statusText, responses, responseHeaders) {
40+
xdr.onload = xdr.onerror = xdr.ontimeout = $.noop;
41+
xdr = null;
42+
completeCallback(status, statusText, responses, responseHeaders);
43+
}
44+
xdr = new XDomainRequest();
45+
// XDomainRequest only supports GET and POST:
46+
if (s.type === 'DELETE') {
47+
s.url = s.url + (/\?/.test(s.url) ? '&' : '?') +
48+
'_method=DELETE';
49+
s.type = 'POST';
50+
} else if (s.type === 'PUT') {
51+
s.url = s.url + (/\?/.test(s.url) ? '&' : '?') +
52+
'_method=PUT';
53+
s.type = 'POST';
54+
}
55+
xdr.open(s.type, s.url);
56+
xdr.onload = function () {
57+
callback(
58+
200,
59+
'OK',
60+
{text: xdr.responseText},
61+
'Content-Type: ' + xdr.contentType
62+
);
63+
};
64+
xdr.onerror = function () {
65+
callback(404, 'Not Found');
66+
};
67+
if (s.xdrTimeout) {
68+
xdr.ontimeout = function () {
69+
callback(0, 'timeout');
70+
};
71+
xdr.timeout = s.xdrTimeout;
72+
}
73+
xdr.send((s.hasContent && s.data) || null);
74+
},
75+
abort: function () {
76+
if (xdr) {
77+
xdr.onerror = $.noop();
78+
xdr.abort();
79+
}
80+
}
81+
};
82+
}
83+
});
84+
}
85+
}));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/*
2+
* jQuery File Upload Image Processing Plugin 1.0.6
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+
/*jslint nomen: true, unparam: true, regexp: 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([
20+
'jquery',
21+
'load-image',
22+
'canvas-to-blob',
23+
'./jquery.fileupload'
24+
], factory);
25+
} else {
26+
// Browser globals:
27+
factory(
28+
window.jQuery,
29+
window.loadImage,
30+
window.canvasToBlob
31+
);
32+
}
33+
}(function ($, loadImage, canvasToBlob) {
34+
'use strict';
35+
36+
// The File Upload IP version extends the basic fileupload widget
37+
// with image processing functionality:
38+
$.widget('blueimpIP.fileupload', $.blueimp.fileupload, {
39+
40+
options: {
41+
// The regular expression to define which image files are to be
42+
// resized, given that the browser supports the operation:
43+
resizeSourceFileTypes: /^image\/(gif|jpeg|png)$/,
44+
// The maximum file size of images that are to be resized:
45+
resizeSourceMaxFileSize: 20000000, // 20MB
46+
// The maximum width of the resized images:
47+
resizeMaxWidth: undefined,
48+
// The maximum height of the resized images:
49+
resizeMaxHeight: undefined,
50+
// The minimum width of the resized images:
51+
resizeMinWidth: undefined,
52+
// The minimum height of the resized images:
53+
resizeMinHeight: undefined,
54+
55+
// The add callback is invoked as soon as files are added to the fileupload
56+
// widget (via file input selection, drag & drop or add API call).
57+
// See the basic file upload widget for more information:
58+
add: function (e, data) {
59+
$(this).fileupload('resize', data).done(function () {
60+
data.submit();
61+
});
62+
}
63+
},
64+
65+
// Resizes the image file at the given index and stores the created blob
66+
// at the original position of the files list, returns a Promise object:
67+
_resizeImage: function (files, index, options) {
68+
var that = this,
69+
file = files[index],
70+
deferred = $.Deferred(),
71+
canvas,
72+
blob;
73+
options = options || this.options;
74+
loadImage(
75+
file,
76+
function (img) {
77+
var width = img.width,
78+
height = img.height;
79+
canvas = loadImage.scale(img, {
80+
maxWidth: options.resizeMaxWidth,
81+
maxHeight: options.resizeMaxHeight,
82+
minWidth: options.resizeMinWidth,
83+
minHeight: options.resizeMinHeight,
84+
canvas: true
85+
});
86+
if (width !== canvas.width || height !== canvas.height) {
87+
canvasToBlob(canvas, function (blob) {
88+
if (!blob.name) {
89+
if (file.type === blob.type) {
90+
blob.name = file.name;
91+
} else if (file.name) {
92+
blob.name = file.name.replace(
93+
/\..+$/,
94+
'.' + blob.type.substr(6)
95+
);
96+
}
97+
}
98+
files[index] = blob;
99+
deferred.resolveWith(that);
100+
}, file);
101+
} else {
102+
deferred.resolveWith(that);
103+
}
104+
}
105+
);
106+
return deferred.promise();
107+
},
108+
109+
// Resizes the images given as files property of the data parameter,
110+
// returns a Promise object that allows to bind a done handler, which
111+
// will be invoked after processing all images is done:
112+
resize: function (data) {
113+
var that = this,
114+
options = $.extend({}, this.options, data),
115+
resizeAll = $.type(options.resizeSourceMaxFileSize) !== 'number',
116+
isXHRUpload = this._isXHRUpload(options);
117+
$.each(data.files, function (index, file) {
118+
if (isXHRUpload && that._resizeSupport &&
119+
(options.resizeMaxWidth || options.resizeMaxHeight ||
120+
options.resizeMinWidth || options.resizeMinHeight) &&
121+
(resizeAll || file.size < options.resizeSourceMaxFileSize) &&
122+
options.resizeSourceFileTypes.test(file.type)) {
123+
that._processing += 1;
124+
if (that._processing === 1) {
125+
that.element.addClass('fileupload-processing');
126+
}
127+
that._processingQueue = that._processingQueue.pipe(function () {
128+
var deferred = $.Deferred();
129+
that._resizeImage(
130+
data.files,
131+
index,
132+
options
133+
).done(function () {
134+
that._processing -= 1;
135+
if (that._processing === 0) {
136+
that.element
137+
.removeClass('fileupload-processing');
138+
}
139+
deferred.resolveWith(that);
140+
});
141+
return deferred.promise();
142+
});
143+
}
144+
});
145+
return this._processingQueue;
146+
},
147+
148+
_create: function () {
149+
$.blueimp.fileupload.prototype._create.call(this);
150+
this._processing = 0;
151+
this._processingQueue = $.Deferred().resolveWith(this).promise();
152+
this._resizeSupport = canvasToBlob && canvasToBlob(
153+
document.createElement('canvas'),
154+
$.noop
155+
);
156+
}
157+
158+
});
159+
160+
}));

0 commit comments

Comments
 (0)