pixmicat - Rev 311

Subversion Repositories:
Rev:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-tw">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="zh-tw" />
<title>pmc_ajax2</title>
<style type="text/css">
.block { float: left; border: 2px outset; width: 99%; height: auto; margin: 3px; padding: 1px; overflow:auto;}
.resblock { background-color: #CCC; width: auto; height: auto; margin: 3px 3px 3px 1.5em; padding: 1px; overflow:auto;}
.view { float: right; text-decoration: none; }
.tooltip { background-color: #ffa; border: 1px outset; padding: 0 0.5em; visibility:hidden; position: absolute; left: 0; top: 0; white-space: nowrap; }
.checked { background-color: red; }
.cb { display:none; }
</style>
<script type="text/javascript">
// <![CDATA[
/* 建立XMLHttpRequest物件 */
function CreateXMLHttp(){
        var objxml = false;
        /*@cc_on @*/
        /*@if (@_jscript_version >= 5)
        try{
                objxml = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
                try{
                        objxml = new ActiveXObject("Microsoft.XMLHTTP");
                }catch(e2){ objxml = false; }
        }
        @end @*/
        if(!objxml && typeof XMLHttpRequest!='undefined') {
                objxml = new XMLHttpRequest();
                if(objxml.overrideMimeType) objxml.overrideMimeType('text/xml');
        }
        return objxml;
}

function CreateDivBlock(no,imgt,imgext,name,email,subject,time,comment,res){
        return '<div class="block">'+
((hashlink().charAt(0)=='p')?'<a class="view" onclick="getXML(\'r'+no+'\')" href="#r'+no+'">res</a>':'<a class="view" onclick="getXML(\'p1\')" href="#p1">back</a>')+
subject+' Name:'+((email!=" ")?'<a href="mailto:'+email+'">'+name+'</a>':name)+' ['+time+'] '+'No.'+no+'<br />'+
((imgext!="?")?'<a href="'+imgbase+imgt+imgext+'" target="_blank"><img src="'+thumbbase+imgt+'s.jpg" alt="'+imgt+imgext+'" border="0" /></a>':'')+
comment+res+'</div>\n';
}
function CreateResDivBlock(no,imgt,imgext,name,email,subject,time,comment){
        return '<div class="resblock">'+
subject+' Name:'+((email!=" ")?'<a href="mailto:'+email+'">'+name+'</a>':name)+' ['+time+'] '+'No.'+no+'<br />'+
((imgext!="?")?'<a href="'+imgbase+imgt+imgext+'" target="_blank"><img src="'+thumbbase+imgt+'s.jpg" alt="'+imgt+imgext+'" border="0" /></a>':'')+
comment+'</div>\n';
}

function hashlink(){
        var arr = location.href.split(/#/);
        if(arr[1]){
                if(arr[1].match(/([r|p][0-9]+)/)){
                        return arr[1];
                }else return 'p1';
        }else return 'p1';
}

function resize(obj){
        var ratio=250/Math.max(obj.width,obj.height);
        obj.width*=ratio;
//      obj.height*=ratio;
}

// ]]>
</script></head><body onload="getXML(hashlink())">
<div id="ajContent"></div>
<hr style="clear: both;" />
換頁列:<div id="pages"></div><br />
<div id="ajTimer"></div>
<div id="tooltip" class="tooltip"></div>
<script type="text/javascript">
// <![CDATA[
var tt = document.getElementById("tooltip"); // 進階資訊
var ajc = document.getElementById("ajContent"); // 主要介面
var pg = document.getElementById("pages"); // 換頁列
var runtime = document.getElementById("ajTimer"); // 執行時間
var ie=document.all;
var xhttp = CreateXMLHttp();
var timer1, timer2, page, page_max, thumbbase, imgbase, curX, curY, cltX, cltY;

/* 取得列表 */
function getXML(int_page){
        timer1 = new Date();
        if(xhttp){
                if(int_page==null||int_page.charAt(0)=='p') {
                        page = (int_page==null) ? 1 : int_page.replace('p','');
                        xhttp.open('GET','pmc_ajax2.php?mode=list&page='+page, true);
                }else{
                        var res = (int_page==null) ? 1 : int_page.replace('r','');
                        xhttp.open('GET','pmc_ajax2.php?mode=list&no='+res, true);
                }
                xhttp.onreadystatechange = readXML;
                xhttp.send(null);
        }
}
function readXML(){
        if(xhttp.readyState==4){ // 讀取完成
                var returnXML = xhttp.responseXML;
                var pagebar = '', page_link = '', result = '';
                var status = returnXML.getElementsByTagName('status').item(0).firstChild.nodeValue;
                if(status!="+OK"){ ajc.innerHTML = "ERROR"; return false; }

                page_max = returnXML.getElementsByTagName('pages').item(0).firstChild.nodeValue;
                if(!imgbase) imgbase = returnXML.getElementsByTagName('imgbase').item(0).firstChild.nodeValue;
                if(!thumbbase) thumbbase = returnXML.getElementsByTagName('thumbbase').item(0).firstChild.nodeValue;

                var item_list = returnXML.getElementsByTagName('item');
                var arycount = item_list.length;
                for(i = 0; i < arycount; i++){
                        var no = item_list[i].getAttribute('id');
                        var imgt = item_list[i].getElementsByTagName('imgt')[0].firstChild.nodeValue;
                        var imgext = item_list[i].getElementsByTagName('imgext')[0].firstChild.nodeValue;
                        var name = item_list[i].getElementsByTagName('name')[0].firstChild.nodeValue;
                        var email = item_list[i].getElementsByTagName('email')[0].firstChild.nodeValue;
                        var subject = item_list[i].getElementsByTagName('subject')[0].firstChild.nodeValue;
                        var time = item_list[i].getElementsByTagName('time')[0].firstChild.nodeValue;
                        var comment = item_list[i].getElementsByTagName('comment')[0].firstChild.nodeValue;

                        var haschild = item_list[i].getElementsByTagName('replies')[0];
                        var res='';
                        if(haschild) {
                                var res_list = item_list[i].getElementsByTagName('replies')[0].getElementsByTagName('item');
                                rescount = res_list.length;
                                for(var j = 0; j < rescount; j++) {
                                        var r_no = res_list[j].getAttribute('id');
                                        var r_imgt = res_list[j].getElementsByTagName('imgt')[0].firstChild.nodeValue;
                                        var r_imgext = res_list[j].getElementsByTagName('imgext')[0].firstChild.nodeValue;
                                        var r_name = res_list[j].getElementsByTagName('name')[0].firstChild.nodeValue;
                                        var r_email = res_list[j].getElementsByTagName('email')[0].firstChild.nodeValue;
                                        var r_subject = res_list[j].getElementsByTagName('subject')[0].firstChild.nodeValue;
                                        var r_time = res_list[j].getElementsByTagName('time')[0].firstChild.nodeValue;
                                        var r_comment = res_list[j].getElementsByTagName('comment')[0].firstChild.nodeValue;
                                        res+=CreateResDivBlock(r_no, r_imgt, r_imgext, r_name, r_email, r_subject, r_time, r_comment);
                                }
                        }
                        result += CreateDivBlock(no, imgt, imgext, name, email, subject, time, comment,res);
                        if(hashlink().charAt(0)=='r') break;

                }
                ajc.innerHTML = result;

                page = (!page) ? 1 : page; // 目前所在頁數
                for(i = 1; i <= page_max; i++){
                        page_link = '<a href="#p'+i+'" onclick="getXML(\'p'+i+'\')">['+i+']</a> '; // 正常換頁連結
                        if(page==i) page_link = '<b>['+page+']</b> '; // 本頁
                        if(page != 1 && i == 1) page_link = '<a href="#p'+(page-1)+'"  onclick="getXML(\'p'+(page-1)+'\')">&lt;&lt;</a> ' + page_link; // <<
                        if(page != page_max && i == page_max) page_link += '<a href="#p'+(page+1)+'" onclick="getXML(\'p'+(page+1)+'\')">&gt;&gt;</a> '; // >>
                        pagebar += page_link;
                }
                pg.innerHTML = pagebar;
                timer2 = new Date();
                runtime.innerHTML = timer2.getTime() - timer1.getTime()+" ms";
        }
}

// ]]>
</script>
</body></html>