diff --git a/WebContent/WEB-INF/view/contractMgmt/estimateAndOrderRegistFormPopup.jsp b/WebContent/WEB-INF/view/contractMgmt/estimateAndOrderRegistFormPopup.jsp index b402653..278c234 100644 --- a/WebContent/WEB-INF/view/contractMgmt/estimateAndOrderRegistFormPopup.jsp +++ b/WebContent/WEB-INF/view/contractMgmt/estimateAndOrderRegistFormPopup.jsp @@ -136,37 +136,41 @@ // ===== Select2 드래그 복사 지원 ===== function fn_initSelect2DragCopy() { - // capturing phase로 Select2보다 먼저 mousedown 가로채기 - document.addEventListener('mousedown', function(e) { - var $target = $(e.target); - var $container = $target.closest('#itemListTable .select2-container'); - if($container.length === 0) return; - if($target.hasClass('select2-selection__clear')) return; + var mouseTarget = null; // 마우스 조작 중인 select 요소 - // Select2의 mousedown 이벤트 전파 차단 - e.stopPropagation(); + // select2:opening을 상시 감시 — 마우스 조작 중이면 열림 차단 + $(document).on('select2:opening', '#itemListTable select', function(e) { + if(mouseTarget === this) { + e.preventDefault(); + } + }); + // mousedown: 이벤트 전파는 그대로 (네이티브 텍스트 선택 유지) + $(document).on('mousedown', '#itemListTable .select2-selection', function(e) { + if($(e.target).hasClass('select2-selection__clear')) return; + + var $container = $(this).closest('.select2-container'); var $select = $container.prev('select'); + mouseTarget = $select[0]; // 열림 차단 활성화 + var startX = e.pageX, startY = e.pageY; var wasDragged = false; - var onMove = function(ev) { + $(document).on('mousemove.s2drag', function(ev) { if(Math.abs(ev.pageX - startX) > 3 || Math.abs(ev.pageY - startY) > 3) { wasDragged = true; } - }; + }); - var onUp = function() { - document.removeEventListener('mousemove', onMove, true); - document.removeEventListener('mouseup', onUp, true); + $(document).on('mouseup.s2drag', function() { + $(document).off('mousemove.s2drag mouseup.s2drag'); if(!wasDragged) { + mouseTarget = null; // 차단 해제 $select.select2('open'); } - }; - - document.addEventListener('mousemove', onMove, true); - document.addEventListener('mouseup', onUp, true); - }, true); // capturing phase + setTimeout(function() { mouseTarget = null; }, 50); + }); + }); } $(function() { diff --git a/WebContent/WEB-INF/view/contractMgmt/estimateRegistFormPopup.jsp b/WebContent/WEB-INF/view/contractMgmt/estimateRegistFormPopup.jsp index 96e7bf7..a559624 100644 --- a/WebContent/WEB-INF/view/contractMgmt/estimateRegistFormPopup.jsp +++ b/WebContent/WEB-INF/view/contractMgmt/estimateRegistFormPopup.jsp @@ -137,37 +137,41 @@ // ===== Select2 드래그 복사 지원 ===== function fn_initSelect2DragCopy() { - // capturing phase로 Select2보다 먼저 mousedown 가로채기 - document.addEventListener('mousedown', function(e) { - var $target = $(e.target); - var $container = $target.closest('#itemListTable .select2-container'); - if($container.length === 0) return; - if($target.hasClass('select2-selection__clear')) return; + var mouseTarget = null; // 마우스 조작 중인 select 요소 - // Select2의 mousedown 이벤트 전파 차단 - e.stopPropagation(); + // select2:opening을 상시 감시 — 마우스 조작 중이면 열림 차단 + $(document).on('select2:opening', '#itemListTable select', function(e) { + if(mouseTarget === this) { + e.preventDefault(); + } + }); + // mousedown: 이벤트 전파는 그대로 (네이티브 텍스트 선택 유지) + $(document).on('mousedown', '#itemListTable .select2-selection', function(e) { + if($(e.target).hasClass('select2-selection__clear')) return; + + var $container = $(this).closest('.select2-container'); var $select = $container.prev('select'); + mouseTarget = $select[0]; // 열림 차단 활성화 + var startX = e.pageX, startY = e.pageY; var wasDragged = false; - var onMove = function(ev) { + $(document).on('mousemove.s2drag', function(ev) { if(Math.abs(ev.pageX - startX) > 3 || Math.abs(ev.pageY - startY) > 3) { wasDragged = true; } - }; + }); - var onUp = function() { - document.removeEventListener('mousemove', onMove, true); - document.removeEventListener('mouseup', onUp, true); + $(document).on('mouseup.s2drag', function() { + $(document).off('mousemove.s2drag mouseup.s2drag'); if(!wasDragged) { + mouseTarget = null; // 차단 해제 $select.select2('open'); } - }; - - document.addEventListener('mousemove', onMove, true); - document.addEventListener('mouseup', onUp, true); - }, true); // capturing phase + setTimeout(function() { mouseTarget = null; }, 50); + }); + }); } $(function() {