From 9e3766632b99a9c38081b8c8cc630e179a3ff8fa Mon Sep 17 00:00:00 2001 From: Dmitry Korobkin Date: Wed, 18 Nov 2015 19:52:24 +0300 Subject: [PATCH 1/2] cloudweb-5925: abort FileReader only when readyState==LOADING --- dist/FileAPI.html5.js | 18 ++++++++++++++---- dist/FileAPI.js | 18 ++++++++++++++---- lib/FileAPI.core.js | 4 +++- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/dist/FileAPI.html5.js b/dist/FileAPI.html5.js index c2417010..2c179719 100644 --- a/dist/FileAPI.html5.js +++ b/dist/FileAPI.html5.js @@ -139,6 +139,8 @@ _rdata = /^data:[^,]+,/, _toString = {}.toString, + _supportConsoleLog, + _supportConsoleLogApply, Math = window.Math, @@ -343,8 +345,8 @@ }, log: function (){ - if( api.debug && window.console && console.log ){ - if( console.log.apply ){ + if( api.debug && _supportConsoleLog ){ + if( _supportConsoleLogApply ){ console.log.apply(console, arguments); } else { @@ -1610,7 +1612,9 @@ _one(reader, _readerEvents, function (evt){ var isFile = evt.type != 'error'; if( isFile ){ - reader.abort(); + if ( reader.readyState == void 0 || reader.readyState === 1 /*LOADING*/ ) { + reader.abort(); + } callback(isFile); } else { @@ -1887,7 +1891,13 @@ }); - // @configuration + // Configuration + try { + _supportConsoleLog = !!console.log; + _supportConsoleLogApply = !!console.log.apply; + } + catch (err) {} + if( !api.flashUrl ){ api.flashUrl = api.staticPath + 'FileAPI.flash.swf'; } if( !api.flashImageUrl ){ api.flashImageUrl = api.staticPath + 'FileAPI.flash.image.swf'; } if( !api.flashWebcamUrl ){ api.flashWebcamUrl = api.staticPath + 'FileAPI.flash.camera.swf'; } diff --git a/dist/FileAPI.js b/dist/FileAPI.js index bc043bca..9a5aeab2 100644 --- a/dist/FileAPI.js +++ b/dist/FileAPI.js @@ -139,6 +139,8 @@ _rdata = /^data:[^,]+,/, _toString = {}.toString, + _supportConsoleLog, + _supportConsoleLogApply, Math = window.Math, @@ -343,8 +345,8 @@ }, log: function (){ - if( api.debug && window.console && console.log ){ - if( console.log.apply ){ + if( api.debug && _supportConsoleLog ){ + if( _supportConsoleLogApply ){ console.log.apply(console, arguments); } else { @@ -1610,7 +1612,9 @@ _one(reader, _readerEvents, function (evt){ var isFile = evt.type != 'error'; if( isFile ){ - reader.abort(); + if ( reader.readyState == void 0 || reader.readyState === 1 /*LOADING*/ ) { + reader.abort(); + } callback(isFile); } else { @@ -1887,7 +1891,13 @@ }); - // @configuration + // Configuration + try { + _supportConsoleLog = !!console.log; + _supportConsoleLogApply = !!console.log.apply; + } + catch (err) {} + if( !api.flashUrl ){ api.flashUrl = api.staticPath + 'FileAPI.flash.swf'; } if( !api.flashImageUrl ){ api.flashImageUrl = api.staticPath + 'FileAPI.flash.image.swf'; } if( !api.flashWebcamUrl ){ api.flashWebcamUrl = api.staticPath + 'FileAPI.flash.camera.swf'; } diff --git a/lib/FileAPI.core.js b/lib/FileAPI.core.js index 4943b648..2e486b7b 100644 --- a/lib/FileAPI.core.js +++ b/lib/FileAPI.core.js @@ -1518,7 +1518,9 @@ _one(reader, _readerEvents, function (evt){ var isFile = evt.type != 'error'; if( isFile ){ - reader.abort(); + if ( reader.readyState == void 0 || reader.readyState === 1 /*LOADING*/ ) { + reader.abort(); + } callback(isFile); } else { From 009ca98d35dbcc3349f568a2aa05ca1ca7b8e525 Mon Sep 17 00:00:00 2001 From: Dmitry Korobkin Date: Thu, 19 Nov 2015 21:51:27 +0300 Subject: [PATCH 2/2] cloudweb-5925: beautify code --- lib/FileAPI.core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/FileAPI.core.js b/lib/FileAPI.core.js index 2e486b7b..a282cd33 100644 --- a/lib/FileAPI.core.js +++ b/lib/FileAPI.core.js @@ -1518,7 +1518,7 @@ _one(reader, _readerEvents, function (evt){ var isFile = evt.type != 'error'; if( isFile ){ - if ( reader.readyState == void 0 || reader.readyState === 1 /*LOADING*/ ) { + if ( reader.readyState == null || reader.readyState === reader.LOADING ) { reader.abort(); } callback(isFile);