Файл: touchSpace/js/avatar_change.js
Строк: 233
<?php
define("avatar_change","init",function(){function e(){r=$("#change_avatar_menu"),r.on("click",".menu_back",function(e){e.preventDefault(),e.stopPropagation(),i($(this).data("view"))}),r.append($('<div id="change_avatar_menu-upload" class="hide"><div class="upload_widget"></div></div>')),p=$(".change_avatar_link"),u=r.find(".ava_upload"),_=$("#change_avatar_menu-action"),f=$("#change_avatar_menu-buttons"),$menu_upload=$("#change_avatar_menu-upload");var e=$(".change_avatar_sublink");v=r.data("photo_id"),h=m=!1,v||r.find(".ava_delete").hide(),p.addClass("js-dd_menu_link").attr("data-menu_id","change_avatar_menu").attr("data-noclass","1").attr("data-position","1"),e.addClass("js-dd_menu_link user__ava").attr("data-menu_id","change_avatar_menu").attr("data-noclass","1").attr("data-position","1"),r.find(".ava_delete").click(function(e){e.preventDefault(),o(0,null)}),r.on("dd_menu_close",function(e){m?e.preventDefault():i("main")}),r.on("dd_menu_opened",function(){h?f.find(".photos_list").imagesSlider():(h=!0,i("action").append('<img src="'+ICONS_BASEURL+'roundPreloader.gif" alt="" class="m upload_spinner" /> Загрузка...'),require("avatar_change_modules",function(){r.find(".change_avatar_selector").click(function(e){e.preventDefault(),FilesSelector.open({attaches:!1,type:Spaces.TYPES.PICTURE,onFileSelect:function(e,a,n){o(e,n.preview.previewURL)}})}),r.find(".ava_take_photo").hide();f.find();n(function(){Spaces.api("files.getUploadInfo",{Type:Spaces.TYPES.PICTURE},function(e){0==e.code&&(upload=s(e),i("main"),f.find(".photos_list").imagesSlider())})})}))})}function a(e,a){var n,t,i=f.find(".photos_list");if(!e.length)return void i.html("<div>У вас нет загруженных фото. </div>");for(n="",t=0;t<e.length;++t)n+='<div data-file_id="'+e[t].nid+'"><span class="ico ico_photo_'+(a==e[t].nid?"selected":"select")+'"></span><img src="'+e[t].preview.previewURL+'" /></div>';n+="",i.html(n).find("[data-file_id]").click(function(){var e=$(this);o(e.data("file_id"),e.find("img").prop("src"))})}function n(e){Spaces.api("files.select",{Type:Spaces.TYPES.PICTURE,Lt:Spaces.FILES_LIST.FILES_ALL},function(n){0==n.code&&(r.find(".change_avatar_selector").toggle(n.select_widget.listingW.files.length>0),a(n.select_widget.listingW.files,v),f.find(".photos_list").imagesSlider()),e&&e()})}function t(){$(document.body).click()}function i(e){return"main"==e||"action"==e?($menu_upload.hide(),"action"==e?(_.empty().show(),f.hide()):(_.empty().hide(),f.show()),_):"upload"==e?(f.hide(),_.empty().hide(),$menu_upload.show(),$menu_upload):void 0}function o(e,a){Spaces.clearError("upload_err"),c(!0),r.find(".ava_delete").toggle(e>0),Spaces.api(e?"anketa.photoEdit":"anketa.photoDelete",{CK:null,Photo:e},function(n){0==n.code?(v=e,d(e,e?a:n.default_photo)):(c(!1),Spaces.showApiError(n,"upload_err"))},{prefix:"neoapi"})}function d(e,a){var n=f.find(".photos_list");n.find(".ico_photo_selected").removeClass("ico_photo_selected").addClass("ico_photo_select"),e&&n.find('[data-file_id="'+e+'"] .ico_photo_select').addClass("ico_photo_selected"),$(".update_avatar img").prop("src",a)}function c(e){var a=$(".update_avatar img");e?(a.prop("old_src",a.prop("src")),a.prop("src",ICONS_BASEURL+"roundPreloader.gif")):a.prop("src",a.prop("old_src"))}function l(e,a){i("action").append('<div><div class="content-bl content-bl_first content-bl__sep" style="color: red">'+e+'</div><button class="menu_back btn-main" data-view="'+(a||"main")+'"><span class="ico ico_remove"></span> Отмена</button></div>')}function s(e){FileUploader.init({selectButton:u,uploadWidget:$menu_upload.find(".upload_widget"),buttonClass:{hover:"strong_clicked"},name:"myFile",type:Spaces.TYPES.PICTURE,action:e.url,maxSize:1024*e.maxSize*1024,autoSubmit:!0,mode:FileUploader.MODES.BUTTON,onSubmit:function(){m=!0,i("upload")},onShowNative:function(){i("upload")},onFileUpload:function(e){if(m=!1,0!=e.code){var a;a=51==e.code||e.code==Codes.FILES.ERR_UPLOAD_ERROR?e.errMsg:Spaces.services.processingCodes(e),l(a)}else m=!1,e.data=Spaces.core.fixFile(e.data,Spaces.TYPES.PICTURE,!0),o(e.data.id,e.data.thumbLink),n(),t()},onError:function(e){m=!1,l(e)},onHideError:function(){},onReset:function(){m=!1,i("main")}})}var r,p,u,_,f,v,h,m;page_loader&&page_loader.one("beforerequest",function(){return m?confirm("Вы уверены, что хотите прервать загрузку файла и перейти на другую страницу?")?(_.find(".upload_cancel").click(),!0):!1:void 0}),window.AvatarChange={init:e}}),define("avatar_change","onRequest",function(e){$(function(){AvatarChange.init(e)})});
?>