source: branches/version-2_4-dev/html/test/uehara/js/tree.js @ 18699

Revision 18699, 5.3 KB checked in by nanasess, 16 years ago (diff)

Copyright の更新(#601)

  • Property svn:mime-type set to application/x-httpd-php; charset=UTF-8
Line 
1var IMG_FOLDER_CLOSE   = "./img/folder_close.gif";              // フォルダクローズ時画像
2var IMG_FOLDER_OPEN    = "./img/folder_open.gif";               // フォルダオープン時画像
3var IMG_PLUS           = "./img/plus.gif";                      // プラスライン
4var IMG_MINUS          = "./img/minus.gif";                     // マイナスライン
5var IMG_NORMAL         = "./img/normal.gif";                    // ノーマルライン
6
7var tree = "";                      // 生成HTML格納
8var count = 0;                      // ループカウンタ
9var arrTreeStatus = new Array();    // ツリー状態保持
10var old_select_id = '';             // 前回選択していたファイル
11
12// ツリー表示
13function fnTreeView(view_id, arrTree, openFolder) {
14
15    //tree += '<form name="tree_form">';
16    for(i = 0; i < arrTree.length; i++) {
17       
18        id = arrTree[i][0];
19        level = arrTree[i][3];
20       
21        if(i == 0) {
22            old_id = "0";
23            old_level = 0;
24        } else {
25            old_id = arrTree[i-1][0];
26            old_level = arrTree[i-1][3];
27        }
28   
29        // 階層上へ戻る
30        if(level <= (old_level - 1)) {
31            tmp_level = old_level - level;
32            for(up_roop = 0; up_roop <= tmp_level; up_roop++) {
33                tree += '</div>';
34            }
35        }
36       
37        // 同一階層で次のフォルダへ
38        if(id != old_id && level == old_level) tree += '</div>';
39   
40        // 階層の分だけスペースを入れる
41        for(space_cnt = 0; space_cnt < arrTree[i][3]; space_cnt++) {
42            tree += "&nbsp;&nbsp;&nbsp;";
43        }
44
45        // 階層画像の表示・非表示処理
46        if(arrTree[i][4]) {
47            if(arrTree[i][1] == '_parent') {
48                rank_img = IMG_MINUS;
49            } else {
50                rank_img = IMG_NORMAL;
51            }
52            // 開き状態を保持
53            arrTreeStatus.push(arrTree[i][2]);
54            display = 'block';
55        } else {
56            if(arrTree[i][1] == '_parent') {
57                rank_img = IMG_PLUS;
58            } else {
59                rank_img = IMG_NORMAL;
60            }
61            display = 'none';
62        }
63       
64        // フォルダの画像を選択
65        if(arrTree[i][2] == openFolder) {
66            folder_img = IMG_FOLDER_OPEN;
67        } else {
68            folder_img = IMG_FOLDER_CLOSE;
69        }
70
71        arrFileSplit = arrTree[i][2].split("/");
72        file_name = arrFileSplit[arrFileSplit.length-1];
73
74        // 階層画像がノーマルの時のみオンクリック処理をつける
75        if(rank_img != IMG_NORMAL) {
76            tree += '<input type="image" src="'+ rank_img +'" border="0" name="rank_img'+ i +'" id="rank_img'+ i +'" onclick="fnTreeMenu(\'tree'+ i +'\',\'rank_img'+ i +'\',\''+ arrTree[i][2] +'\')">';
77        } else {
78            tree += '<img src="'+ rank_img +'" border="0" name="rank_img'+ i +'" id="rank_img'+ i +'">';
79        }
80        tree += '<input type="image" src="'+ folder_img +'" border="0" name="tree_img'+ i +'" id="tree_img'+ i +'" onclick="fnFolderOpen(\''+ arrTree[i][2] +'\')">&nbsp;'+ file_name +'<br/>';
81        tree += '<div id="tree'+ i +'" style="display:'+ display +'">';
82   
83    }
84    //tree += '</form>';
85    fnDrow(view_id, tree);
86    //document.tree_form.tree_test2.focus();   
87}
88
89// Tree状態をhiddenにセット
90function setTreeStatus(name) {
91    var tree_status = "";
92    for(i=0; i < arrTreeStatus.length ;i++) {
93        if(i != 0) tree_status += '|';
94        tree_status += arrTreeStatus[i];
95    }
96    document.form1[name].value = tree_status;
97}
98
99// Tree状態を削除する(閉じる状態へ)
100function fnDelTreeStatus(path) {
101    for(i=0; i < arrTreeStatus.length ;i++) {
102        if(arrTreeStatus[i] == path) {
103            arrTreeStatus[i] = "";
104        }
105    }
106}
107// ツリー描画
108function fnDrow(id, tree) {
109    // ブラウザ取得
110    MyBR = fnGetMyBrowser();
111    // ブラウザ事に処理を切り分け
112    switch(myBR) {
113        // IE4の時の表示
114        case 'I4':
115            document.all(id).innerHTML = tree;
116            break;
117        // NN4の時の表示
118        case 'N4':
119            document.layers[id].document.open();
120            document.layers[id].document.write("<div>");
121            document.layers[id].document.write(tree);
122            document.layers[id].document.write("</div>");
123            document.layers[id].document.close();
124            break;
125        default:
126            document.getElementById(id).innerHTML=tree;
127            break;
128    }
129}
130
131// 階層ツリーメニュー表示・非表示処理
132function fnTreeMenu(tName, imgName, path) {
133
134    tMenu = document.all[tName].style;
135
136    if(tMenu.display == 'none') {
137        fnChgImg(IMG_MINUS, imgName);
138        tMenu.display = "block";
139        // 階層の開いた状態を保持
140        arrTreeStatus.push(path);
141
142    } else {
143        fnChgImg(IMG_PLUS, imgName);
144        tMenu.display = "none";
145        // 閉じ状態を保持
146        fnDelTreeStatus(path);
147    }
148}
149
150// フォルダオープン処理
151function fnFolderOpen(path) {
152
153    // クリックしたフォルダ情報を保持
154    document.form1['tree_select_file'].value = path;
155    // treeの状態をセット
156    setTreeStatus('tree_status');
157    // submit
158    fnModeSubmit('move','','');
159}
160
161
162// 閲覧ブラウザ取得
163function fnGetMyBrowser() {
164    myOP = window.opera;            // OP
165    myN6 = document.getElementById; // N6
166    myIE = document.all;            // IE
167    myN4 = document.layers;         // N4
168    if      (myOP) myBR="O6";       // OP6以上
169    else if (myIE) myBR="I4";       // IE4以上
170    else if (myN6) myBR="N6";       // NS6以上
171    else if (myN4) myBR="N4";       // NN4
172    else           myBR="";         // その他
173       
174    return myBR;
175}
176
177// imgタグの画像変更
178function fnChgImg(fileName,imgName){
179    document.getElementById(imgName).src = fileName;
180}
181
182// ファイル選択
183function fnSelectFile(id, val) {
184    if(old_select_id != '') document.getElementById(old_select_id).style.backgroundColor = '';
185    document.getElementById(id).style.backgroundColor = val;
186    old_select_id = id;
187}
188
189// 背景色を変える
190function fnChangeBgColor(id, val) {
191    if (old_select_id != id) {
192        document.getElementById(id).style.backgroundColor = val;
193    }
194}
Note: See TracBrowser for help on using the repository browser.