Skip to content

Commit 046a671

Browse files
committed
* flash upload without files
1 parent e512549 commit 046a671

File tree

8 files changed

+143
-102
lines changed

8 files changed

+143
-102
lines changed

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ module.exports = function (grunt){
9696
watch: {
9797
scripts: {
9898
files: 'lib/**/*.js',
99-
tasks: ['build'],
99+
tasks: ['concat'],
100100
options: { interrupt: true }
101101
}
102102
}

dist/FileAPI.html5.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,9 @@
284284
flashImageUrl: 0, // @default: './FileAPI.flash.image.swf'
285285

286286
ext2mime: {
287-
jpg: 'image/jpeg'
288-
, tif: 'image/tiff'
287+
jpg: 'image/jpeg'
288+
, tif: 'image/tiff'
289+
, txt: 'text/plain'
289290
},
290291

291292
// Fallback for flash
@@ -748,8 +749,8 @@
748749

749750
_each(accept, function (ext, type){
750751
ext = new RegExp(ext.replace(/\s/g, '|'), 'i');
751-
if( ext.test(file.type) ){
752-
file.type = api.ext2mime[file.type] || type.split('/')[0] +'/'+ file.type;
752+
if( ext.test(file.type) || api.ext2mime[file.type] ){
753+
file.type = api.ext2mime[file.type] || (type.split('/')[0] +'/'+ file.type);
753754
}
754755
});
755756

@@ -2310,7 +2311,7 @@
23102311
}
23112312

23122313
data.start = -1;
2313-
data.end = data.file.FileAPIReadPosition || -1;
2314+
data.end = data.file && data.file.FileAPIReadPosition || -1;
23142315
data.retry = 0;
23152316
});
23162317
},
@@ -2484,13 +2485,14 @@
24842485
},
24852486

24862487
_send: function (options, data){
2487-
24882488
var _this = this, xhr, uid = _this.uid, url = options.url;
24892489

24902490
api.log('XHR._send:', data);
24912491

2492-
// No cache
2493-
url += (~url.indexOf('?') ? '&' : '?') + api.uid();
2492+
if( !options.cache ){
2493+
// No cache
2494+
url += (~url.indexOf('?') ? '&' : '?') + api.uid();
2495+
}
24942496

24952497
if( data.nodeName ){
24962498
// legacy

dist/FileAPI.html5.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/FileAPI.js

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,9 @@
284284
flashImageUrl: 0, // @default: './FileAPI.flash.image.swf'
285285

286286
ext2mime: {
287-
jpg: 'image/jpeg'
288-
, tif: 'image/tiff'
287+
jpg: 'image/jpeg'
288+
, tif: 'image/tiff'
289+
, txt: 'text/plain'
289290
},
290291

291292
// Fallback for flash
@@ -748,8 +749,8 @@
748749

749750
_each(accept, function (ext, type){
750751
ext = new RegExp(ext.replace(/\s/g, '|'), 'i');
751-
if( ext.test(file.type) ){
752-
file.type = api.ext2mime[file.type] || type.split('/')[0] +'/'+ file.type;
752+
if( ext.test(file.type) || api.ext2mime[file.type] ){
753+
file.type = api.ext2mime[file.type] || (type.split('/')[0] +'/'+ file.type);
753754
}
754755
});
755756

@@ -2310,7 +2311,7 @@
23102311
}
23112312

23122313
data.start = -1;
2313-
data.end = data.file.FileAPIReadPosition || -1;
2314+
data.end = data.file && data.file.FileAPIReadPosition || -1;
23142315
data.retry = 0;
23152316
});
23162317
},
@@ -2484,13 +2485,14 @@
24842485
},
24852486

24862487
_send: function (options, data){
2487-
24882488
var _this = this, xhr, uid = _this.uid, url = options.url;
24892489

24902490
api.log('XHR._send:', data);
24912491

2492-
// No cache
2493-
url += (~url.indexOf('?') ? '&' : '?') + api.uid();
2492+
if( !options.cache ){
2493+
// No cache
2494+
url += (~url.indexOf('?') ? '&' : '?') + api.uid();
2495+
}
24942496

24952497
if( data.nodeName ){
24962498
// legacy
@@ -2997,13 +2999,14 @@
29972999
})();
29983000

29993001

3000-
api.support.flash
3001-
&& (0
3002-
|| !api.html5 || !api.support.html5
3003-
|| (api.cors && !api.support.cors)
3004-
|| (api.media && !api.support.media)
3005-
)
3006-
&& (function (){
3002+
3003+
api.support.flash
3004+
&& (0
3005+
|| !api.html5 || !api.support.html5
3006+
|| (api.cors && !api.support.cors)
3007+
|| (api.media && !api.support.media)
3008+
)
3009+
&& (function (){
30073010
var
30083011
_attr = api.uid()
30093012
, _retry = 0
@@ -3346,6 +3349,7 @@
33463349
})
33473350
});
33483351
}
3352+
33493353
file.__info.then(fn);
33503354
}
33513355
}
@@ -3543,7 +3547,7 @@
35433547
}
35443548
}
35453549

