Skip to content

Commit c948815

Browse files
author
Ilya Lebedev
committed
master merged
2 parents a2fb04b + 46822e8 commit c948815

File tree

6 files changed

+108
-85
lines changed

6 files changed

+108
-85
lines changed

FileAPI.min.js

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

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ All the other codes - fatal error, user's involvement is recommend.
529529
header('Access-Control-Allow-Methods: POST, OPTIONS');
530530
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Range, Content-Disposition, Content-Type'); // and other custom headers
531531
header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']); // a comma-separated list of domains
532+
header('Access-Control-Allow-Credentials: true');
532533

533534
if( $_SERVER['REQUEST_METHOD'] == 'OPTIONS' ){
534535
exit;
@@ -670,6 +671,8 @@ All the other codes - fatal error, user's involvement is recommend.
670671
671672
672673
## Changelog
674+
* [#91](https://github.com/mailru/FileAPI/issues/91): replace `new Image` to `FileAPI.newImage`
675+
* + FileAPI.withCredentials: true
673676
* [#90](https://github.com/mailru/FileAPI/issues/90): Fixed `progress` event
674677
675678

index.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,14 @@ function onFiles(files){
335335
}
336336

337337
FileAPI.each(result.images, function (dataURL, name){
338-
$('<div/>')
339-
.append('<div><b>'+name+'</b></div>')
340-
.append($(new Image).attr('src', dataURL))
341-
.css({ margin: 5, border: '1px dotted #666', padding: 5 })
342-
.appendTo('body')
343-
;
338+
FileAPI.newImage(dataURL, function (err, img){
339+
$('<div/>')
340+
.append('<div><b>'+name+'</b></div>')
341+
.append(img)
342+
.css({ margin: 5, border: '1px dotted #666', padding: 5 })
343+
.appendTo('body')
344+
;
345+
});
344346
});
345347

346348
document.getElementById('Log').innerHTML += '<pre style="font-size: 11px;">'+xhr.responseText.substr(0, 200)+'</pre>';

lib/FileAPI.Flash.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,7 @@
366366
}, base64, fn);
367367
}
368368
else {
369-
var img = new Image;
370-
api.event.one(img, 'error abort load', function (evt){
371-
fn(evt.type != 'load' && evt.type, img);
372-
img = null;
373-
});
374-
img.src = 'data:'+ file.type +';base64,'+ base64;
369+
api.newImage('data:'+ file.type +';base64,'+ base64, fn);
375370
}
376371
})
377372
});
@@ -644,12 +639,9 @@
644639

645640

646641
// Check dataURI support
647-
var dataURICheck = new Image;
648-
api.event.one(dataURICheck, 'error load', function (){
649-
api.support.dataURI = !(dataURICheck.width != 1 || dataURICheck.height != 1);
650-
dataURICheck = null;
642+
api.newImage('data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==', function (err, img){
643+
api.support.dataURI = !(img.width != 1 || img.height != 1);
651644
flash.init();
652645
});
653-
dataURICheck.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==';
654646
})();
655647
})(FileAPI, window, document);

lib/FileAPI.XHR.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@
140140
}
141141

142142
xhr.open('POST', url, true);
143-
xhr.withCredentials = "true";
143+
144+
if( api.withCredentials ){
145+
xhr.withCredentials = "true";
146+
}
144147

145148
if( !options.headers || !options.headers['X-Requested-With'] ){
146149
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');

lib/FileAPI.core.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
debug: false,
6464
pingUrl: false,
6565
flashAbortTimeout: 0,
66+
withCredentials: true,
6667

6768
staticPath: './',
6869

@@ -105,6 +106,29 @@
105106
}
106107
},
107108

109+
/**
110+
* Create new image
111+
*
112+
* @param {String} [src]
113+
* @param {Function} [fn] 1. error -- boolean, 2. img -- Image element
114+
* @returns {HTMLElement}
115+
*/
116+
newImage: function (src, fn){
117+
var img = document.createElement('img');
118+
if( fn ){
119+
api.event.one(img, 'error load', function (evt){
120+
fn(evt.type == 'error', img);
121+
img = null;
122+
});
123+
}
124+
img.src = src;
125+
returnimg;
126+
},
127+
128+
/**
129+
* Get XHR
130+
* @returns {XMLHttpRequest}
131+
*/
108132
getXHR: function (){
109133
var xhr;
110134

@@ -478,8 +502,7 @@
478502
}
479503
else {
480504
// Created image
481-
var img = new Image;
482-
img.src = file.dataURL || file;
505+
var img = api.newImage(file.dataURL || file);
483506
api.readAsImage(img, fn, progress);
484507
}
485508
},

0 commit comments

Comments
 (0)