소스 파일 : /testing/dev_testing.js (2021-01-28)     소스 설명 : (개발 테스트) 메인 파일 로드시 자바스크립트 수행
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// (2022.7.31, 차재복, Cha Jae Bok, http://www.ktword.co.kr)

// load 이벤트 리스너 (collapsible 메뉴 관련)
window.addEventListener('load', function(event) {

    // 단순 펼침 메뉴 이벤트
    let subTrees = document.getElementsByClassName('subTreeOut');   // dev_testing.php
    for(let i=0; i<subTrees.length; i++) {
        subTrees[i].addEventListener('click', function(e) {
            e.preventDefault();

            // 이미 데이터 가져왔었으면, show/hide(toggle)
            let next = this.nextElementSibling;
            if(next && next.getAttribute('class') == 'tree') {
                itemShowHide(next, this);
            } else {
                this.innerHTML = this.innerText.replace('∨','∧');
                let out = document.createElement('div');
                    out.style.border = '1px gray solid';
                    out.setAttribute('class','tree');
                    // out div의 type, id 설정
                    out.dataset.type = subTrees[i].dataset.type;
                    out.dataset.id = subTrees[i].dataset.id;
                insertAfter(subTrees[i], out);      // common_utils.js
                fetchDataCreateOl(out);             // navi_base.js
            }
        });
    }

}, false);


// load 이벤트 리스너 (Toggle)
window.addEventListener('load', function(event) {

    // toggle 이벤트
    let opens = document.getElementsByClassName('toggle');
    for(let i=0; i<opens.length; i++) {
        opens[i].addEventListener('click', function(e) {
            e.preventDefault();
            const next = this.nextElementSibling;
            itemShowHide(next, opens[i]);
        });
    }

}, false);


// load 이벤트 리스너 (소스 관련)
window.addEventListener('load', function(event) {

    // 소스 내용 보기 이벤트
    let srcs = document.getElementsByClassName('src_view');
    for(let i=0; i<srcs.length; i++) {
        srcs[i].addEventListener('click', function(e) {
            e.preventDefault();
            const next = this.nextElementSibling;
            if(next && next.getAttribute('class')=='src_view_div') itemShowHide(next, srcs[i]);
            else {
                this.innerHTML = this.innerText.replace('∨','∧');
                srcViewDiv(this);
            }
        });
    }

}, false);

// 소스 내용 보기용 div 생성 및 소스 내용 보여주기
function srcViewDiv(that) {
    const queryString = that.href.split('?')[1];        // href 중 '?' 이후 문자열
    const urlParams = new URLSearchParams(queryString);
//console.log('dir='+urlParams.get('dir')+', file='+urlParams.get('file'));

    const div = document.createElement('div');
        div.setAttribute('class','src_view_div');
        div.style.margin = '5px';
        div.style.border = '1px solid gray';
        div.style.padding = '5px';
    insertAfter(that, div);

    const url = '../open_src/view_src.php?bare=1&dir='+urlParams.get('dir')+'&file='+urlParams.get('file');
    const method = 'get';
    ajaxText(div, url, method);
}

//
function ajaxText(out, url, method, parms) {
    const xhr = new XMLHttpRequest();
    if (!method) method = 'get';
    xhr.open(method, url);
	xhr.onreadystatechange = function() {
        if (xhr.readyState === 4 && xhr.status === 200) {
            // 서버로부터 온 결과가 비었을 경우
			if (!xhr.responseText) {
                    console.log(xhr.responseText);
                    alert('서버 처리 에러 ('+url+')');
					return;
            }
            // 서버로부터 온 결과를 out에 보여줌
			out.innerHTML = xhr.responseText;
        }
    };
    // ajax 호출용 쿼리 파라미터
    if (method=='post') {
        // FormData 형식이 아닌 경우 
        if (!parms.formData) {
            xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            let sendData = '';
            for (const property in parms) {
                sendData += property + '=' + encodeURIComponent(parms[property]) + '&';
            }
            xhr.send(sendData);
        // FormData 형식인 경우 
        } else if (parms.formData) {
            xhr.send(parms.formData);
        }
    } else if (method=='get') {
        xhr.send();    
    }

}



Copyrightⓒ written by 차재복 (Cha Jae Bok)
"본 웹사이트 내 모든 저작물은 원출처를 밝히는 한 자유롭게 사용(상업화포함) 가능합니다"