3546-
api.log('flash.Form.toData');
3550+
api.log('Flash.Form.toData');
35473551
fn(items);
35483552
}
35493553
});
@@ -3581,10 +3585,16 @@
35813585
}
35823586
});
35833587

3584-
if( !(fileId || flashId) ){
3588+
if( !fileId ){
3589+
flashId = _attr;
3590+
}
3591+
3592+
if( !flashId ){
3593+
api.log('[err] Flash._send: flashId -- undefined');
35853594
return this.parent.apply(this, arguments);
3586-
} else {
3587-
api.log('flash.XHR._send:', flashId, fileId, files);
3595+
}
3596+
else {
3597+
api.log('Flash.XHR._send: '+ flashId +' -> '+ fileId, files);
35883598
}
35893599

35903600
_this.xhr = {
@@ -3598,8 +3608,8 @@
35983608
flash.cmd(flashId, 'upload', {
35993609
url: _getUrl(options.url)
36003610
, data: data
3601-
, files: files
3602-
, headers: options.headers
3611+
, files: fileId ? files : null
3612+
, headers: options.headers || {}
36033613
, callback: _wrap(function upload(evt){
36043614
var type = evt.type, result = evt.result;
36053615

@@ -3731,6 +3741,7 @@
37313741
key
37323742
, flashId = api.uid()
37333743
, el = document.createElement('div')
3744+
, attempts = 10
37343745
;
37353746

37363747
for( key in opts ){
@@ -3749,7 +3760,9 @@
37493760
, wmode: 'opaque'
37503761
, flashvars: 'scale='+ opts.scale +'&callback='+_wrap(function _(){
37513762
_unwrap(_);
3752-
_setImage();
3763+
if( --attempts > 0 ){
3764+
_setImage();
3765+
}
37533766
return true;
37543767
})
37553768
}, opts));

dist/FileAPI.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/FileAPI.Flash.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@
3333
})();
3434

3535

36-
api.support.flash
37-
&& (0
38-
|| !api.html5 || !api.support.html5
39-
|| (api.cors && !api.support.cors)
40-
|| (api.media && !api.support.media)
41-
)
42-
&& (function (){
36+
37+
api.support.flash
38+
&& (0
39+
|| !api.html5 || !api.support.html5
40+
|| (api.cors && !api.support.cors)
41+
|| (api.media && !api.support.media)
42+
)
43+
&& (function (){
4344
var
4445
_attr = api.uid()
4546
, _retry = 0
@@ -382,6 +383,7 @@
382383
})
383384
});
384385
}
386+
385387
file.__info.then(fn);
386388
}
387389
}
@@ -579,7 +581,7 @@
579581
}
580582
}
581583

582-
api.log('flash.Form.toData');
584+
api.log('Flash.Form.toData');
583585
fn(items);
584586
}
585587
});
@@ -617,10 +619,16 @@
617619
}
618620
});
619621

620-
if( !(fileId || flashId) ){
622+
if( !fileId ){
623+
flashId = _attr;
624+
}
625+
626+
if( !flashId ){
627+
api.log('[err] Flash._send: flashId -- undefined');
621628
return this.parent.apply(this, arguments);
622-
} else {
623-
api.log('flash.XHR._send:', flashId, fileId, files);
629+
}
630+
else {
631+
api.log('Flash.XHR._send: '+ flashId +' -> '+ fileId, files);
624632
}
625633

626634
_this.xhr = {
@@ -634,8 +642,8 @@
634642
flash.cmd(flashId, 'upload', {
635643
url: _getUrl(options.url)
636644
, data: data
637-
, files: files
638-
, headers: options.headers
645+
, files: fileId ? files : null
646+
, headers: options.headers || {}
639647
, callback: _wrap(function upload(evt){
640648
var type = evt.type, result = evt.result;
641649

lib/FileAPI.core.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,9 @@
193193
flashImageUrl: 0, // @default: './FileAPI.flash.image.swf'
194194

195195
ext2mime: {
196-
jpg: 'image/jpeg'
197-
, tif: 'image/tiff'
196+
jpg: 'image/jpeg'
197+
, tif: 'image/tiff'
198+
, txt: 'text/plain'
198199
},
199200

200201
// Fallback for flash
@@ -657,8 +658,8 @@
657658

658659
_each(accept, function (ext, type){
659660
ext = new RegExp(ext.replace(/\s/g, '|'), 'i');
660-
if( ext.test(file.type) ){
661-
file.type = api.ext2mime[file.type] || type.split('/')[0] +'/'+ file.type;
661+
if( ext.test(file.type) || api.ext2mime[file.type] ){
662+
file.type = api.ext2mime[file.type] || (type.split('/')[0] +'/'+ file.type);
662663
}
663664
});
664665

0 commit comments

Comments
 (0)