diff --git a/lib/FileAPI.Flash.js b/lib/FileAPI.Flash.js index 904c407b..941da85d 100644 --- a/lib/FileAPI.Flash.js +++ b/lib/FileAPI.Flash.js @@ -337,7 +337,7 @@ patch: function (){ - api.flashEngine = + api.flashEngine = true; api.support.transform = true; // FileAPI @@ -509,31 +509,33 @@ // FileAPI.Camera:statics - api.Camera.fallback = function (el, options, callback){ - var camId = api.uid(); - api.log('FlashAPI.Camera.publish: ' + camId); - flash.publish(el, camId, api.extend(options, { - camera: true, - onEvent: _wrap(function _(evt){ - if( evt.type == 'camera' ){ - _unwrap(_); - - if( evt.error ){ - api.log('FlashAPI.Camera.publish.error: ' + evt.error); - callback(evt.error); - } - else { - api.log('FlashAPI.Camera.publish.success: ' + camId); - callback(null); - } - } - }) - })); - }; + if (api.Camera != null) { + api.Camera.fallback = function (el, options, callback){ + var camId = api.uid(); + api.log('FlashAPI.Camera.publish: ' + camId); + flash.publish(el, camId, api.extend(options, { + camera: true, + onEvent: _wrap(function _(evt){ + if( evt.type == 'camera' ){ + _unwrap(_); + + if( evt.error ){ + api.log('FlashAPI.Camera.publish.error: ' + evt.error); + callback(evt.error); + } + else { + api.log('FlashAPI.Camera.publish.success: ' + camId); + callback(null); + } + } + }) + })); + }; + } // FileAPI.Camera:proto - _inherit(api.Camera.prototype, { + api.Camera && _inherit(api.Camera.prototype, { _id: function (){ return this.video.id; }, diff --git a/lib/FileAPI.Image.js b/lib/FileAPI.Image.js index ab4f5f12..1dc5bfe5 100644 --- a/lib/FileAPI.Image.js +++ b/lib/FileAPI.Image.js @@ -132,41 +132,46 @@ // For `renderImageToCanvas` image._type = this.file.type; - while( min(w/dw, h/dh) > 2 ){ - w = (w/2 + 0.5)|0; - h = (h/2 + 0.5)|0; - - copy = getCanvas(); - copy.width = w; - copy.height = h; - - if( buffer !== image ){ - renderImageToCanvas(copy, buffer, 0, 0, buffer.width, buffer.height, 0, 0, w, h); - buffer = copy; - } - else { - buffer = copy; - renderImageToCanvas(buffer, image, m.sx, m.sy, m.sw, m.sh, 0, 0, w, h); - m.sx = m.sy = m.sw = m.sh = 0; - } - } - - - canvas.width = (deg % 180) ? dh : dw; - canvas.height = (deg % 180) ? dw : dh; - - canvas.type = m.type; - canvas.quality = m.quality; - - ctx.rotate(deg * Math.PI / 180); - renderImageToCanvas(canvas, buffer - , m.sx, m.sy - , m.sw || buffer.width - , m.sh || buffer.height - , (deg == 180 || deg == 270 ? -dw : 0) - , (deg == 90 || deg == 180 ? -dh : 0) - , dw, dh - ); + try{ + while(api.multiPassResize && min(w/dw, h/dh) > 2 ){ + w = (w/2 + 0.5)|0; + h = (h/2 + 0.5)|0; + + copy = getCanvas(); + copy.width = w; + copy.height = h; + + if( buffer !== image ){ + renderImageToCanvas(copy, buffer, 0, 0, buffer.width, buffer.height, 0, 0, w, h); + buffer = copy; + } + else { + buffer = copy; + renderImageToCanvas(buffer, image, m.sx, m.sy, m.sw, m.sh, 0, 0, w, h); + m.sx = m.sy = m.sw = m.sh = 0; + } + } + + + canvas.width = (deg % 180) ? dh : dw; + canvas.height = (deg % 180) ? dw : dh; + + canvas.type = m.type; + canvas.quality = m.quality; + + ctx.rotate(deg * Math.PI / 180); + renderImageToCanvas(canvas, buffer + , m.sx, m.sy + , m.sw || buffer.width + , m.sh || buffer.height + , (deg == 180 || deg == 270 ? -dw : 0) + , (deg == 90 || deg == 180 ? -dh : 0) + , dw, dh + ); + } catch (ex) { + fn(true); + return; + } dw = canvas.width; dh = canvas.height; @@ -278,7 +283,11 @@ fn(err); } else { - this._apply(image, fn); + try { + this._apply(image, fn); + } catch (ex) { + fn(ex); + } } }); }, diff --git a/lib/FileAPI.XHR.js b/lib/FileAPI.XHR.js index 24eaba61..e368a4a4 100644 --- a/lib/FileAPI.XHR.js +++ b/lib/FileAPI.XHR.js @@ -88,13 +88,21 @@ } if( data.nodeName ){ - // legacy + if (options.addCallbackNameToUrl) { + if (url.indexOf('?') >= 0) { + url += "&callback="+encodeURIComponent(uid); + } else { + url += "?callback="+encodeURIComponent(uid); + } + } + + // legacy options.upload(options, _this); xhr = document.createElement('div'); xhr.innerHTML = '
' ; @@ -124,17 +132,35 @@ _this.xhr.node = xhr; // jsonp-callack - window[uid] = function (status, statusText, response){ + var func = function (status, statusText, response){ _this.readyState = 4; _this.responseText = response; _this.end(status, statusText); xhr = null; }; + window[uid] = func; - // send + // send _this.readyState = 2; // loaded form.submit(); form = null; + + var repeats = 0; + var timer = function () { + try { + var transport = xhr.getElementsByTagName('iframe')[0]; + var result = transport.contentWindow.result; + if (result != null) { + func(result.status, result.statusText, result.response); + return; + } + } catch (e) { + } + if (repeats++ < 50) { + window.setTimeout(timer, 500+repeats*100); + } + }; + window.setTimeout(timer, 500); } else { // html5 diff --git a/lib/FileAPI.core.js b/lib/FileAPI.core.js index 7ac0b0a1..9d829fe6 100644 --- a/lib/FileAPI.core.js +++ b/lib/FileAPI.core.js @@ -24,7 +24,7 @@ XMLHttpRequest = window.XMLHttpRequest, jQuery = window.jQuery, - html5 = !!(File && (FileReader && (window.Uint8Array || FormData || XMLHttpRequest.prototype.sendAsBinary))) + html5 = window.FileAPI.html5 && !!(File && (FileReader && (window.Uint8Array || FormData || XMLHttpRequest.prototype.sendAsBinary))) && !(/safari\//i.test(userAgent) && !/chrome\//i.test(userAgent) && /windows/i.test(userAgent)), // BugFix: https://github.com/mailru/FileAPI/issues/25 cors = html5 && ('withCredentials' in (new XMLHttpRequest)), @@ -189,6 +189,7 @@ html5: true, media: false, formData: true, + multiPassResize: true, debug: false, pingUrl: false,