From 3617dc0d4260f194450e3c3cb640bbb7cd743f76 Mon Sep 17 00:00:00 2001 From: Coxxs Date: Sat, 13 Jan 2018 12:05:56 +0800 Subject: [PATCH] =?UTF-8?q?!140=20=E4=BF=AE=E5=A4=8D=20=E5=A4=B4=E5=83=8F?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E8=B7=A8=E5=9F=9F=E9=97=AE=E9=A2=98=20Merge?= =?UTF-8?q?=20pull=20request=20!140=20from=20Coxxs/fix/avatar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- upload/static/avatar/avatar.js | 72 +++++++++---------- .../default/home/spacecp_avatar_body.htm | 14 ++-- upload/uc_server/control/user.php | 4 +- 3 files changed, 43 insertions(+), 47 deletions(-) diff --git a/upload/static/avatar/avatar.js b/upload/static/avatar/avatar.js index 04958e3..949a68e 100644 --- a/upload/static/avatar/avatar.js +++ b/upload/static/avatar/avatar.js @@ -16,9 +16,8 @@ jQuery('#avatarcanvas').attr('width', (dwidth-150)); jQuery('#avatarcanvas').attr('height', dheight-25); jQuery('#avatardisplaycanvas').attr('width', dwidth-20); jQuery('#avatardisplaycanvas').attr('height', dheight-25); -var src = data[data.indexOf('src')+1].replace('images/camera.swf?inajax=1','index.php?m=user&a=uploadavatar'); -$('avatarform').action = src; -$('avatarform').target ='uploadframe'; +$('avatarform').target ='uploadframe'; +$('avatarfile').onchange = uploadAvatarDone; jQuery(document).ready(function () { jQuery("#selector") @@ -41,37 +40,32 @@ jQuery(document).ready(function () { jQuery("#slider").append("
 
" ); }); -function uploadAvatarDone() { - var iframe = $('uploadframe'); - var iframeDocument = iframe.contentDocument || iframe.contentWindow.document; - if (!iframeDocument.body) return; - var imageSrc = iframeDocument.body.innerHTML; - if (!imageSrc) return; +window.addEventListener('message', receiveMessage, false); - if (imageSrc.indexOf('/')===-1) { // server returns error message - if (imageSrc!=-4) { // ie11 bug?: called twice, the value in the second time is -4 - alert(imageSrc); - } +function receiveMessage(event) { + var msgdata = event.data; + if (typeof(msgdata) !== 'string') { return; - } - try { - var av = $('avatarfile'); - av.value = ''; - if(av.value){ - av.type = "text"; - av.type = "file"; - } - } catch(e){} - jQuery('#avatarfileselector').hide(); - jQuery('#avatardisplayer').hide(); - jQuery('#avataradjuster').show(); - jQuery('#selector').css('left', Math.floor((dwidth-300)/2)); - jQuery('#selector').css('top', Math.floor((dheight-150)/2)); - jQuery('#selector').width(150); - jQuery('#selector').height(150); - imageSrc += "?" + (new Date()); - $('avatarimage').src = imageSrc; - jQuery("#slider").slider('value', 50); + } + rectAvatarDone(msgdata); +} + +function uploadAvatarDone() { + if (this.files && this.files[0]) { + var fr = new FileReader(); + fr.onload = function(e) { + jQuery('#avatarfileselector').hide(); + jQuery('#avatardisplayer').hide(); + jQuery('#avataradjuster').show(); + jQuery('#selector').css('left', Math.floor((dwidth-300)/2)); + jQuery('#selector').css('top', Math.floor((dheight-150)/2)); + jQuery('#selector').width(150); + jQuery('#selector').height(150); + $('avatarimage').src = e.target.result; + jQuery("#slider").slider('value', 50); + }; + fr.readAsDataURL(this.files[0]); + } } function showAvatarFileSelector() { @@ -189,6 +183,8 @@ function saveAvatar() { canvas.width = tw; canvas.height = th; var ctx = canvas.getContext("2d"); + ctx.fillStyle = 'white'; + ctx.fillRect(0, 0, tw, th); ctx.drawImage(img, sl, st, sw, sh, 0, 0, tw, th); var dataURL = canvas.toDataURL("image/jpeg"); jQuery('#avatar1').val(dataURL.substr(dataURL.indexOf(",") + 1)); @@ -204,6 +200,8 @@ function saveAvatar() { canvas.width = tw; canvas.height = th; var ctx = canvas.getContext("2d"); + ctx.fillStyle = 'white'; + ctx.fillRect(0, 0, tw, th); ctx.drawImage(img, sl, st, sw, sh, 0, 0, tw, th); var dataURL = canvas.toDataURL("image/jpeg"); jQuery('#avatar2').val(dataURL.substr(dataURL.indexOf(",") + 1)); @@ -223,12 +221,14 @@ function saveAvatar() { canvas.width = tw; canvas.height = th; var ctx = canvas.getContext("2d"); + ctx.fillStyle = 'white'; + ctx.fillRect(0, 0, tw, th); ctx.drawImage(img, sl, st, sw, sh, 0, 0, tw, th); var dataURL = canvas.toDataURL("image/jpeg"); jQuery('#avatar3').val(dataURL.substr(dataURL.indexOf(",") + 1)); var src = $('avatarform').action; - $('avatarform').action = src.replace('&a=uploadavatar', '&a=rectavatar&base64=yes'); + $('avatarform').action = data[data.indexOf('src')+1].replace('images/camera.swf?inajax=1', 'index.php?m=user&a=rectavatar&base64=yes'); $('avatarform').target='rectframe'; } @@ -291,11 +291,7 @@ function refreshAvatarCanvasForDisplay() { ctx.fillText('以上是您头像的三种尺寸', dwidth - 200, 180); } -function rectAvatarDone() { - var iframe = $('rectframe'); - var iframeDocument = iframe.contentDocument || iframe.contentWindow.document; - if (!iframeDocument.body) return; - var res = iframeDocument.body.innerHTML; +function rectAvatarDone(res) { if (!res) return; if (res=='success') { jQuery('#avatardisplayer').show(); diff --git a/upload/template/default/home/spacecp_avatar_body.htm b/upload/template/default/home/spacecp_avatar_body.htm index a1c2162..07e1539 100644 --- a/upload/template/default/home/spacecp_avatar_body.htm +++ b/upload/template/default/home/spacecp_avatar_body.htm @@ -1,6 +1,6 @@
- +
@@ -33,15 +33,15 @@
- + - - - + + + - - \ No newline at end of file + + \ No newline at end of file diff --git a/upload/uc_server/control/user.php b/upload/uc_server/control/user.php index ce6d282..b16c214 100644 --- a/upload/uc_server/control/user.php +++ b/upload/uc_server/control/user.php @@ -398,9 +398,9 @@ class usercontrol extends base { if(getgpc('base64', 'G')){ if($success) { - return "success"; + return ""; } else { - return "failure"; + return ""; } }else{ if($success) {