|
1 | 1 | /*
|
2 |
| - * jQuery File Upload File Processing Plugin 1.0 |
| 2 | + * jQuery File Upload File Processing Plugin 1.2.1 |
3 | 3 | * https://github.com/blueimp/jQuery-File-Upload
|
4 | 4 | *
|
5 | 5 | * Copyright 2012, Sebastian Tschan
|
|
32 | 32 | }(function ($, loadImage) {
|
33 | 33 | 'use strict';
|
34 | 34 |
|
35 |
| - // The File Upload IP version extends the basic fileupload widget |
| 35 | + // The File Upload FP version extends the fileupload widget |
36 | 36 | // with file processing functionality:
|
37 |
| - $.widget('blueimpFP.fileupload', $.blueimp.fileupload, { |
| 37 | + $.widget('blueimp.fileupload', $.blueimp.fileupload, { |
38 | 38 |
|
39 | 39 | options: {
|
40 | 40 | // The list of file processing actions:
|
|
70 | 70 |
|
71 | 71 | processActions: {
|
72 | 72 | // Loads the image given via data.files and data.index
|
73 |
| - // as canvas element. |
| 73 | + // as img element if the browser supports canvas. |
74 | 74 | // Accepts the options fileTypes (regular expression)
|
75 | 75 | // and maxFileSize (integer) to limit the files to load:
|
76 | 76 | load: function (data, options) {
|
|
85 | 85 | options.fileTypes.test(file.type))) {
|
86 | 86 | loadImage(
|
87 | 87 | 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; |
90 | 93 | dfd.resolveWith(that, [data]);
|
91 |
| - }, |
92 |
| - {canvas: true} |
| 94 | + } |
93 | 95 | );
|
94 | 96 | } else {
|
95 | 97 | dfd.rejectWith(that, [data]);
|
96 | 98 | }
|
97 | 99 | return dfd.promise();
|
98 | 100 | },
|
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. |
101 | 103 | // Accepts the options maxWidth, maxHeight, minWidth and
|
102 | 104 | // minHeight to scale the given image:
|
103 | 105 | 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) { |
108 | 113 | data.canvas = canvas;
|
109 |
| - data.processed = true; |
110 | 114 | }
|
111 | 115 | }
|
112 | 116 | return data;
|
|
115 | 119 | // inplace at data.index of data.files:
|
116 | 120 | save: function (data, options) {
|
117 | 121 | // Do nothing if no processing has happened:
|
118 |
| - if (!data.canvas || !data.processed) { |
| 122 | + if (!data.canvas) { |
119 | 123 | return data;
|
120 | 124 | }
|
121 | 125 | var that = this,
|
|
208 | 212 | },
|
209 | 213 |
|
210 | 214 | _create: function () {
|
211 |
| - $.blueimp.fileupload.prototype._create.call(this); |
| 215 | + this._super(); |
212 | 216 | this._processing = 0;
|
213 | 217 | this._processingQueue = $.Deferred().resolveWith(this)
|
214 | 218 | .promise();
|
|
0 commit comments