prototype 实现网络相册的ajax界面。
源代码在线查看: images.js.svn-base
var ui={}; var currPath="/"; var updater=null; window.onload=function(){ ui.title=$('title'); ui.closeup=$('closeup'); ui.closeupImg=$('closeup_img'); ui.folders=$('folders'); ui.images=$('images'); Element.hide(ui.closeup,ui.folders); load(); } function load(newPath){ if (newPath!=null){ currPath=newPath; } if (updater){ updater.stop(); } updater=new Ajax.PeriodicalUpdater( "images", "images.php?path="+currPath, { method: "GET", evalScripts: true, frequency: 10, onComplete: function(){ Element.hide(ui.closeup); } } ); } function showBreadcrumbs(){ var crumbs=currPath.split("/"); var crumbHTML=" > home"; for(var i=0;i var crumb=crumbs[i]; if (crumb.length>0){ var path=subpath(currPath,"/",i); crumbHTML+=" > "+crumb+""; } } ui.title.innerHTML=crumbHTML; } function subpath(str,delim,ix){ var all=str.split(delim); var some=all.findAll( function(v,i){ //alert("i="+i+", ix="+ix+", v="+v+", result: "+(i return (i } ); return some.join(delim); } function showFolders(folders){ if (folders.length==0){ Element.hide(ui.folders); }else{ var folderHTML=""; for (var i=0;i var folder=folders[i]; var path=(currPath=="/") ? "/"+folder : [currPath,folder].join("/"); folderHTML+=""+folder+""; } Element.show(ui.folders); ui.folders.innerHTML=folderHTML; } } function showCloseup(imgSrc){ Element.hide(ui.images); Element.show(ui.closeup); ui.closeupImg.src=imgSrc; }