本クラスは、十分なテストを行っていません。また、エラー周りの実装は検討していません。
正常ケースを確認した環境は、IE6 for Windows、FireFox for Linuxです。
本プログラムは、高橋登史朗さま作成の jslb_ajax.js と拙作のkotatucommon1.jsが必要です。
jslb_ajax.jsについては、高橋登史朗さまのホームページ http://jsgt.org/mt/01/ を参照してください。
本プログラムは、商用利用および改造を自由に行ってくださってもかまいません。 ただし、Ajaxの更なる発展のため、改造したソースは公開してください。 利用・改造の連絡は不要です。 なお、本プログラムの利用によりあなた、またはあなたの周囲に損害が発生しても、 当方は一切関知しません。
| パラメータ名 | データ型 | 説明 |
|---|---|---|
| name | string | ツリー固有の名称を設定。展開格納点の<div><span>タグに付与するIDの先頭につける。IDが重複する(複数ツリーオブジェクトを作成するときなど)場合、適当な名称を入力する。 |
| imgflag | boolean | 子要素の展開格納マークにアイコンを使用するときに設定する。未設定またはfalseを指定したとき、showmark・hiddenmarkパラメータを使用する。trueを指定したとき、showimg・hiddenimgパラメータに指定したアイコンを使用する。 |
| showmark | string | 子要素を展開するときのマークを設定する。テキストを設定できる。デフォルト'-' |
| hiddenmark | string | 子要素を格納するときのマークを設定する。テキストを設定できる。デフォルト'+' |
| showimg | string | 子要素を展開するときのマークを設定する。アイコンのURIを設定できる。 |
| hiddenmark | string | 子要素を格納するときのマークを設定する。アイコンのURIを設定できる。 |
| showflag | boolean | 全展開格納点に対して初期状態での展開格納を設定できる。trueの場合展開、falseの場合格納する。 |
| idtype | number | 展開格納するときに子要素を囲む<div>タグおよび展開格納点+/-を囲む<span>に設定するIDの付け方を指定する。0を指定した場合、設定した順番を元に命名する。0以外の場合、表示名を元に命名する。先頭にトップオブジェクトID+nameパラメータの値を付加し、各レベルのID・表示名の間に、'_'を付与する。 例: <トップオブジェクトID>_<nameパラメータの値>_9_9 <トップオブジェクトID>_<nameパラメータの値>_xxxx_yyyy |
| パラメータ名 | データ型 | 説明 |
|---|---|---|
| text | string | ツリー要素の表示名 |
| url | string | 表示名のリンク先URL。リンク先を指定しない場合は、<a>タグを指定しない。> |
| showflag | boolean | 初期時の展開・格納状態を指定する。未設定およびtrueの場合、展開状態にする。falseの場合、格納状態にする。 |
| child | string(リスト)/null | 子の要素をリストで指定する。子要素がない場合は、nullを指定する。 |
| childurl | string(リスト) | 動的ローディングを行うツリーデータのURLをリストで指定する。 |
<html>
<head>
<script type="text/javascript" src="./ajax/lib/jslb_ajax.js"></script>
<script type="text/javascript" src="./kotatutree.js"></script>
<script type="text/javascript" src="./kotatucommon.js"></script>
<script language="javascript">
<!--
function changeContent(tURL){
parent.main.location.href=tURL;
}
var tree1=new kotatutree();
// -->
</script>
</head>
top1<br>
<div id='top1'></div>
<script language="javascript">
<!--
tree1.setTreeData('./contents_forobj.list');
tree1.createTree('top1');
tree1.show();
document.write("<textarea rows=10 cols=80>" + tree3.createTreeData + "</textarea>");
// -->
</script>
</body>
</html>
テストデータは、以下になります。テスト1とテスト2の違いは、1行目(トップのデータになります。)のshowflagが未設定(デフォルト:true)かfalseかになります。
{"text":"テスト2","url":"test4_1.html","child":[
{"text":"コンテンツ1","url":"test4_1.html","child":null},
{"text":"コンテンツ2","child":null},
{"text":"コンテンツ3","url":"test4_3.html","child":null}
]}
テスト2データ
{"text":"テスト1","url":"test4_1.html","showflag":false,"child":[
{"text":"コンテンツ1","url":"test4_1.html","child":null},
{"text":"コンテンツ2","child":null},
{"text":"コンテンツ3","url":"test4_3.html","child":null}
]}
<script language="javascript">
<!--
var treedata=
{text:"テスト1",url:"test4_1.html",child:[
{text:"コンテンツ1",url:"test1.html",child:[
{text:"コンテンツ1",url:"test4_1.html",child:[
{text:"コンテンツ1",url:"test4_1.html",child:null},
{text:"コンテンツ1",url:"test4_1.html",child:null}
]},
{text:"コンテンツ1",url:"test4_1.html",showflag:false,child:[
{text:"コンテンツ1",url:"test4_1.html",child:null},
{text:"コンテンツ1",url:"test4_1.html",child:null}
]}
]},
{text:"コンテンツ2",child":null},
{text:"コンテンツ3",url:"test4_3.html",child:[
{text:"コンテンツ1",url:"test4_1.html",child:[
{text:"コンテンツ1",url:"test4_1.html",child:null},
{text:"コンテンツ1",url:"test4_1.html",child:null}
]},
{text:"コンテンツ1",url:"test4_1.html",child:[
{text:"コンテンツ1",url:"test4_1.html",child:null},
{text:"コンテンツ1",url:"test4_1.html",child:null}
]}
]}
]}
var tree1=new kotatutree();
tree1.setTreeData(treedata);
tree1.createTree('top1');
tree1.show();
// -->
</script>
<script language="javascript">
<!--
function changeContent(tURL){
alert(tURL);
location.href=tURL;
return false;
}
var tree41=new kotatutree();
tree41.setTreeData('./test4.list');
tree41.setLinkScript('changeContent');
var param={treename:'test41',imgflag:false,showmark:'(゚.゚)/',hiddenmark:'(-_-)',showflag:false,idtype:0};
tree41.setParam(param);
tree41.createTree('top41');
var tree42=new kotatutree();
tree42.setTreeData('./test4.list');
tree42.setLinkScript('changeContent');
tree42.setParam({treename:'test42',imgflag:true,showimg:'./img/open.gif',hiddenimg:'./img/close.gif',showflag:true,idtype:1});
tree42.createTree('top42');
tree41.show();
tree42.show();
// -->
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>tree test6</title>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="./css/kotatu.css" type="text/css" title="Default">
<script type="text/javascript" src="./ajax/lib/jslb_ajax.js"></script>
<script type="text/javascript" src="./ajax/lib/jsgt_progressbar002.js" charset = "utf-8"></script>
<script type="text/javascript" src="./cgi/kotatutree.js"></script>
<script type="text/javascript" src="./cgi/kotatucommon1.js"></script>
</head>
<body class="contentslist">
<h1>子要素を動的に読み込む</h1>
<br>
<div id='top6'></div>
<script language="javascript">
<!--
function changeContent(tURL){
location.href=tURL;
return false;
}
test1 = new jsgt_ProgressBar();
var tree6=new kotatutree();
tree6.setTreeData('./test6.list');
tree6.setLinkScript('changeContent');
tree6.setProgress(test1);
tree6.createTree('top6');
tree6.show();
// -->
</script>
<br><li>上ツリー部分のhtmlソース</li><br>
<form name="testform">
<textarea rows=10 cols=40 name="testarea">
</textarea><br>
<INPUT TYPE="button" Value="更新" onClick="document.testform.testarea.value=window.document.documentElement.outerHTML;">
</form>
<script language="javascript">
<!--
document.testform.testarea.value=tree6.createTreeData;
// -->
</script>
</body>
</html>
{"text":"テスト1","url":"test4_1.html","childurl":["test6_1.list","test6_2.list","test6_3.list"]}
test6_1.list
{"text":"コンテンツ1","url":"test4_1.html","childurl":["test6_1_1.list","test6_1_2.list"]}
test6_1_1.list
{"text":"コンテンツ11","url":"test4_1.html","child":[
{"text":"コンテンツ111","url":"test4_1.html","child":null},
{"text":"コンテンツ112","url":"test4_1.html","child":null}
]}
test6_1_2.list
{"text":"コンテンツ11","url":"test4_1.html","child":[
{"text":"コンテンツ111","url":"test4_1.html","child":null},
{"text":"コンテンツ112","url":"test4_1.html","child":null}
]}
test6_2.list
{"text":"コンテンツ2","child":null}
test6_3.list
{"text":"コンテンツ3","url":"test4_3.html","child":[
{"text":"コンテンツ31","url":"test4_1.html","child":[
{"text":"コンテンツ311","url":"test4_1.html","child":null},
{"text":"コンテンツ312","url":"test4_1.html","child":null}
]},
{"text":"コンテンツ32","url":"test4_1.html","child":[
{"text":"コンテンツ321","url":"test4_1.html","child":null},
{"text":"コンテンツ322","url":"test4_1.html","showflag":false,"child":null}
]}
]}
| 2006/05/01 | リリース |
| 2006/05/06 | 動的ローディングでの問題「childurlに複数設定すると、 タグのidが重複する、および全て端になる」を解決しました。非同期でローディングしたのが問題でした。途中の要素を動的ローディングする場合は、同期でローディングするように修正しました。 |
| 2006/05/12 | 「1つのHTML中に2つ以上のオブジェクト作成すると最後のオブジェクトのみ生成される」問題を解決しました。非同期でローディングしたのが問題でした。途中の要素を動的ローディングする場合は、同期でローディングするように修正しました。(非同期でできるか検討中です。というか今の時点ではAJAXではないな。SJAX?) |