Файл: touchSpace/js/files_uploader.js
Строк: 271
<?php
define("files_uploader","init",function(){function e(e){var i,t,l,s,S,h,E,w,D,y,U,x,F;r=extend({type:Spaces.TYPES.FILE,maxSize:!1,action:null,name:"myFile",selectButton:null,buttonClass:{},uploadWidget:null,uploadDrag:null,autoSubmit:!1,mode:m.WIDGET,onShowNative:null,onFileUpload:null,onError:null,onHideError:null,onSubmit:null,onReset:null},e),c=$(r.uploadWidget),_=$(r.uploadDrag),c.replaceWith(n()),r.selectButton?(u=$(r.selectButton),b&&(u.click(function(e){e.preventDefault(),e.stopPropagation(),r.onShowNative&&r.onShowNative()}),u=$("#upload_file_btn"))):u=$("#upload_file_btn"),i=new Url(r.action),t=$("#upload_file_name"),l=ge("#upload_progress"),s=$("#upload_file_size"),S=$("#upload_new_file"),h=$("#upload_selected_file"),E=$("#upload_progress_wrap"),w=$("#upload_cancel_btn"),D=$("#upload_file_delete").hide(),y=$("#upload_file_info"),$("#upload_submit_btn").click(function(e){e.preventDefault(),setTimeout(function(){p.submit()},0)}),U=function(){b?(D.hide(),y.hide()):r.mode==m.WIDGET&&u.val("Выберите файл"),w.hide(),t.text("Файл не выбран").find(".upload_spinner").remove(),s.text(""),u.show(),E.hide(),S.show(),h.hide(),r.onReset&&r.onReset(),p.updateButton()},b&&y.hide(),_.data("dragover-class","dropable-selected"),_.data("dragavail-class","dropable"),i.query.json=1,i.query._origin=location.protocol+"//"+location.host,FilesUploader.isAjaxSupport()||(i.query.xhr_iframe=1),x=g[r.type],p=new FilesUploader({button:b?null:u,action:i.url(),name:r.name,maxSize:r.maxSize,maxFiles:1,autoSubmit:r.autoSubmit,accept:x.accept,postData:{json:1},buttonClass:r.buttonClass,allowedExtensions:x.exts}),p.addDropPlace(_),p.addPastePlace(_),D.click(function(){return p.reset(),!1}),w.click(function(){return p.cancel(),!1}),F=!1,p.on("progress",function(e,o,i){i>0&&!F&&(E.show(),F=!0),l.style.width=o+"%",r.mode!=m.WIDGET||b||u.val("Выгружаем..."+(i>0?" "+Math.round(o)+"%":""))}).on("delete",function(){U()}).on("input",function(e){console.log("input",e),b&&(u.empty(),u.append(e))}).on("file",function(e,o,i){return d(!1),S.hide(),h.show(),t.html('<img src="'+ICONS_BASEURL+Spaces.getFileIcon(o)+'" alt="" class="m"/> <span class="m">'+html_wrap(e||"Имя файла не определено")+"</span>"),s.text(i?"("+Spaces.getHumanSize(i)+")":""),b&&(u.hide(),r.autoSubmit||D.show(),y.show()),!0}).on("submit",function(){return r.onSubmit&&r.onSubmit()===!1?!1:(w.show(),"desktop"!=Device.type&&u.hide(),f.json=1,this.setPostData(f),d(!1),F=!1,void o())}).on("uploadStart",function(){v=[]}).on("complete",function(){if(U(),r.onFileUpload)for(var e=0;e<v.length;++e)r.onFileUpload(v[e])}).on("uploaded",function(e,o){if(0!=o.code){var i;i=51==o.code||o.code==Codes.FILES.ERR_UPLOAD_ERROR?o.errMsg:Spaces.services.processingCodes(o),d(i)}else o.data&&Spaces.core.fixFile(o.data,r.type,!0),v.push(o)}).on("extError",function(e,o){d("Данный тип файла ("+html_wrap(o)+") нельзя хранить в разделе <b>"+x.name+"</b>")}).on("sizeError",function(){d("Файл не должен быть больше "+Spaces.getHumanSize(r.maxSize))}).on("notSelectedError",function(){d("Файл не выбран!")}).on("error",function(e,o,i,t){d(status>0?Spaces.getHttpError(o):"Ошибка загрузки файла "+i),console.error("[upload error]",e,o,i,t)}),page_loader&&(page_loader.on("shutdown","files_uploader",a),page_loader.one("beforerequest",function(){return p.inUpload()?confirm("Вы уверены, что хотите прервать загрузку файла и перейти на другую страницу?")?(p.cancel(),!0):!1:void 0}))}function o(){$("#upload_file_name").find("img").replaceWith('<img src="'+ICONS_BASEURL+'roundPreloader.gif" alt="" class="m upload_spinner" /> ')}function i(e){f=$.extend({},e)}function t(){var e="";return FilesUploader.maybeUnsupported()&&(e='<div style="color: red">Скорее всего, ваше устройство не поддерживает выгрузку файлов. </div>'),b?r.mode==FileUploader.MODES.BUTTON?'<div class="t_center"><span id="upload_file_btn"></span> <input type="submit" value="OK" id="upload_submit_btn" />'+e+"</div>":'<div id="upload_file_btn"></div>'+e:r.mode==FileUploader.MODES.WIDGET?e+'<input type="submit" value="Выберите файл" type="submit" id="upload_file_btn" /> ':'<div id="upload_file_btn" class="t_center"><img src="'+ICONS_BASEURL+'icon_add_file.gif" alt="" class="m" /> <small class="m" style="font-weight:bold;">Загрузить новый файл</small>'+e+"</div>"}function n(){var e,o='<input id="upload_cancel_btn" type="submit" value="Отмена" class="hide'+("desktop"==Device.type?" response font_medium right":"")+'" /> ',i=' <span id="upload_file_delete"class="m ico ico_close"></span>';return e=r.mode==FileUploader.MODES.WIDGET?'<div><div id="upload_chooser_wrap">'+o+t()+'<span id="upload_file_info"> <span id="upload_file_name">Файл не выбран</span> <b id="upload_file_size"></b>'+i+'</span></div><div id="upload_progress_wrap" style="display: none;"><br /><div class="progress-item"><div class="progress-item__runner progress-item__runner_light" id="upload_progress"></div></div></div></div>':'<div class="stnd_padd light_border_bottom grey pointer"><div id="upload_new_file">'+t()+'</div><div id="upload_selected_file" class="hide pad_t_a"><div id="upload_chooser_wrap">'+o+'<span id="upload_file_info"> <span id="upload_file_name"></span> <b id="upload_file_size"></b>'+i+'</span></div><div id="upload_progress_wrap" style="display: none;"><br /><div class="progress-item"><div class="progress-item__runner progress-item__runner_light" id="upload_progress"></div></div></div></div></div>'}function a(){$(document.body).off(".files_uploader")}function l(e){var o,i,t,n={};for(o=0;o<e.elements.length;++o)i=e.elements[o],t=i.type.toLowerCase(),i.name.length&&"file"!=t&&("radio"!=t&&"checkbox"!=t||i.checked)&&("submit"!=t||i==e.submit_btn)&&(n[i.name]=i.value);return n}function d(e){e?r.onError?r.onError(e):Spaces.showError(e,"upload_err"):r.onHideError?r.onHideError(e):Spaces.clearError("upload_err")}function s(o,i){var t=$("#"+o),n=t.find('input[type="file"]');e({uploadWidget:n,uploadDrag:t,name:n.prop("name"),accept:n.prop("accept"),type:i.filter||Spaces.TYPES.FILE,action:t.prop("action"),maxSize:1024*i.max_size||0,autoSubmit:!1,mode:FileUploader.MODES.WIDGET,onSubmit:function(){FileUploader.setPostData(l(t[0]))},onFileUpload:function(e){Spaces.redirect(e.redirect_link)}}),t.submit(function(e){e.preventDefault(),p.submit()})}var r,p,u,c,_,m={WIDGET:0,BUTTON:1},f={},v=[],b=FilesUploader.needNtiveControls(),g={};g[Spaces.TYPES.FILE]={name:"Файлы",exts:[],accept:""},g[Spaces.TYPES.PICTURE]={name:"Фото",exts:["gif","jpg","jpeg","png","bmp"],accept:"image/*"},g[Spaces.TYPES.MUSIC]={name:"Музыка",exts:["mp3","aac"],accept:"audio/*"},g[Spaces.TYPES.VIDEO]={name:"Видео",exts:["avi","3gp","3gpp","mpg","mpeg","wmv","mp4","flv","mov","webm","asf"],accept:"ucbrowser"!=Device.browser?"video/*":""},window.FileUploader={MODES:m,init:e,setupForm:s,setPostData:i}});
?>