fine('app/v8/controls/photo_reader/1.0',null,function(require,exports,module) {var Base=require('app/v8/lang/1.0')。基地; var misc = 要求 (应用程序/v8/控制/mood_poster/utils/misc/1.0 '); var $= 需要 ('jquery'); var QZFL = 窗口。QZFL; var env = 需要 (应用程序/v8/env/1.0 '); var 记录器 = 需要 (' app/v8/utils/记录器/1.0 '); var 块 = 需要 (' app/v8/utils/块/1.0 '); var 计数 = 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)) {返回 false;}} count++;this.setId(count);if(properties.maxImageCount){this.setMaxImageCount(properties.maxImageCount)如果 (properties.onPhotoSelected & & typeof properties.onPhotoSelected=='function'){this.onPhotoSelected=properties.onPhotoSelected;}如果 (properties.onPhotoLoaded & & typeof properties.onPhotoLoaded=='function'){this.onPhotoLoaded=properties.onPhotoLoaded;}如果 (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()}); 如果 (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()}); 返回 flashHtml;},hide:function(){if(!this.isVisible()) {回报;}var flashObj=document.getElementById(FLASH_ID_PREIFX+this.getId());flashObj.height='1px';flashObj.width='1px';this.setVisible(false);},show:function(){if(this.isVisible()) {回报;}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;i返回 false;},addFlashCallbacks:function() {var 自我 = 这; 窗口。QZAPPCTRL = 窗口。QZAPPCTRL||{}; 窗口。QZAPPCTRL[self.getFlashFacadeId()] | |(窗口。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() {返回 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 (宽度height){return(height/width) > =2;},remove:function() {var flashObj=document.getElementById(FLASH_ID_PREIFX+this.getId());flashObj.parentNode.removeChild(flashObj);if(QZAPPCTRL.imageReader) {删除 QZAPPCTRL.imageReader['instance'+this.getId()];}},onReady:function(){},onPhotoSelected:function(photoIds){},_onPhotoSelected:function(photoIds) {var selectedPhotoIds=photoIds.concat (); var loadedIds=this.getLoadedPhotoIds (); 为 (var 我 = 0; 我-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)。 {返回 ';}var contentLength = base64.length; if(base64.length<128) {返回 base64 + ' + contentLength;}var frag1 = base64.slice (0,32); var frag2=base64.slice(-32); var frag3=base64.slice (实际上 (contentLength/2),32); 返回 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) {回报;}如果 (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); 回报;}self.setCompressing (true); params = $.extend({photoIds:[],width:800,height:800,interval:500,onPhotoCompressed:$.noop,onAllPhotoCompressed:$.noop,forceCompress:false},params); 仅限于 logger.info ('开始压缩图片:',params); var 指数 = 0; var length=params.photoIds.length;var allPhotoData=[];chunk.async(params.photoIds,function(photoId,callback){if(!self.isExistInFlash(photoId)) {回调 (); 回报;}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;iif(!this.getPhotoList().length){this.setCompressing(false);}},getPhotoList:function(callback) {var photoList=this.call ('getPhotoList') | |[]; 返回 photoList;},_clearAllPhotoData:function(photoIds){if(!photoIds) {logger.warn ('photoReader.clearAllPhotoData photoIds 是空'); 返回;}试着 {为 (var 我 = 0; 我var returnString = _flash。CallFunction (['',__flash__argumentsToXML(arguments,0),''] 闭 (')); var returnValue = eval (returnString); 如果 (returnValue! = = 未定义 & & typeof returnValue.post==="object"){returnValue=unescapeFilePostParams(returnValue);}返回 returnValue;}}});返回 PhotoReader;});/* |xGv00|d92b66674779cf133fad9b8ed00e2
正在翻譯中..
![](//zhcntimg.ilovetranslation.com/pic/loading_3.gif?v=b9814dd30c1d7c59_8619)