cfmgrv4/app/Views/templates/admin/modal_form.php
2024-10-04 11:50:44 +09:00

61 lines
3.1 KiB
PHP

<!-- 처음 호출할때 사용법
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#iframeInModal" data-src="시작URL">시작</button>
-->
<!-- 동적으로 ifram src 바꾸고싶을때
<span data-bs-toggle="modal" data-bs-target="#iframeInModal" data-src="바꾸고싶은URL" style="cursor:pointer;">바꾸기</span>
-->
<div id="index_action_form" class="index_action_form modal fade" tabindex="-1" aria-labelledby="iframeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-centered modal-dialog-scrollable"> <!-- modal-lg는 모달 크기를 크게 설정 -->
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="iframeModalLabel">
<h4>&nbsp;&nbsp;<?= ICONS['DESKTOP'] ?> <?= $viewDatas['title'] ?>&nbsp;&nbsp;</h4>
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<iframe id="iframeInModal" src="about:blank" width="100%" height="400" frameborder="0" allowfullscreen></iframe>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- Modal이 열릴 때 iframe의 src를 설정 -->
<script>
function resizeIframe() {
var iframe = document.getElementById('iframeInModal');
iframe.style.height = iframe.contentWindow.document.body.scrollHeight + 'px';
}
function closeBootstrapModal() {
var modalElement = document.getElementById('index_action_form'); // 모달의 실제 DOM 요소 가져오기
var modalInstance = bootstrap.Modal.getInstance(modalElement); // 모달 인스턴스 가져오기
if (modalInstance) {
// 먼저 모달을 호출한 페이지를 리로드
window.location.reload();
modalInstance.hide(); // 모달 닫기 (hide() 메서드 사용)
} else {
console.error("Modal instance not found.");
}
}
var index_action_form = document.getElementById('index_action_form');
index_action_form.addEventListener('show.bs.modal', function(event) {
// 버튼이 클릭된 이벤트를 가져옴
var button = event.relatedTarget;
// console.log(button.getAttribute('data-src'));
var iframeSrc = button.getAttribute('data-src'); // data-src 값을 가져옴
var iframe = document.getElementById('iframeInModal');
// console.log(iframe.getAttribute('src'));
iframe.src = iframeSrc; // 가져온 data-src 값을 iframe에 설정
// iframe.onload = resizeIframe; // iframe이 로드된 후 높이를 조정
});
// 모달이 닫힐 때 iframe src를 초기화하여 종료 처리
index_action_form.addEventListener('hidden.bs.modal', function() {
var iframe = document.getElementById('iframeInModal');
iframe.src = "about:blank"; // 모달 닫힐 때 iframe 초기화
});
</script>