window.FU = config: maxFileSizeMB: 10 messages: error: "Ошибка" done: "Загружено" data: -> icon: image: "//cdn1.iconfinder.com/data/icons/humano2/32x32/apps/synfig_icon.png" files: [] index: 0 active: false add: (file) -> FU.files.push file if /^image/.test(file.type) FileAPI.Image(file).preview(35).rotate("auto").get (err, img) -> FU._getEl(file, ".js-left").addClass("b-file__left_border").html img unless err getFileById: (id) -> i = FU.files.length return FU.files[i] if FileAPI.uid(FU.files[i]) is id while i-- start: -> FU._upload FU.files[FU.index] if not FU.active and (FU.active = FU.files.length > FU.index) abort: (id) -> file = @getFileById(id) file.xhr.abort() if file.xhr _getEl: (file, sel) -> $el = $("#file-" + FileAPI.uid(file)) (if sel then $el.find(sel) else $el) _upload: (file) -> if file FileAPI.upload( url: FU.config.uploadUrl+"?authenticity_token=#{encodeURIComponent($("meta[name=\"csrf-token\"]").attr("content"))}" data: FU.config.data() dataType: "script" files: file: file upload: -> FU._getEl(file).addClass "b-file_upload" FU._getEl(file, ".js-progress").css(opacity: 0).show().animate opacity: 1 , 100 progress: (evt) -> FU._getEl(file, ".js-bar").css "width", evt.loaded / evt.total * 100 + "%" complete: (err, xhr) -> setTimeout(xhr.responseText, 10) state = (if err then "error" else "done") FU._getEl(file).removeClass "b-file_upload" FU._getEl(file, ".js-progress").animate opacity: 0 , 200, -> $(@).hide().closest("div.js-file").delay(1000).fadeOut 200, -> $(@).remove() FU._getEl(file, ".js-info").append ", " + ((if err then (xhr.statusText or err) else FU.config.messages[state])) + "" FU.index++ FU.active = false FU.start() ) template: '