cropzoom.js 2.43 KB
/**
 * 处理头像
 */


var sourceImage = '';
var cropzoomSend = 'http://sso.upload.yohobuy.com/crop';
function init()
{
	 $("#crop").click(function(){
		 	if($('#image_source').val() == '')
		 	{
		 		alert('请上传头像图片');
		 		return false;
		 	}
		 	var parameters = cropzoom.getSendData(cropzoomSend, {} ,'userIframe' );
			$('#cropForm').submit();
			$(".loading").attr('style', 'display:block');
		  	return false;
	 });
	 $("#restore").click(function(){
		  cropzoom.restore();
	 });
	 $("#cropUpdate").click(function(){
		 if($("#headico").val() == '')
		{
			 return false;
		}
		 return true;
	 });
	 $('#choosepic').qupload({
		  upload_url: 'http://sso.upload.yohobuy.com',
		  uploadKey: 'f21ebQj7oPAzeleYfLjI5Zf87pXxl1V2-R6wkaICPbRgiMtd4AqnRtKWnXYUPQ20rb697a2gEV7IzOfc08rNasn8H-RRcGBhVeSgkLpSEgJ57yjgM8iJactjicvSGeXhKvY3XFgQsimA1wWwoWcycmk-43HEWnTJw2aY4F8-E-PIdAD6dIDCZSRFcq6xY1W19vKGKTmr1NfZu4UK6q1B4458ZkUJapslzmBK2-6n4RifhXsIke_GF1TDNFpgIKdESweCsXML_nbwKWFWiDDo07QUs9l9F0d90cqkWRV7iqGnm08-zOzC4RzPvRYUqJROEoNiFjBrZdI',
		  button_image_url:	'http://static.yohobuy.com/images/btn_upload_xzzp.png',
		  file_types: "*.jpg;*.gif;*.jpeg;*.png",
		  uploadSuccessed:function(serverData){
			var data = eval('(' + serverData + ')');
			if(data.code != 12)
			{
				alert(data.message);
				return false;
			}
			
			$('#image_source').val(data.data.hit.Filedata.return_file_path);
			$('#headico').val(data.data.hit.Filedata.return_file_path);
			var imgPath = QGlobal.Common.QGetImagesMongo(data.data.hit.Filedata.return_file_path, 'source', myProject);
			crop(imgPath);
		  }
	 });
}
function crop(imgPath)
{
	if(typeof imgPath == 'undfined' || imgPath == '')
	{
		return false;
	}
	$("#" + previewImgId).attr("src", imgPath);
	var img = new Image();
	img.src = imgPath;
	img.onload = function(){
		var iWidth = img.width;
		var iHeight = img.height;
		cropzoom =  $('#' + cropzoomId).cropzoom({
	        width: 300,
	        height: 300,
	        bgColor: '#ccc',
	        enableRotation: true,
	        enableZoom: true,
	        selector: {
				 w:100,
				 h:100,
				 showPositionsOnDrag:true,
				 showDimetionsOnDrag:false,
	             centered: true,
				 bgInfoLayer:'#fff',
	             borderColor: 'blue',
	             borderColorHover: 'yellow'
	         },
	         image: {
	             source: img.src,
	             width: iWidth,
	             height: iHeight,
	             minZoom: 30,
	             maxZoom: 150
	          }
	    });
	};
}