diff --git a/ckeditor/core_five_filemanager/scripts/filemanager.js b/ckeditor/core_five_filemanager/scripts/filemanager.js index ddb06de9b763dcdf05ff81e0bd20b3e89a88ac78..e3025df0ec1f4c64317f4ebbc35f2e84ebfc2cbc 100755 --- a/ckeditor/core_five_filemanager/scripts/filemanager.js +++ b/ckeditor/core_five_filemanager/scripts/filemanager.js @@ -894,34 +894,36 @@ $(function(){ $('#uploader').attr('action', fileConnector); - var resizeImage = function(file, dataurl, max_width, max_height) { - var img = document.createElement("img"); - img.src = dataurl; - - var canvas = document.createElement("canvas"); + var uploadResizeImageAjax = function(file, dataurl, max_width, max_height) { + var img = new Image(); + img.onload = function() { + var canvas = document.createElement("canvas"); - var width = img.width; - var height = img.height; - - if (width > height) { - if (width > max_width) { - height *= max_width / width; - width = max_width; - } - } else { - if (height > max_height) { - width *= max_height / height; - height = max_height; + var width = img.width; + var height = img.height; + + if (width > height) { + if (width > max_width) { + height *= max_width / width; + width = max_width; + } + } else { + if (height > max_height) { + width *= max_height / height; + height = max_height; + } } + + canvas.width = width; + canvas.height = height; + var ctx = canvas.getContext("2d"); + ctx.drawImage(img, 0, 0, width, height); + + uploadFileAjax(file, canvas.toDataURL(file.type)); } - - canvas.width = width; - canvas.height = height; - var ctx = canvas.getContext("2d"); - ctx.drawImage(img, 0, 0, width, height); - return canvas.toDataURL(file.type); + img.src = dataurl; } @@ -947,7 +949,7 @@ $(function(){ } var reader = new FileReader(); - reader.onload = (function(e) { + reader.onloadend = (function(e) { var dataurl = e.target.result; if (is_image) { @@ -965,9 +967,10 @@ $(function(){ "1024":{"width":1024, "height": 768}, "1280":{"width":1280, "height": 1024}}; var geometry = geometries[formVals.geometry]; - dataurl = resizeImage(file, dataurl, geometry.width, geometry.height); + uploadResizeImageAjax(file, dataurl, geometry.width, geometry.height); + } else { + uploadFileAjax(file, dataurl); } - uploadFileAjax(file, dataurl); } }]); } else {