| Current Path : /home/zqegovsj/www/us3web.haibo.com.cn/biguo/image/js/ |
| Current File : /home/zqegovsj/www/us3web.haibo.com.cn/biguo/image/js/xmltree.js |
/* JavaScript Document */
/*
xmlTree v1.2
=================================
Infomation
----------------------
Author : Lapuasi
E-Mail : lapuasi@gmail.com
WebSite : http://www.lapuasi.com/javascript
DateTime : 2005-12-25
Example
----------------------
var tree = new xmlTree('tree'); //��ɶ���
tree.typeid = 1; //���ó�ʼģʽ��Ĭ��ȫ���رա�0ȫ���رգ�1ȫ��չ��
tree.createTree(); //���
@params typeid:
1:��ʾͳ����
2:��ʾͳ�ƹ�Ӧ
3:��ʾͳ�ƹ�˾��
4:��ʾͳ��Product��
@params mode:
for Internet Explorer, Mozilla Firefox
*/
function xmlTree(name,xmlfile,typeid) {
this.use_static_html = false;
this.name = name; //ʵ�����
if(xmlfile == null)
this.xmlFile = './$_SESSION['MemberName']/xml/industry_list.xml'; //Ĭ��xml�ļ�
else this.xmlFile = xmlfile;
this.mode = 1;//չ��ģʽ ,1һ����ʾ����,2ֻ��ʾһ����
this.typeid = typeid; //��ʼģʽ��Ĭ��ȫ���رա�0ȫ���رգ�1ȫ��չ��
this.html = ''; //������htmlcode
this.prevTip = null; //��һ�α���ʾ��tip��Time��� (�ڲ�ʹ��)
this.prevSelected = null; //��һ�α�ѡ�еĽڵ���Զ���� (�ڲ�ʹ��)
}
xmlTree.prototype.createXMLDOM = function() { //���XMLDOM����
var xmldom;
if (window.ActiveXObject){
var xmldom = new ActiveXObject("Microsoft.XMLDOM");
} else {
if (document.implementation && document.implementation.createDocument) {
var xmldom = document.implementation.createDocument("","doc",null);
}
}
xmldom.async = false;
xmldom.resolveExternals = false;
xmldom.validateOnParse = false;
xmldom.preserveWhiteSpace = true;
return xmldom;
}
xmlTree.prototype.createTree = function() { //��ɲ�Print
var xmldom = this.createXMLDOM();
document.write('<div class="tree"><\/div>'); // ���ò�
if (xmldom.load(this.xmlFile)) {
this.createNodes(xmldom);
} else {
this.html = 'Load XML Error';
}
document.getElementById('tree').innerHTML = this.html;
return;
}
xmlTree.prototype.getFirstChildData = function(obj, name) { //ȡ��ָ����ƽڵ�ĵ�һ���ӽڵ�����
var result = '';
if (typeof(obj) == 'object' && name != null && name != '') {
var node = obj.getElementsByTagName(name);
if (node != null && node.length > 0) {
result = node[0].firstChild.data;
}
}
return result;
}
xmlTree.prototype.checkChildNodes = function(obj, id) { //���yes no�з�֧
var result = false;
var nodes = obj.getElementsByTagName('node');
if (nodes != null && nodes.length > 0) {
//var pid;
for (var i = 0; i < nodes.length; i++) {
//pid = nodes[i].getAttribute('parentid');
if (nodes[i].getAttribute('parentid') == id) {
result = true;
break;
}
}
}
return result;
}
xmlTree.prototype.createNodes = function(obj, id) { //���ָ����Žڵ���
if (typeof(id) == 'undefined') id = null; //��û��id������Ϊ���ڵ�
var nodes = obj.getElementsByTagName('node');
if (nodes != null && nodes.length > 0) {
//var modeClass, modeSrc, iconClass, iconSrc;
var nid, npid, nname, nicon, nlink, ntarget, nexplain, hasChildNodes;
var amount;
var xmlWidth=188;
switch ((this.typeid))
{
case 1:counttype='buy';break;
case 2:counttype='sell';break;
case 3:counttype='company';break;
case 4:counttype='product';break;
case 5:counttype='news';break;
default:counttype='buy';break;
}
//�ж�ģʽ���ͣ���Ӧ���ʽ
if (id == null) modeClass = 'open'; //��Ϊ���ڵ�����ʾ
//this.html += '<ul id="tree_' + id + '_c" class="' + modeClass + '">';
this.html += '<table width='+xmlWidth+' border=0><tr>';
var pcount = nodes.length;
var currentp = 0;//��ǰ��
for (var i = 0; i<pcount; i++) {
npid = nodes[i].getAttribute('parentid');
amount = nodes[i].getAttribute(counttype+'_amount');
if (npid == id) {
//��ʼ��
currentp++;
//ȡ�ýڵ��Ų����
nid = nodes[i].getAttribute('id');
//this.html += '<li id="tree_' + nid + '"><span>';
//ȡ�ýڵ��Զ���ͼ��
//�ж�yes no�����ӽڵ㣬��ȷ����ͷ��ͼ���picture���ʽ
hasChildNodes = this.checkChildNodes(obj, nid);
/**
* ��̬ҳ��ʱ����
*/
if(this.static_html_level>0){
nlink = '../htmls/'+counttype+'/list/'+nid+'/'+nid+'_1.html';
}else{
//ȡ�ýڵ���
nlink = './list.php?sid='+nid;
}
if (nlink != '') {
nlink = ' href="' + nlink + '"';
} else {
nlink = ' href="javascript:;"';
}
//ȡ�ýڵ����
nname = this.getFirstChildData(nodes[i], 'name');
if(npid ==null){
this.html += '<td width=100% align="left"><img alt="" src="/images/dot2.gif" width="3" height="5"></td><td><a class="font14blak" id="tree_' + nid + '_l"' + nlink + ' title="'+ nname + '">' + nname + '</a><span class="time">' + '(' + amount + ')</span>';
}else{
this.html += '<a id="tree_' + nid + '_l"' + nlink + ' title="'+ nname + '">' + nname + '</a>' + '|';
}
//this.html+=i;
//this.html += '<a id="tree_' + nid + '_l"' + nlink + '>' + nname +'<\/a>' + '(' + amount + ')<\/span>';
if (hasChildNodes) {
//this.htm += '</tr><tr>';
this.html += '<br>';
this.createNodes(obj, nid); //�����ӽڵ�
this.html += '</td>';
if(this.mode==1){
if (currentp%2==0)
{
this.html += '</tr>';
}
}else{
this.html += '</tr>';
}
}else{
if(npid==null){
this.html += '</td>';
if(this.mode==1){
if (currentp%2==0)
{
this.html += '</tr>';
}
}else{
this.html += '</tr>';
}
}
}
}
if(i==pcount-1) this.html += '</table>';
}
}
return;
}