Created
October 20, 2015 08:32
-
-
Save 4ox/9389a6c5f582854d5e16 to your computer and use it in GitHub Desktop.
upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#reportAddPhoto, #reportAddMovie").change(function(e){ | |
//파일 로드 및 사이즈 관리 | |
var file = e.target.files[0]; | |
var size = ( file.size / 1000 / 1000 ).toFixed(2); | |
var maxFileSize = 100; //MB | |
var maxFileLength = 3; | |
var fileCount = $(".progress-box .progress-wrap").length; | |
//파일크기부터 체크 | |
if( maxFileSize > size && size > 0 ) { | |
//첨부 파일 개수 관리 | |
if( fileCount < maxFileLength ) { | |
//파일리더 호출 | |
var fileReader = new FileReader(); | |
fileReader.readAsDataURL( file ); | |
//영상인지 사진인지에 따라 분리 | |
if( e.target.id == "reportAddMovie") { | |
fileReader.onloadend = function(e) { | |
//파일 이름 추출 및 가공 | |
var fileName = ( file.name.length > 10 ) ? file.name.substring(0,25) + "..." : file.name; | |
//템플릿 및 이벤트 설정 | |
var template = $("#tmpl_movie").tmpl({"FILENAME": fileName }); | |
template.find('.btn-del').click(function(){ | |
var box = $(this).closest(".progress-wrap"); | |
if( !NewReport.uploading ) { | |
var re = confirm( box.find('.txt').text() + " 항목을 삭제하시겠습니까?"); | |
if( re ) box.remove(); | |
NewReport.setFileNames(); | |
} | |
else { | |
alert("업로드 중입니다. 삭제하실수 없습니다."); | |
} | |
}); | |
//FILE데이터를 ELEMENT에 매핑 | |
template.data("FILE",file); | |
//보여줄 이미지 삽입 | |
$('.progress-box').append( template ); | |
template.find("video").remove(); | |
NewReport.setFileNames(); | |
/* | |
* 영상프리뷰를 보여주려했으나. 요청이 없는바. 삭제함 | |
try { | |
//비디오 프리뷰를 보여줌.. 안되면 삭제 | |
template.find("video") | |
.attr("src", (window.URL||window.webkitURL).createObjectURL( file ) ) | |
.css({"width":"100%"}); | |
} | |
catch(e) { | |
template.find("video").remove(); | |
} | |
*/ | |
} | |
e.target.files = []; | |
} | |
else { | |
//영상과 비슷하나 더심플 | |
fileReader.onloadend = function(e) { | |
var fileName = file.name.length > 10 ? file.name.substring(0,25) + "..." : file.name; | |
var template = $("#tmpl_photo").tmpl({"PREVIEW": e.target.result, "FILENAME" : fileName }); | |
template.find('.btn-del').click(function(){ | |
var box = $(this).closest(".progress-wrap"); | |
if( !NewReport.uploading ) { | |
var re = confirm( box.find('.txt').text() + " 항목을 삭제하시겠습니까?"); | |
if( re ) box.remove(); | |
NewReport.setFileNames(); | |
} | |
else { | |
alert("업로드 중입니다. 삭제하실수 없습니다."); | |
} | |
}); | |
template.data("FILE",file); | |
$('.progress-box').append( template ); | |
NewReport.setFileNames(); | |
} | |
} | |
$(this).val(""); | |
} | |
else { | |
alert("첨부파일은 3건 까지 가능합니다."); | |
} | |
} | |
else { | |
alert("제한 용량(100MB)를 초과하였습니다."); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment