/************************************************************************************************** 鏂囦欢锛 js/webuploader/admin.upload.js 璇存槑锛 鍚庡彴闄勪欢绫诲瀷涓婁紶鎿嶄綔绫伙紝浠呴檺鍚庡彴鎿嶄綔 鐗堟湰锛 4.0 缃戠珯锛 www.phpok.com 浣滆€咃細 qinggan 鏃ユ湡锛 2015骞?4鏈?7鏃 12鏃?6鍒 ***************************************************************************************************/ ;(function($){ $.www_upload = function(options){ var self = this; var defaults = { 'id':'upload', 'swf':'js/webuploader/uploader.swf', 'server':'index.php', 'pick':'#picker', 'resize': false, 'multiple':false, 'disableGlobalDnd':true, 'fileVal':'upfile', 'sendAsBinary':false, 'chunked':true, 'chunkSize':102400, 'threads':3, 'auto':false, 'duplicate':true, 'accept':{'title':'鍥剧墖(*.jpg, *.gif, *.png)','extensions':'jpg,png,gif'} }; this.opts = $.extend({},defaults,options); this.id = "#"+this.opts.id; this.uploader = WebUploader.create(this.opts); this.upload_state = 'ready'; this.uploader.on('beforeFileQueued',function(file){ var extlist = (self.opts.accept.extensions).split(","); if($.inArray((file.ext).toLowerCase(),extlist) < 0){ $.dialog.alert('闄勪欢绫诲瀷涓嶆敮鎸 '+file.ext+' 鏍煎紡'); return false; } }); this.option = function(k,val){ self.uploader.option(k,val); } this.uploader.on('fileQueued',function(file){ $(self.id+"_progress").append('
' + '
' + file.name + ' 绛夊緟涓婁紶鈥?/span>
' + '
 
' + '
' + '
' ); $("#phpok-upfile-"+file.id+" .cancel").click(function(){ self.uploader.removeFile(file,true); $("#phpok-upfile-"+file.id).remove(); }); }); this.uploader.on('uploadProgress',function(file,percent){ var $li = $('#phpok-upfile-'+file.id), $percent = $li.find('.progress span'); var width = $li.find('.progress').width(); $percent.css( 'width', parseInt(width * percent, 10) + 'px' ); $li.find('span.status').html('姝e湪涓婁紶鈥?); self.upload_state = 'running'; }); this.uploader.on('uploadSuccess',function(file,data){ if(data.status != 'ok'){ $.dialog.alert('涓婁紶寮傚父锛岄敊璇彁绀猴細'+data.content); return false; } //鎵ц鑷畾涔夌殑鏂规硶 if(self.opts.success && self.opts.success != 'undefined'){ (self.opts.success)(file,data); return true; } $('#phpok-upfile-'+file.id).find('span.status').html('涓婁紶鎴愬姛'); var tmp = $.dialog.data('upload-'+self.opts.id); if(self.opts.multiple == 'true'){ var val = $(self.id).val(); if(val){ val += ","+data.content.id; }else{ val = data.content.id; } $(self.id).val(val); if(tmp){ tmp += ','+data.content.id; } }else{ if(tmp){ self.remote_delete(tmp); } tmp = data.content.id; $(self.id).val(data.content.id); } $.dialog.data('upload-'+self.opts.id,tmp); self.showhtml(); }); this.showhtml = function(){ var id = $(this.id).val(); if(!id){ return false; } var url = get_url('upload','thumbshow','id='+$.str.encode(id)); $.phpok.json(url,function(rs){ if(rs.status != 'ok'){ $(self.id).val(''); $(self.id+"_list").html('').fadeOut(); return true; } var html = ''; var index_i = 1; for(var i in rs.content){ html += self.html(rs.content[i],index_i); index_i++; } $(self.id+"_list").html(html).show(); if(!html){ $(self.id+"_list").html('').fadeOut(); } return true; }); }; this.html = function(rs,i){ var html = '
'; html += '
'; html += '
'; html += ' '; html += '
'; html += '
'; html += ''; return html; }; this.uploader.on('uploadError',function(file,reason){ $('#phpok-upfile-'+file.id).find('span.status').html('涓婁紶閿欒锛欬span style="color:red">'+reason+' '); }); this.uploader.on('uploadFinished',function(){ self.upload_state = 'ready'; }); //涓婁紶瀹屾垚锛屾棤璁哄け璐ヤ笌鍚︼紝3绉掑悗鍒犻櫎 this.uploader.on('uploadComplete',function(file){ $("#phpok-upfile-"+file.id).fadeOut(); }); this.uploader.on('error',function(handle){ if(handle == 'Q_EXCEED_NUM_LIMIT'){ $.dialog.alert('瑕佹坊鍔犵殑鏂囦欢鏁伴噺瓒呭嚭绯荤粺闄愬埗'); }else if(handle == 'Q_EXCEED_SIZE_LIMIT'){ $.dialog.alert('瑕佹坊鍔犵殑鏂囦欢鎬诲ぇ灏忚秴鍑虹郴缁熼檺鍒?); }else if(handle == 'Q_TYPE_DENIED'){ $.dialog.alert('鏂囦欢绫诲瀷涓嶇鍚堣姹?); }else if(handle == 'F_EXCEED_SIZE'){ $.dialog.alert('涓婁紶鏂囦欢瓒呰繃绯荤粺闄愬埗'); }else{ $.dialog.alert(handle); } return false; }); this.update = function(id){ $.dialog.open(get_url('upload','editopen','id='+id),{ 'title':'缂栬緫闄勪欢淇℃伅', 'width':'700px', 'height':'400px', 'lock':true, 'okVal':'鎻愪氦', 'ok':function(){ var iframe = this.iframe.contentWindow; if (!iframe.document.body) { alert('iframe杩樻病鍔犺浇瀹屾瘯鍛?); return false; }; iframe.save(); return false; }, 'cancelVal':'鍙栨秷淇敼', 'cancel':function(){} }); }; this.preview = function(id){ $.dialog.open(get_url('upload','preview','id='+id),{ 'title':'棰勮闄勪欢淇℃伅', 'width':'700px', 'height':'400px', 'lock':true, 'okVal':'鍏抽棴', 'ok':function(){} }); }; this.del = function(id){ var content = $(self.id).val(); if(!content || content == "undefined"){ return true; } //鍒犻櫎鍗曚釜闄勪欢 if(content == id){ $(self.id).val(""); $(self.id+"_list").fadeOut(function(){ $(this).html(''); }); //杩滅▼鍒犻櫎鏁版嵁 self.remote_delete(id); return true; } var list = content.split(","); var newlist = new Array(); var new_i = 0; for(var i=0;iparseInt(b['id']) ? 1 : -1}); var list = new Array(); for(var i in t){ list[i] = t[i]['data']; } var val = list.join(","); $(this.id).val(val); this.showhtml(); }; $(this.id+"_submit").click(function(){ if($(this).hasClass('disabled')){ $.dialog.alert('姝e湪涓婁紶涓紝宸查攣瀹?); return false; } var f = $(self.id+"_progress .phpok-upfile-list").length; if(f<1){ $.dialog.alert('璇烽€夋嫨瑕佷笂浼犵殑鏂囦欢'); return false; } if(self.upload_state == 'ready' || self.upload_state == 'paused'){ self.uploader.upload(); }else{ self.uploader.stop(); } }); }; })(jQuery);