rhymix/modules/editor/tpl/js/uploader.min.js
2015-07-07 18:03:49 +09:00

1 line
No EOL
9.1 KiB
JavaScript

function previewFiles(a,b){var c,d,e,f,g,h,i=jQuery;if(!b){if(c=i(a.target).parent().addBack().filter("select").find(">option:selected"),!c.length)return;b=c.attr("value")}b&&is_def(e=uploadedFiles[b])&&(d=i("#"+e.previewAreaID).html("&nbsp;"),d.length&&(f=e.download_url||"",g=f.match(/\.(?:(flv)|(swf)|(wmv|avi|mpe?g|as[fx]|mp3)|(jpe?g|png|gif))$/i),"Y"==e.direct_download&&g?g[1]?h='<embed src="'+request_uri+"common/img/flvplayer.swf?autoStart=false&file="+uploaded_filename+'" width="100%" height="100%" type="application/x-shockwave-flash" />':g[2]?h='<embed src="'+request_uri+f+'" width="100%" height="100%" type="application/x-shockwave-flash" />':g[3]?h='<embed src="'+request_uri+f+'" width="100%" height="100%" autostart="true" showcontrols="0" />':g[4]&&(h='<img src="'+request_uri+f+'" border="0" width="100%" height="100%" />'):h='<img src="'+request_uri+'modules/editor/tpl/images/files.gif" border="0" width="100%" height="100%" />',h&&d.html(h)))}function removeUploadedFile(a){var b=uploaderSettings[a],c=b.fileListAreaID,d=get_by_id(c);if(d&&!(d.selectedIndex<0)){for(var e=[],f=0;f<d.options.length;f++)if(d.options[f].selected){var g=d.options[f].value;g&&(e[e.length]=g)}if(!(e.length<1)){var h={file_srls:e.join(","),editor_sequence:a};exec_xml("file","procFileDelete",h,function(){reloadFileList(b)})}}}function insertUploadedFile(a){var b=uploaderSettings[a],c=b.fileListAreaID,d=get_by_id(c);if(d){var e;if("preview"!=editorMode[a]){for(var f=[],g=0;g<d.options.length;g++)if(d.options[g].selected){var h=d.options[g].value;if(h){var i=uploadedFiles[h];editorFocus(a),"Y"==i.direct_download?/\.(jpg|jpeg|png|gif)$/i.test(i.download_url)?(loaded_images[h]?e=loaded_images[h]:(e=new Image,e.src=i.download_url),temp_code="",temp_code+='<img src="'+i.download_url+'" alt="'+i.source_filename+'"',e.complete===!0&&(temp_code+=' width="'+e.width+'" height="'+e.height+'"'),temp_code+=" />\r\n<p><br /></p>\r\n",f.push(temp_code)):f.push('<img src="common/img/blank.gif" editor_component="multimedia_link" multimedia_src="'+i.download_url+'" width="400" height="320" style="display:block;width:400px;height:320px;border:2px dotted #4371B9;background:url(./modules/editor/components/multimedia_link/tpl/multimedia_link_component.gif) no-repeat center;" auto_start="false" alt="" />'):f.push('<a href="'+i.download_url+'">'+i.source_filename+"</a>\n")}}if("html"==editorMode[a])f.length>0&&get_by_id("editor_textarea_"+a)&&(get_by_id("editor_textarea_"+a).value+=f.join(""));else{var j=editorGetIFrame(a);if(!j)return;f.length>0&&editorReplaceHTML(j,f.join(""))}}}}var uploadedFiles=[],uploaderSettings=[],loaded_images=[],swfUploadObjs=[],uploadSettingObj=[],uploadAutosaveChecker=!1;!function(a){function b(b,d){var e=b.editorSequence;is_def(e)&&(b=a.extend({sessionName:"PHPSESSID",allowedFileSize:2097152,allowedFileTypes:"*.*",allowedFileTypesDescription:"All Files",replaceButtonID:"swfUploadButton"+b.editorSequence,insertedFiles:0},b),uploadSettingObj[e]=b,a(function(){c(b)}))}function c(b){var c,d,g,h,i,j,k,l,m,n,o,p;i=b.editorSequence,j=b.replaceButtonID,c=a("#"+j).wrap('<span style="position:relative;display:inline-block" />'),d=c.width(),g=c.height(),h=a('<span id="dummy'+j+'" />').insertAfter(c),k={flash_url:request_uri+"modules/editor/tpl/images/SWFUpload.swf",upload_url:request_uri+"index.php",post_params:{mid:current_mid,act:"procFileUpload",editor_sequence:i,uploadTargetSrl:editorRelKeys[i].primary.value},http_success:[302],file_size_limit:Math.floor((parseInt(b.allowedFileSize,10)||1024)/1024),file_queue_limit:0,file_upload_limit:0,file_types:b.allowedFileTypes,file_types_description:b.allowedFileTypesDescription,custom_settings:{progressTarget:null,cancelButtonId:null},debug:!1,button_window_mode:"transparent",button_placeholder_id:h.attr("id"),button_text:null,button_image_url:request_uri+"common/img/blank.gif",button_width:d,button_height:g,button_text_style:null,button_text_left_padding:0,button_text_top_padding:0,button_cursor:-2,editorSequence:i,uploadTargetSrl:editorRelKeys[i].primary.value,fileListAreaID:b.fileListAreaID,previewAreaID:b.previewAreaID,uploaderStatusID:b.uploaderStatusID},"undefined"!=typeof enforce_ssl&&enforce_ssl&&(k.upload_url=request_uri+"index.php"),a("#"+b.fileListAreaID).click(previewFiles),l={file_queued:"FileQueued",file_queue_error:"FileQueueError",file_dialog_complete:"FileDialogComplete",upload_start:"UploadStart",upload_progress:"UploadProgress",upload_error:"UploadError",upload_success:"UploadSuccess",upload_complete:"UploadComplete",queue_complete:"QueueComplete"};for(m in l)l.hasOwnProperty(m)&&(n="on"+l[m],k[m+"_handler"]=b["on"+n]||f[n]);is_def(window.xeVid)&&(k.post_params.vid=xeVid),k.sessionName=b.sessionName,getCookie(b.sessionName)&&(k.post_params[b.sessionName]=getCookie(b.sessionName)),uploaderSettings[i]=k,o=new SWFUpload(k),p=a("#"+o.movieName),swfUploadObjs[i]=o.movieName,p.length&&(p.css({display:"block",cursor:"pointer",position:"absolute",left:0,top:0,width:d+"px",height:g+"px"}),(b.insertedFiles||editorRelKeys[i].primary.value)&&e(b))}function d(){return!0}function e(b){function c(){"function"==typeof _editorAutoSave&&(uploadAutosaveChecker=!0,_editorAutoSave(!0))}function d(d,e){var f,g,h,i,j,k,l,m,n,o,p;if(g=d.editor_sequence,h=d.files,j=d.upload_status,i=d.upload_target_srl,k=Math.floor((parseInt(d.left_size,10)||0)/1024),f=a("#"+b.fileListAreaID).empty(),i&&(editorRelKeys[g].primary.value!=i&&(editorRelKeys[g].primary.value=i,c()),editorRelKeys[g].primary.value=i,b.uploadTargetSrl=i),a("#"+b.uploaderStatusID).html(j),a("#"+b.previewAreaID).empty(),h&&h.item){for(l=h.item,a.isArray(l)||(l=[l]),m=0,n=l.length;n>m;m++)o=l[m],p=o.file_srl,uploadedFiles[p]=o,o.previewAreaID=b.previewAreaID,/\.(jpe?g|png|gif)$/i.test(o.download_url)&&(loaded_images[p]=a("<img />").attr("src",o.download_url).get(0)),a("<option />").text(o.source_filename+" ("+o.disp_file_size+" )").attr("value",p).appendTo(f);m&&f.prop("selectedIndex",m-1).click()}uploadAutosaveChecker||c()}var e={mid:current_mid,file_list_area_id:b.fileListAreaID,editor_sequence:b.editorSequence,upload_target_srl:b.uploadTargetSrl};exec_xml("file","getFileList",e,d,"error,message,files,upload_status,upload_target_srl,editor_sequence,left_size".split(","))}var f;f={onFileQueued:d,onFileQueueError:function(a,b,c){try{switch(b){case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:alert("You have attempted to queue too many files.\n"+(0===c?"You have reached the upload limit.":"You may select "+(c>1?"up to "+c+" files.":"one file.")));break;case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:alert("Error Code: File too big, File name: "+a.name+", File size: "+a.size+", Message: "+c);break;case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:alert("Error Code: Zero byte file, File name: "+a.name+", File size: "+a.size+", Message: "+c);break;case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:alert("Error Code: Invalid File Type, File name: "+a.name+", File size: "+a.size+", Message: "+c);break;default:alert("Error Code: "+b+", File name: "+a.name+", File size: "+a.size+", Message: "+c)}}catch(d){this.debug(d)}},onFileDialogComplete:function(a,b){try{getCookie(this.settings.sessionName)&&this.addPostParam(this.settings.sessionName,getCookie(this.settings.sessionName)),this.startUpload()}catch(c){this.debug(c)}},onUploadStart:d,onUploadProgress:function(b,c,d){getCookie(this.settings.sessionName)&&this.addPostParam(this.settings.sessionName,getCookie(this.settings.sessionName));try{var e,f,g,h;e=a("#"+this.settings.fileListAreaID),g=Math.ceil(c/d*100),h=b.name,f=e.find(">option:last"),h.length>20&&(h=h.substr(0,20)+"..."),f.length&&f.attr("value")==b.id||(f=a("<option />").attr("value",b.id).appendTo(e)),f.text(h+" ("+g+"%)")}catch(i){this.debug(i)}},onUploadSuccess:function(a,b){try{0!==this.getStats().files_queued&&this.startUpload()}catch(c){this.debug(c)}},onUploadError:function(a,b,c){try{switch(b){case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:alert("Error Code: HTTP Error, File name: "+a.name+", Message: "+c);break;case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:alert("Error Code: Upload Failed, File name: "+a.name+", File size: "+a.size+", Message: "+c);break;case SWFUpload.UPLOAD_ERROR.IO_ERROR:alert("Error Code: IO Error, File name: "+a.name+", Message: "+c);break;case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:alert("Error Code: Security Error, File name: "+a.name+", Message: "+c);break;case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:alert("Error Code: Upload Limit Exceeded, File name: "+a.name+", File size: "+a.size+", Message: "+c);break;case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:alert("Error Code: File Validation Failed, File name: "+a.name+", File size: "+a.size+", Message: "+c);break;case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:0===this.getStats().files_queued&&(document.getElementById(this.customSettings.cancelButtonId).disabled=!0);break;case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:break;default:alert("Error Code: "+b+", File name: "+a.name+", File size: "+a.size+", Message: "+c)}}catch(d){this.debug(d)}},onUploadComplete:function(a){try{this.settings.fileListAreaID,this.settings.uploadTargetSrl;e(this.settings)}catch(b){this.debug(ex)}}},window.editorUploadInit=b,window.reloadFileList=e,a(function(){try{document.execCommand("BackgroundImageCache",!1,!0)}catch(a){}})}(jQuery);