38 lines
1.7 KiB
JavaScript
38 lines
1.7 KiB
JavaScript
/**
|
|
* 지정된 범위(scope) 내에서 '.rb-autounwrap' 클래스를 찾아 포장을 해제하는 함수
|
|
* @param {HTMLElement} scope - 검색을 수행할 DOM 요소. 제공되지 않으면 문서 전체를 검색합니다.
|
|
*/
|
|
function unwrapModuleContainers(scope) {
|
|
// 검색 범위를 지정합니다.
|
|
const searchScope = scope || document;
|
|
|
|
// 'rb-autounwrap' 클래스를 가진 모든 모듈 컨테이너를 찾습니다.
|
|
const autoUnwrapModules = searchScope.querySelectorAll('.rb-autounwrap');
|
|
|
|
autoUnwrapModules.forEach(moduleContainer => {
|
|
// 이 모듈이 리빌더의 .content_box 안에 직접적으로 포함되어 있는지 확인합니다.
|
|
if (moduleContainer.parentElement.closest('.content_box')) {
|
|
// 부모가 .content_box라면, 이 모듈은 중첩된 상태입니다.
|
|
// 따라서, moduleContainer의 포장을 해제합니다.
|
|
|
|
// 1. moduleContainer 안의 모든 자식 요소들을 가져옵니다.
|
|
const children = Array.from(moduleContainer.childNodes);
|
|
|
|
// 2. moduleContainer의 부모 요소를 찾습니다.
|
|
const parent = moduleContainer.parentNode;
|
|
|
|
// 3. 모든 자식 요소들을 moduleContainer의 앞으로 이동시킵니다.
|
|
children.forEach(child => {
|
|
parent.insertBefore(child, moduleContainer);
|
|
});
|
|
|
|
// 4. 이제 비어있는 moduleContainer를 제거합니다.
|
|
parent.removeChild(moduleContainer);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 페이지가 처음 로드될 때 한 번 실행하여, 정적으로 포함된 모듈도 처리할 수 있도록 합니다.
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
unwrapModuleContainers(document.body);
|
|
}); |