Permalink
Browse files

* imageTransform.type -> imageTransform.strategy

  • Loading branch information...
1 parent c763739 commit e7a952b00a6fe273bdcdf142acecadb0038a146d @RubaXa RubaXa committed Nov 20, 2013
Showing with 88 additions and 42 deletions.
  1. +21 −2 README.md
  2. +2 −2 README.ru.md
  3. +9 −9 dist/FileAPI.html5.js
  4. +1 −1 dist/FileAPI.html5.min.js
  5. +9 −9 dist/FileAPI.js
  6. +1 −1 dist/FileAPI.min.js
  7. +9 −9 lib/FileAPI.Image.js
  8. +1 −1 statics/docs.json
  9. +35 −8 tests/tests.js
View
@@ -765,12 +765,12 @@ FileAPI.Image(imageFile)
---
<a name="FileAPI.Image.resize"></a>
-### resize(width`:Number`, height`:Number`[, type`:String`])`:FileAPI.Image`
+### resize(width`:Number`, height`:Number`[, strategy`:String`])`:FileAPI.Image`
Resize image.
* width — new image width
* height — new image height
-* type — enum: `min`, `max`, `preview`. By default `undefined`.
+* strategy — enum: `min`, `max`, `preview`. By default `undefined`.
```js
FileAPI.Image(imageFile)
@@ -1377,6 +1377,25 @@ Button like link.
<a name="Changelog"></a>
## Changelog
+<ul>
+ <li>* resize: `imageTransform.type` rename to `imageTransform.strategy` (!!!)</li>
+</ul>
+
+### 2.0.2
+<ul>
+ <li>+ test: upload headers</li>
+ <li>+ test: upload + camanjs</li>
+ <li>+ test: upload + autoOrientation</li>
+ <li>FileAPI.class.php: + HTTP header Content-Type: application/json</li>
+ <li>#143: + `FileAPI.flashWebcamUrl` option</li>
+ <li>* merge v1.2.7</li>
+ <li>+ `FileAPI.formData: true` option</li>
+</il>
+
+### 2.0.1
+<ul>
+ <li>+ support 'filter' prop in imageTransform</li>
+</il>
### 2.0.0
<ul>
View
@@ -747,12 +747,12 @@ FileAPI.Image(imageFile)
---
<a name="FileAPI.Image.resize"></a>
-### resize(width`:Number`, height`:Number`[, type`:String`])`:FileAPI.Image`
+### resize(width`:Number`, height`:Number`[, strategy`:String`])`:FileAPI.Image`
Ресайз.
* width — новая ширина
* height — новая высота
-* type — enum: `min`, `max`, `preview`. По умолчанию `undefined`.
+* strategy — enum: `min`, `max`, `preview`. По умолчанию `undefined`.
```js
FileAPI.Image(imageFile)
View
@@ -1832,13 +1832,13 @@
return this.set({ sx: x, sy: y, sw: w, sh: h || w });
},
- resize: function (w, h, type){
- if( typeof h == 'string' ){
- type = h;
+ resize: function (w, h, strategy){
+ if( /min|max/.test(h) ){
Prinzhorn
Prinzhorn Nov 20, 2013

How about /(^(?:min|max)$/ ?

Mithgol
Mithgol Nov 29, 2013

…or /(?:min|max)/ at least, since non-capturing parenthes are regarded as faster than capturing.

Prinzhorn
Prinzhorn Nov 29, 2013

The first parenthesis is a typo (there's no counterpart). The point was the ^ and $ anchor, because only exact matches are relevant.

/^(?:min|max)$/

+ strategy = h;
h = w;
}
- return this.set({ dw: w, dh: h, resize: type });
+ return this.set({ dw: w, dh: h || w, resize: strategy });
},
preview: function (w, h){
@@ -1990,10 +1990,10 @@
, dw = m.dw = m.dw || sw
, dh = m.dh = m.dh || sh
, sf = sw/sh, df = dw/dh
- , type = m.resize
+ , strategy = m.resize
;
- if( type == 'preview' ){
+ if( strategy == 'preview' ){
if( dw != sw || dh != sh ){
// Make preview
var w, h;
@@ -2014,12 +2014,12 @@
}
}
}
- else if( type ){
+ else if( strategy ){
if( !(sw > dw || sh > dh) ){
dw = sw;
dh = sh;
}
- else if( type == 'min' ){
+ else if( strategy == 'min' ){
dw = round(sf < df ? min(sw, dw) : dh*sf);
dh = round(sf < df ? dw/sf : min(sh, dh));
}
@@ -2099,7 +2099,7 @@
params(img, ImgTrans);
}
else if( params.width ){
- ImgTrans[params.preview ? 'preview' : 'resize'](params.width, params.height, params.type);
+ ImgTrans[params.preview ? 'preview' : 'resize'](params.width, params.height, params.strategy);
}
else {
if( params.maxWidth && (img.width > params.maxWidth || img.height > params.maxHeight) ){
Oops, something went wrong.
View
@@ -1832,13 +1832,13 @@
return this.set({ sx: x, sy: y, sw: w, sh: h || w });
},
- resize: function (w, h, type){
- if( typeof h == 'string' ){
- type = h;
+ resize: function (w, h, strategy){
+ if( /min|max/.test(h) ){
+ strategy = h;
h = w;
}
- return this.set({ dw: w, dh: h, resize: type });
+ return this.set({ dw: w, dh: h || w, resize: strategy });
},
preview: function (w, h){
@@ -1990,10 +1990,10 @@
, dw = m.dw = m.dw || sw
, dh = m.dh = m.dh || sh
, sf = sw/sh, df = dw/dh
- , type = m.resize
+ , strategy = m.resize
;
- if( type == 'preview' ){
+ if( strategy == 'preview' ){
if( dw != sw || dh != sh ){
// Make preview
var w, h;
@@ -2014,12 +2014,12 @@
}
}
}
- else if( type ){
+ else if( strategy ){
if( !(sw > dw || sh > dh) ){
dw = sw;
dh = sh;
}
- else if( type == 'min' ){
+ else if( strategy == 'min' ){
dw = round(sf < df ? min(sw, dw) : dh*sf);
dh = round(sf < df ? dw/sf : min(sh, dh));
}
@@ -2099,7 +2099,7 @@
params(img, ImgTrans);
}
else if( params.width ){
- ImgTrans[params.preview ? 'preview' : 'resize'](params.width, params.height, params.type);
+ ImgTrans[params.preview ? 'preview' : 'resize'](params.width, params.height, params.strategy);
}
else {
if( params.maxWidth && (img.width > params.maxWidth || img.height > params.maxHeight) ){
View
Oops, something went wrong.
View
@@ -67,13 +67,13 @@
return this.set({ sx: x, sy: y, sw: w, sh: h || w });
},
- resize: function (w, h, type){
- if( typeof h == 'string' ){
- type = h;
+ resize: function (w, h, strategy){
+ if( /min|max/.test(h) ){
+ strategy = h;
h = w;
}
- return this.set({ dw: w, dh: h, resize: type });
+ return this.set({ dw: w, dh: h || w, resize: strategy });
},
preview: function (w, h){
@@ -225,10 +225,10 @@
, dw = m.dw = m.dw || sw
, dh = m.dh = m.dh || sh
, sf = sw/sh, df = dw/dh
- , type = m.resize
+ , strategy = m.resize
;
- if( type == 'preview' ){
+ if( strategy == 'preview' ){
if( dw != sw || dh != sh ){
// Make preview
var w, h;
@@ -249,12 +249,12 @@
}
}
}
- else if( type ){
+ else if( strategy ){
if( !(sw > dw || sh > dh) ){
dw = sw;
dh = sh;
}
- else if( type == 'min' ){
+ else if( strategy == 'min' ){
dw = round(sf < df ? min(sw, dw) : dh*sf);
dh = round(sf < df ? dw/sf : min(sh, dh));
}
@@ -334,7 +334,7 @@
params(img, ImgTrans);
}
else if( params.width ){
- ImgTrans[params.preview ? 'preview' : 'resize'](params.width, params.height, params.type);
+ ImgTrans[params.preview ? 'preview' : 'resize'](params.width, params.height, params.strategy);
}
else {
if( params.maxWidth && (img.width > params.maxWidth || img.height > params.maxHeight) ){
View
Oops, something went wrong.
View
@@ -382,24 +382,51 @@ module('FileAPI');
- FileAPI.html5 && test('upload + imageTransform', function (){
+ FileAPI.html5 && test('upload + imageTransform (min, max, preview)', function (){
var file = FileAPI.getFiles(uploadForm['image.jpg'])[0];
+ var queue = FileAPI.queue(start);
stop();
+
+ // strategy: 'min'
+ queue.inc();
FileAPI.upload({
url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
files: { image: file },
- imageTransform: {
- width: 100,
- height: 100,
- rotate: 'auto',
- preview: true
- },
+ imageTransform: { width: 100, height: 100, strategy: 'min' },
+ complete: function (err, res){
+ queue.next();
+ var res = FileAPI.parseJSON(res.responseText);
+ equal(res.images['image'].width, 141, 'min.width');
+ equal(res.images['image'].height, 100, 'min.height');
+ }
+ });
+
+ // strategy: 'max'
+ queue.inc();
+ FileAPI.upload({
+ url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
+ files: { image: file },
+ imageTransform: { width: 100, height: 100, strategy: 'max' },
+ complete: function (err, res){
+ queue.next();
+ var res = FileAPI.parseJSON(res.responseText);
+ equal(res.images['image'].width, 100, 'max.width');
+ equal(res.images['image'].height, 71, 'max.height');
+ }
+ });
+
+ // preview
+ queue.inc();
+ FileAPI.upload({
+ url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
+ files: { image: file },
+ imageTransform: { width: 100, height: 100, rotate: 'auto', preview: true },
complete: function (err, res){
var res = FileAPI.parseJSON(res.responseText);
imageEqual(res.images.image.dataURL, 'files/samples/'+browser+'-image-auto-100x100.jpeg', 'image auto 100x100.png', function (){
- start();
+ queue.next();
});
}
});

0 comments on commit e7a952b

Please sign in to comment.