Skip to content

Commit c29e5cc

Browse files
committed
Refactored @-options handling to save bytes.
If an option is set to @, the global option of the same name as the key will be used, e.g.: acceptFileTypes: '@', // acceptFileTypes If the options set contains a property prefix, the global options key will be the prefix plus the option key, concatenated in camel-case spelling, e.g.: prefix: 'loadImage', acceptFileTypes: '@', // loadImageAcceptFileTypes If the prefix is set to true, the action of the options set will be used as key.
1 parent 921c816 commit c29e5cc

File tree

3 files changed

+50
-36
lines changed

3 files changed

+50
-36
lines changed

js/jquery.fileupload-image.js

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload Image Preview & Resize Plugin 1.1
2+
* jQuery File Upload Image Preview & Resize Plugin 1.2
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2013, Sebastian Tschan
@@ -35,31 +35,35 @@
3535
// Prepend to the default processQueue:
3636
$.blueimp.fileupload.prototype.options.processQueue.unshift(
3737
{
38-
action: 'loadImage',
38+
action: 'loadImageMetaData',
3939
// Always trigger this action,
4040
// even if the previous action was rejected:
4141
always: true,
42-
fileTypes: '@loadImageFileTypes',
43-
maxFileSize: '@loadImageMaxFileSize',
44-
noRevoke: '@loadImageNoRevoke',
45-
disabled: '@disableImageLoad'
42+
disableImageHead: '@',
43+
disableExif: '@',
44+
disableExifThumbnail: '@',
45+
disableExifSub: '@',
46+
disableExifGps: '@',
47+
disabled: '@disableImageMetaDataLoad'
4648
},
4749
{
48-
action: 'loadImageMetaData',
49-
disabled: '@disableImageMetaDataLoad',
50-
disableImageHead: '@disableImageHead',
51-
disableExif: '@disableExif',
52-
disableExifThumbnail: '@disableExifThumbnail',
53-
disableExifSub: '@disableExifSub',
54-
disableExifGps: '@disableExifGps'
50+
action: 'loadImage',
51+
// Use the action as prefix for the "@" options:
52+
prefix: true,
53+
fileTypes: '@',
54+
maxFileSize: '@',
55+
noRevoke: '@',
56+
disabled: '@disableImageLoad'
5557
},
5658
{
5759
action: 'resizeImage',
58-
maxWidth: '@imageMaxWidth',
59-
maxHeight: '@imageMaxHeight',
60-
minWidth: '@imageMinWidth',
61-
minHeight: '@imageMinHeight',
62-
crop: '@imageCrop',
60+
// Use "image" as prefix for the "@" options:
61+
prefix: 'image',
62+
maxWidth: '@',
63+
maxHeight: '@',
64+
minWidth: '@',
65+
minHeight: '@',
66+
crop: '@',
6367
disabled: '@disableImageResize'
6468
},
6569
{
@@ -72,14 +76,19 @@
7276
},
7377
{
7478
action: 'resizeImage',
75-
maxWidth: '@previewMaxWidth',
76-
maxHeight: '@previewMaxHeight',
77-
minWidth: '@previewMinWidth',
78-
minHeight: '@previewMinHeight',
79-
crop: '@previewCrop',
80-
orientation: '@previewOrientation',
81-
thumbnail: '@previewThumbnail',
82-
canvas: '@previewAsCanvas',
79+
// Always trigger this action,
80+
// even if the previous action was rejected:
81+
always: true,
82+
// Use "preview" as prefix for the "@" options:
83+
prefix: 'preview',
84+
maxWidth: '@',
85+
maxHeight: '@',
86+
minWidth: '@',
87+
minHeight: '@',
88+
crop: '@',
89+
orientation: '@',
90+
thumbnail: '@',
91+
canvas: '@',
8392
disabled: '@disableImagePreview'
8493
},
8594
{
@@ -98,7 +107,7 @@
98107
// matched against the file type:
99108
loadImageFileTypes: /^image\/(gif|jpeg|png)$/,
100109
// The maximum file size of images to load:
101-
loadImageMaxFileSize: 5000000, // 5MB
110+
loadImageMaxFileSize: 10000000, // 10MB
102111
// The maximum width of resized images:
103112
imageMaxWidth: 1920,
104113
// The maximum height of resized images:
@@ -119,7 +128,7 @@
119128
// Define if preview images should be cropped or only scaled:
120129
previewCrop: false,
121130
// Define if preview images should be resized as canvas elements:
122-
previewAsCanvas: true
131+
previewCanvas: true
123132
},
124133

125134
processActions: {

js/jquery.fileupload-process.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload Processing Plugin 1.1
2+
* jQuery File Upload Processing Plugin 1.2
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2012, Sebastian Tschan
@@ -98,11 +98,16 @@
9898
_transformProcessQueue: function (options) {
9999
var processQueue = [];
100100
$.each(options.processQueue, function () {
101-
var settings = {};
101+
var settings = {},
102+
action = this.action,
103+
prefix = this.prefix === true ? action : this.prefix;
102104
$.each(this, function (key, value) {
103105
if ($.type(value) === 'string' &&
104106
value.charAt(0) === '@') {
105-
settings[key] = options[value.slice(1)];
107+
settings[key] = options[
108+
value.slice(1) || prefix ? prefix +
109+
key.charAt(0).toUpperCase() + key.slice(1) : key
110+
];
106111
} else {
107112
settings[key] = value;
108113
}

js/jquery.fileupload-validate.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload Validation Plugin 1.0.2
2+
* jQuery File Upload Validation Plugin 1.1
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2013, Sebastian Tschan
@@ -37,10 +37,10 @@
3737
// even if the previous action was rejected:
3838
always: true,
3939
// Options taken from the global options map:
40-
acceptFileTypes: '@acceptFileTypes',
41-
maxFileSize: '@maxFileSize',
42-
minFileSize: '@minFileSize',
43-
maxNumberOfFiles: '@maxNumberOfFiles',
40+
acceptFileTypes: '@',
41+
maxFileSize: '@',
42+
minFileSize: '@',
43+
maxNumberOfFiles: '@',
4444
disabled: '@disableValidation'
4545
}
4646
);

0 commit comments

Comments
 (0)