fine('app/v8/controls/photo_reader/1.0',null,function(require,exports,module){var Base=require('app/v8/lang/1.0').Base;var misc=require('app/v8/controls/mood_poster/utils/misc/1.0');var $=require('jquery');var QZFL=window.QZFL;var env=require('app/v8/env/1.0');var logger=require('app/v8/utils/logger/1.0');var chunk=require('app/v8/utils/chunk/1.0');var count=0;var MAX_IMAGE_SELECT_COUNT=1;var FLASH_ID_PREIFX='qz_app_imageReader_';var PhotoReader=Base.derive({constructor:function(properties){if(!arguments.callee.Base.apply(this,arguments)){return false;}count++;this.setId(count);if(properties.maxImageCount){this.setMaxImageCount(properties.maxImageCount);}if(properties.onPhotoSelected&&typeof properties.onPhotoSelected=='function'){this.onPhotoSelected=properties.onPhotoSelected;}if(properties.onPhotoLoaded&&typeof properties.onPhotoLoaded=='function'){this.onPhotoLoaded=properties.onPhotoLoaded;}if(properties.onAllPhotoLoaded&&typeof properties.onAllPhotoLoaded=='function'){this.onAllPhotoLoaded=properties.onAllPhotoLoaded;}this.setTargetWidth(properties.width||$(properties.target).innerWidth()||100);this.setTargetHeight(properties.height||$(properties.target).innerHeight()||100);var flashHtml=this.getFlashHtml({id:this.getId(),width:this.getTargetWidth(),height:this.getTargetHeight()});if(properties.target&&typeof properties.target=='object'&&properties.target.nodeType==1){this.addFlashCallbacks();$(flashHtml).appendTo(properties.target.parentNode);}return true;},properties:{id:{},maxImageCount:{initialValue:1,getter:function(){logger.info('photoReader_'+this.getId()+'还可以插入'+this['@maxImageCount']+'张图片');return this['@maxImageCount'];}},selectedPhotoIds:{initialValue:[]},loadedPhotoIds:{initialValue:[]},outputSize:{initialValue:4000},clearDataAfterLoaded:{getterPrefix:'need',initialValue:true},flashFacadeId:{initialValue:'photoReader'},targetWidth:{},targetHeight:{},visible:{initialValue:true,getterPrefix:'is'},compressing:{initialValue:false,getterPrefix:'is'},compressQueue:{initialValue:[]}},methods:{getFlashHtml:function(options){if(QZFL.media.getFlashVersion().major<9){return'';}var flashHtml=QZFL.media.getFlashHtml({id:FLASH_ID_PREIFX+options.id,style:'position:absolute;z-index:1;left:1px;top:1px;',width:(options.width>2?options.width-2:options.width)+"px",height:(options.height>2?options.height-2:options.height)+"px",allowScriptAccess:"always",wmode:"transparent",src:'http://'+env.imgcacheDomain+'/qzone/client/photo/swf/SimpleLocalFileUploader/Main.swf?max_age=20140605',flashvars:'facadeId=QZAPPCTRL.'+this.getFlashFacadeId()+'.instance'+options.id+'.&max='+this.getMaxImageCount()});return flashHtml;},hide:function(){if(!this.isVisible()){return;}var flashObj=document.getElementById(FLASH_ID_PREIFX+this.getId());flashObj.height='1px';flashObj.width='1px';this.setVisible(false);},show:function(){if(this.isVisible()){return;}var flashObj=document.getElementById(FLASH_ID_PREIFX+this.getId());flashObj.height=this.getTargetHeight()+'px';flashObj.width=this.getTargetWidth()+'px';this.setVisible(true);},isExistInFlash:function(photoId){var photoList=this.getPhotoList();for(var i=0;ireturn false;},addFlashCallbacks:function(){var self=this;window.QZAPPCTRL=window.QZAPPCTRL||{};window.QZAPPCTRL[self.getFlashFacadeId()]||(window.QZAPPCTRL[self.getFlashFacadeId()]={});QZAPPCTRL[self.getFlashFacadeId()]['instance'+self.getId()]=self.getFlashCallbacks();logger.info('图片读取flash的接口绑定成功');},getFlashCallbacks:function(){var self=this;return{photoSelected:function(photoIds){logger.info('选图完成:',photoIds);self._onPhotoSelected(photoIds);},getPhotoId:misc.getUuid,getMaxNumFromJS:function(){return self.getMaxImageCount();},allLoadComplete:function(){setTimeout(function(){self._onAllPhotoLoaded();},0);},flashInit:function(){setTimeout(function(){self.onReady();logger.info('图片读取flash初始化成功 id:',self.getId());},0);},loadBmdSuccess:function(photoId){logger.info('图片bmd加载完成:',photoId);},compressPhotoCallback:function(photoData){setTimeout(function(){self.onPhotoCompressFinished(photoData);},0);}};},isLongPhoto:function(width,height){return(height/width)>=2;},remove:function(){var flashObj=document.getElementById(FLASH_ID_PREIFX+this.getId());flashObj.parentNode.removeChild(flashObj);if(QZAPPCTRL.imageReader){delete QZAPPCTRL.imageReader['instance'+this.getId()];}},onReady:function(){},onPhotoSelected:function(photoIds){},_onPhotoSelected:function(photoIds){var selectedPhotoIds=photoIds.concat();var loadedIds=this.getLoadedPhotoIds();for(var i=0;i-1){selectedPhotoIds.splice(i,1);i--;}}this.setSelectedPhotoIds(selectedPhotoIds);this.setLoadedPhotoIds(this.getLoadedPhotoIds().concat(selectedPhotoIds));this.onPhotoSelected(selectedPhotoIds);},_onAllPhotoLoaded:function(){var self=this;self.onAllPhotoLoaded();},onAllPhotoLoaded:function(){},compressAllPhoto:function(params){var params=$.extend(params,{photoIds:[].concat(this.getLoadedPhotoIds())});this.compressPhoto(params);},onPhotoCompressFinished:$.noop,calculateFingerPrint:function(base64){if(!base64){return'';}var contentLength=base64.length;if(base64.length<128){return base64+''+contentLength;}var frag1=base64.slice(0,32);var frag2=base64.slice(-32);var frag3=base64.slice(Math.floor(contentLength/2),32);return frag1+frag2+frag3+contentLength;},compressAsync:function(photoId,params,onCompressed){logger.info('photo_reader compressAsync:',photoId,params);var self=this;self.onPhotoCompressFinished=function(photoData){if(photoId!=photoData.id){return;}if(onCompressed&&typeof onCompressed=='function'){if(params.needFingerPrint){photoData.fingerPrint=self.calculateFingerPrint(photoData.base64);logger.info('photo fingerprint:'+photoData.fingerPrint);}onCompressed(photoData);}}self.call('compressPhotoAsync',photoId,params);},compressPhoto:function(params){var self=this;if(self.isCompressing()){logger.info('已经在压缩中了,加入等待队列',params);self.getCompressQueue().push(params);return;}self.setCompressing(true);params=$.extend({photoIds:[],width:800,height:800,interval:500,onPhotoCompressed:$.noop,onAllPhotoCompressed:$.noop,forceCompress:false},params);logger.info('开始压缩图片:',params);var index=0;var length=params.photoIds.length;var allPhotoData=[];chunk.async(params.photoIds,function(photoId,callback){if(!self.isExistInFlash(photoId)){callback();return;}
self.compressAsync(photoId,{width:params.width,height:params.height,needFingerPrint:params.needFingerPrint},function(result){if(result.type=='.png'){logger.info('photo_reader.compressPhoto 图片是png,要重新压缩');self.compressAsync(photoId,{width:params.width,height:params.height,type:'png',needFingerPrint:params.needFingerPrint},function(result){params.onPhotoCompressed(result);allPhotoData.push(result);callback();});}else if(params.forceCompress||(!self.isLongPhoto(result.width,result.height))){params.onPhotoCompressed(result);allPhotoData.push(result);callback();}else{logger.info('photo_reader.compressPhoto 图片需要2次处理:',result);self.compressAsync(photoId,{width:10000,height:10000,needFingerPrint:params.needFingerPrint},function(result){params.onPhotoCompressed(result);allPhotoData.push(result);callback();});}});},{interval:params.interval||500,context:self,onComplete:function(){self.setCompressing(false);logger.info('所有图片压缩完成:',allPhotoData);params.onAllPhotoCompressed(allPhotoData);if(self.getCompressQueue().length){var compressArgs=self.getCompressQueue().shift();logger.info('任务队列中还有未执行的压缩任务,开始执行',compressArgs);self.compressPhoto.call(self,compressArgs);}}});},deletePhoto:function(photoId){this.call('deletePhoto',photoId);for(var i=0;ivar returnString=_flash.CallFunction(['',__flash__argumentsToXML(arguments,0),''].join(''));var returnValue=eval(returnString);if(returnValue!==undefined&&typeof returnValue.post==="object"){returnValue=unescapeFilePostParams(returnValue);}
return returnValue;}}});return PhotoReader;});/* |xGv00|d92b66674779cf133fad9b8ed00e2
正在翻譯中..
