본문 바로가기
개발하는 '정'/기타

그누보드4 cheditor5 이미지 업로드 플래시 제거 (ajax로 대체)

by 주앤정_블로그 2021. 3. 19.

cheditor5 에디터 사용 중에

오른쪽 상단에 사진 추가 버튼이 플래시로 되어있어서 사진 추가가 안 되는 현상..

 

그누보드나 에디터 버전 변경할 시간이 없어서 플래시만 떼어내기로 했다.

 


 

/cheditor5/popup/image.html 변경 전

	<head>
		<meta name="robots" content="noindex, nofollow" />
		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
		<link rel="stylesheet" type="text/css" href="../css/imageUpload.css" />
		<script src="js/dialog.js" type="text/javascript"></script>
		<script src="js/image.js" type="text/javascript"></script>
		<script src="js/image_upload_flash.js" type="text/javascript"></script>
		<script type="text/javascript">
		</script>
	</head>
	<body scroll="no">
		<div id="uploadWindow">
 			<div id="container">
				<div style="float:left;margin-top:4px;font-size:8pt;font-family:dottum;color:#666">
					<img src="../icons/imageUpload/mouse_drag_img.gif" width="19" height="16" alt="" style="vertical-align:middle" />
					마우스로 드래그하여 순서를 바꾸세요.&nbsp;&nbsp;&nbsp;(<b><span id="imageCount">0</span></b>장 / 12장 사진)
				</div>
				<div style="float:right;margin:0px 0px 7px 0px">
					<table border="0" cellpadding="0" cellspacing="0">
						<tr>
						<td id="oFlash"></td>
							<td><img src="../icons/imageUpload/remove_all.gif" class="button" style="margin-left:3px;vertical-align:middle" onclick="removeImage()" alt="" /></td>
						</tr>
					</table>
  			</div>

 

/cheditor5/popup/image.html 변경 후

(image.js 파일에 함수를 올리라고 하는데 세팅 문제인지 함수를 찾을 수가 없다고 떠서 image.html 파일에 넣었다.)

	<head>
		<meta name="robots" content="noindex, nofollow" />
		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
		<link rel="stylesheet" type="text/css" href="../css/imageUpload.css" />
		<script src="js/dialog.js" type="text/javascript"></script>
		<script src="js/image.js" type="text/javascript"></script>
		<script src="//code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
		<script src="js/dialog.js" type="text/javascript"></script>
		<!--
		<script src="js/image_upload_flash.js" type="text/javascript"></script>
		-->
		<script type="text/javascript">
			function noFlashUploadOpen() {
				$("#nfile").click(); // 숨김 input file를 클릭하는 효과
			}
			function noFlashUpload() {
				console.log("?");
				var uplist = $("#nfile").get(0).files; // 숨김 input file에서 파일 배열을 가져옴
				if(uplist.length < 1) return; // 첨부없으면 끝 
				for(var i = 0; i < uplist.length; i++) {
					// 각 파일의 형식 제한
					if(uplist[i].type != "image/png" && uplist[i].type != "image/gif" && uplist[i].type != "image/jpg" && uplist[i].type != "image/jpeg") {
						fileFilterError(uplist[i].name);
						return;
					}
				}
				// 업로드 시작 알림(로더)
				startUpload(uplist.length); // image.js
				// 업로드 작업
				// cheditor5/imageUpload/upload.php 에서 1개씩만 업로드를 처리하므로 개별처리
				// 순차 처리를 위해서 ajax의 비동기를 끔 async: false
				// 업로드 진행율이 필요없으므로 xhr 은 제외
				for(var i = 0; i < uplist.length; i++) {
					var formData = new FormData();
					formData.append("file", uplist[i]);
					$.ajax( {
						url: UploadScript,
						type: "POST",
						contentType: false,
						processData: false,
						crossDomain: true,
						cache: false,
						async: false,
						dataType: "text", // 여기 본인 상황에 맞게
						data: formData,
						success: function(response, textStatus, xhr) {
							uploadComplete(response);
						},
						error: function(xhr, textStatus, error) {
							console.log(xhr.responseText);
						}
					});
				}
			}
		</script>
	</head>
	<body scroll="no">
		<div id="uploadWindow">
 			<div id="container">
				<div style="float:left;margin-top:4px;font-size:8pt;font-family:dottum;color:#666">
					<img src="../icons/imageUpload/mouse_drag_img.gif" width="19" height="16" alt="" style="vertical-align:middle" />
					마우스로 드래그하여 순서를 바꾸세요.&nbsp;&nbsp;&nbsp;(<b><span id="imageCount">0</span></b>장 / 12장 사진)
				</div>
				<div style="float:right;margin:0px 0px 7px 0px">
					<table border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td id="oFlash">
								<input type="file" id="nfile" name="nfile" multiple="multiple" accept=".gif,.jpg,.jpeg,.png" style="display:none" onchange="noFlashUpload()"/>
								<img src="../icons/imageUpload/add_image_button.gif" style="margin-left:3px;vertical-align:middle;cursor:pointer" onclick="noFlashUploadOpen()" alt="" />
							</td>
							<td><img src="../icons/imageUpload/remove_all.gif" class="button" style="margin-left:3px;vertical-align:middle" onclick="removeImage()" alt="" /></td>
						</tr>
					</table>
  			</div>

 

/cheditor5/popup/js/image.js 에 추가

function noFlashUploadOpen() {
    $("#nfile").click(); // 숨김 input file를 클릭하는 효과
}
function noFlashUpload() {
    var uplist = $("#nfile").get(0).files; // 숨김 input file에서 파일 배열을 가져옴
    if(uplist.length < 1) return; // 첨부없으면 끝 
    for(var i = 0; i < uplist.length; i++) {
        // 각 파일의 형식 제한
        if(uplist[i].type != "image/png" && uplist[i].type != "image/gif" && uplist[i].type != "image/jpg" && uplist[i].type != "image/jpeg") {
            fileFilterError(uplist[i].name);
            return;
        }
    }
    // 업로드 시작 알림(로더)
    startUpload(uplist.length); // image.js
    // 업로드 작업
    // cheditor5/imageUpload/upload.php 에서 1개씩만 업로드를 처리하므로 개별처리
    // 순차 처리를 위해서 ajax의 비동기를 끔 async: false
    // 업로드 진행율이 필요없으므로 xhr 은 제외
    for(var i = 0; i < uplist.length; i++) {
        var formData = new FormData();
        formData.append("file", uplist[i]);
        $.ajax( {
            url: UploadScript,
            type: "POST",
            contentType: false,
            processData: false,
            crossDomain: true,
            cache: false,
            async: false,
            dataType: "text", // 여기 본인 상황에 맞게
            data: formData,
            success: function(response, textStatus, xhr) {
                uploadComplete(response);
            },
            error: function(xhr, textStatus, error) {
                console.log(xhr.responseText);
            }
        });
    }
}

 

참조글

그누보드 cheditor5 에디터 버튼 플래시 제거

 

그누보드4의 cheditor5 플래시를 ajax로 > SIR

여러 버전이 있고, 또 뭔가 좀 안맞는 구석도 있고 해서 다시 정리해서 올립니다.
복붙하지 마시고 본인의 에디터를 살펴보고 적당히 수정해서 넣으세요.

 

1) 플래시 버튼을

sir.kr

글 올려주신 분께 압도적 감사 ㅠㅠㅠ

빨리 해결하려고 덕지덕지 붙인 소스라 꼭 참조 글을 확인하길...!

또 이런 일이 있을까 봐 글 남겨둔다..

반응형

댓글