Skip to content

Commit

Permalink
+ FileAPI.Image.fromDataURL
Browse files Browse the repository at this point in the history
  • Loading branch information
RubaXa committed Aug 9, 2013
1 parent 1a4da9f commit e696d4f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
36 changes: 29 additions & 7 deletions lib/FileAPI.Flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,23 @@
});


api.Image && _inherit(api.Image, {
fromDataURL: function (dataURL, size, callback){
if( !api.support.dataURI || dataURL.length > 3e4 ){
_makeFlashImage(
api.extend({ scale: 'exactFit' }, size)
, dataURL.replace(/^data:[^,]+,/, '')
, function (err, el){ callback(el); }
);
}
else {
this.parent(dataURL, size, callback);
}
}
});



// FileAPI.Camera:statics
api.Camera.fallback = function (el, options, callback){
var camId = api.uid();
Expand Down Expand Up @@ -720,11 +737,16 @@


function _makeFlashImage(opts, base64, fn){
var _id, flashId = api.uid(), el = document.createElement('div');
var
key
, flashId = api.uid()
, el = document.createElement('div')
// , attempts = 10
;

for( _id in opts ){
el.setAttribute(_id, opts[_id]);
el[_id] = opts[_id];
for( key in opts ){
el.setAttribute(key, opts[key]);
el[key] = opts[key];
}

_css(el, opts);
Expand All @@ -736,9 +758,9 @@
id: flashId
, src: _getUrl(api.flashImageUrl, 'r='+ api.uid())
, wmode: 'opaque'
, flashvars: 'scale='+ opts.scale +'&callback='+_wrap(function _setData(){
_unwrap(_setData);
setTimeout(_setImage, 99);
, flashvars: 'scale='+ opts.scale +'&callback='+_wrap(function _(){
_unwrap(_);
_setImage();
return true;
})
}, opts));
Expand Down
12 changes: 12 additions & 0 deletions lib/FileAPI.Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,18 @@
});


/**
* Create image from DataURL
* @param {String} dataURL
* @param {Object} size
* @param {Function} callback
*/
Image.fromDataURL = function (dataURL, size, callback){
var img = api.newImage(dataURL);
api.extend(img, size);
callback(img);
};


// @export
api.support.canvas = api.support.transform = support;
Expand Down
4 changes: 2 additions & 2 deletions lib/FileAPI.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1272,10 +1272,10 @@
, type: xhr.getResponseHeader('Content-Type')
};
file.dataURL = 'data:'+file.type+';base64,' + api.encode64(xhr.responseBody || xhr.responseText);
fn({ type: 'load', result: file });
fn({ type: 'load', result: file }, xhr);
}
else {
fn({ type: 'error' });
fn({ type: 'error' }, xhr);
}
}
};
Expand Down

0 comments on commit e696d4f

Please sign in to comment.