base.js
复制代码 代码如下:
browser_init()
functionbrowser_init(){
window.isIE=navigator.appName.indexOf("Microsoft")==0
window.$sys={}
window.$my={}
String.prototype.trim=function(){returnthis.replace(/(^[s]*)|([s]*$)/g,"")}
String.prototype.inc=function(s1,s2){if(s2==null){s2=","};return(s2+this+s2).indexOf(s2+s1+s2)>-1?1:0}
String.prototype.lenB=function(){returnthis.replace(/[^x00-xff]/g,"**").length}
String.prototype.leftB=function(len,isOmit){vars;s=this.replace(/*/g,"").replace(/[^x00-xff]/g,"**");if(s.length>len&&isOmit){len-=3};returnthis.slice(0,s.slice(0,len).replace(/**/g,"").replace(/*/g,"").length)+(s.length>len&&isOmit?"...":"")}
String.prototype.getVar=function(str,def){if(this.inc(str,";"))return1;vara=this.match(newRegExp("(^|;)"+str+":[^;]*"));returna==null||str==""?(def==null?"":def):a[0].replace(";","").slice(str.length+1)}
String.prototype._slice="".slice
String.prototype.slice=function(n1,n2){varv,b1=typeof(n1)=="number",b2=typeof(n2)=="number";if(!b1||typeof(n2)=="string"){v=eval("this._slice("+(b1?n1:this.indexOf(n1)+(n2==null?1:0)+(this.indexOf(n1)==-1?this.length:0))+(n2==null?"":(b2?n2:(this.indexOf(n2)==-1?"":","+this.indexOf(n2))))+")")}else{v=eval("this._slice(n1"+(n2==null?"":","+n2)+")")}returnv}
Array.prototype.parseInt=function(){vari,count=this.length;for(i=0;i<count;i++){this[i]=parseInt(this[i])}}
Array.prototype.remove=function(item){vari,count=this.length;for(i=0;i<count;i++){if(this[i]==item){this.splice(i,1);i--;count--}}}
Array.prototype.plus=function(item){for(vari=0;i<this.length;i++){if(this[i]==item){return}}this.push(item)}
window.$=function(obj){returntypeof(obj)=="string"?document.getElementById(obj):obj}
window.ow=function(win){return$(win).contentWindow}
window.oDel=function(obj){if($(obj)!=null){$(obj).parentNode.removeChild($(obj))}}
window.oHide=function(obj){if($(obj)!=null){$(obj).style.visibility="hidden"}}
window.oShow=function(obj){if($(obj)!=null){$(obj).style.visibility=""}}
window.oFocu=function(obj){window.tempObj=$(obj);window.setTimeout("try{window.tempObj.focus()}catch(e){}",10)}
window.fmCheck=function(){returntrue}
$sys.url=location.href
$sys.path=$sys.url.slice(0,"?").slice(0,$sys.url.lastIndexOf("/")+1)
document.write("<body></body>")
if(document.all){
document.execCommand("BackgroundImageCache",false,true)
}
else{
HTMLElement.prototype.attachEvent=function(type,foo){this.addEventListener(type.slice(2),foo,false)}
HTMLElement.prototype.contains=function(node){if(!node)returnfalse;doif(node==this){returntrue}while(node=node.parentNode){returnfalse}}
HTMLElement.prototype.__defineSetter__("outerHTML",function(sHTML){varr=this.ownerDocument.createRange();r.setStartBefore(this);vardf=r.createContextualFragment(sHTML);this.parentNode.replaceChild(df,this);returnsHTML;})
HTMLElement.prototype.__defineGetter__("innerText",function(){varr=this.ownerDocument.createRange();r.selectNodeContents(this);returnr.toString()})
Event.prototype.__defineGetter__("srcElement",function(){varnode=this.target;while(node.nodeType!=1){node=node.parentNode}returnnode})
Event.prototype.__defineGetter__("fromElement",function(){returnthis.relatedTarget})
Event.prototype.__defineGetter__("toElement",function(){returnthis.relatedTarget})
Event.prototype.__defineGetter__("offsetX",function(){returnthis.layerX})
Event.prototype.__defineGetter__("offsetY",function(){returnthis.layerY})
}
drag_init()
thd_init()
document_onload()
}
functiondocument_onload(){
varl
l="<divid=mcSystemstyle='position:absolute;left:-9000px;top:0'>"
l+="<iframeid=wFormname=wFormonload=fmWinOnLoad(this)></iframe>"
l+="<buttonid=btSysFocu></button>"
l+="</div>"
insHtm(document.body,l)
document.body.onmouseover=document.body.onmouseout=document.body.onmousedown=document.body.onmouseup=function(e){
varee
e=e||event
ee=e.srcElement
if(e.type=="mouseover"&&(ee.tagName=="A"||ee.tagName=="INPUT"||ee.tagName=="LABEL")&&!ee.hideFocus)
ee.hideFocus=true
}
document.body.onkeydown=function(e){
varee
e=e||event
ee=e.srcElement
if(ee.tagName=="INPUT"&&e.keyCode==13&&isIE&&ee.form!=null){
if(ee.form.btSubmit!=null)
ee.form.btSubmit.click()
}
}
if(window.body_onload!=null)
body_onload()
}
functiondrag_init(){
window.$drag={}
window.startDrag=function(obj,e){
$drag.obj=$(obj)
$drag.x0=$drag.obj.offsetLeft
$drag.y0=$drag.obj.offsetTop
$drag.sx=e.clientX
$drag.sy=e.clientY
if(document.all)
$drag.obj.setCapture()
}
document.onmouseup=function(){
if($drag.obj==null)
return
if(document.all)
$drag.obj.releaseCapture()
$drag.obj=null
}
document.onmousemove=function(e){
varx,y
if($drag.obj==null)
return
e=e||event
x=Math.min(e.clientX-$drag.sx+$drag.x0,document.body.scrollLeft+document.body.clientWidth-$drag.obj.offsetWidth)
y=Math.min(e.clientY-$drag.sy+$drag.y0,document.body.scrollTop+document.body.clientHeight-$drag.obj.offsetHeight)
x=Math.max(x,0)
y=Math.max(y,document.body.scrollTop)
$drag.obj.style.left=x+"px"
$drag.obj.style.top=y+"px"
}
}
functionthd_init(){
window.$thd={}
$thd.items=[]
$thd.index=0
$thd.push=function(foo,interval){
foo.interval=interval==null?1:interval
$thd.items.push(foo)
}
$thd.remove=function(foo){
$thd.items.remove(foo)
}
$thd.run=function(){
varol=$thd.items,i
for(i=0;i<ol.length;i++){
if($thd.index%ol[i].interval==0||ol[i].start==null){
ol[i].start=1
ol[i]()
}
}
$thd.index++
window.setTimeout("$thd.run()",10)
}
$thd.run()
}
function$x(obj,op){
varo,x=0
op=op||document.body
do{
o=o==null?$(obj):o.parentNode
if(op==o)
break
x+=o.offsetLeft
}while(op.contains(o))
returnx
}
function$y(obj,op){
varo,y=0
op=op||document.body
do{
o=o==null?$(obj):o.parentNode
if(op==o)
break
if(o.tagName=="TR")
continue
y+=o.offsetTop-o.scrollTop
}while(op.contains(o))
returny
}
functiongetPngBg(url){
returndocument.all&&/.png/i.test(url)?"filter:progid:dximagetransform.microsoft.alphaimageloader(src="+url+",sizingMethod=scale)":"background:url("+url+")"
}
functionsetHtm(op,str){
op=$(op)
if(op.tagName=="TABLE"){
if(op.tBodies.length==0)
op.appendChild(document.createElement("tbody"))
op.replaceChild(document.createElement("tbody"),op.tBodies[0])
}
else
op.innerHTML=""
insHtm(op,str)
}
functioninsHtm(op,str,oRefer){
varbx=document.createElement("div"),ol,i
op=$(op)
if(op.tagName=="TABLE"){
bx.innerHTML="<table>"+str+"</table>"
ol=bx.childNodes[0].tBodies[0].rows
if(op.tBodies.length==0)
op.appendChild(document.createElement("tbody"))
while(ol.length>0){
op.tBodies[0].insertBefore(ol[0],oRefer==null?null:oRefer)
}
}
else{
op.insertBefore(bx,oRefer==null?null:oRefer)
bx.outerHTML=str
}
btBinding(op)
fmBinding(op)
}
functionbtBinding(op){
varol,i,a,bg
ol=(op||document.body).getElementsByTagName("SPAN")
for(i=0;i<ol.length;i++){
if(ol[i].getAttribute("type")!="button"||ol[i].getAttribute("bg")==null)
continue
bg=ol[i].getAttribute("bg")
ol[i].removeAttribute("bg")
a=ol[i].getAttribute("pos").split(",")
ol[i].style.cssText="position:absolute;overflow:hidden;left:"+a[0]+";top:"+a[1]+";width:"+a[2]+";height:"+a[3]
ol[i].innerHTML="<imgsrc='"+bg+"'><buttonstyle=position:absolute;left:-9000;top:0></button>"
ol[i].onmouseover=function(){this.scrollTop=this.offsetHeight}
ol[i].onmouseout=function(){this.scrollTop=0}
ol[i].onmousedown=function(){this.scrollTop=this.offsetHeight*2}
ol[i].onmouseup=function(){this.scrollTop=this.offsetHeight}
}
}
functionfmBinding(op){
varol,i,sResult,foo
ol=(op||document.body).getElementsByTagName("FORM")
for(i=0;i<ol.length;i++){
if(ol[i].onsubmit!=null)
continue
insHtm(ol[i],"<inputname=btSubmittype=submitstyle=visibility:hidden>",ol[i].firstChild)
ol[i].onkeydown=function(e){
e=e||event
if(e.keyCode==13)
returnfalse
}
ol[i].onsubmit=function(e){
varfm=this
if(!fmCheck(fm))
returnfalse
sResult=1
try{
foo=fm.getAttribute("onbeforeload")
if(typeof(foo)=="function")
sResult=foo()
elseif(typeof(foo)=="string")
eval(foo.replace(/return/,"sResult="))
}catch(e){alert(e.description)}
if(sResult==false)
returnfalse
if(fm.method=="post"){
fm.target="wForm"
$sys.fmWinType=fm
returntrue
}
loadXml(fmv(fm),function(xml){
varfoo=fm.getAttribute("onload")
if(typeof(foo)=="function")
foo(xml)
elseif(typeof(foo)=="string")
eval(foo)
})
returnfalse
}
}
}
functionfmWinOnLoad(win){
varxml,str,foo,error
if(document.all){
str=win.contentWindow.document.body.innerText.replace(/n[s]*-/g,"n")
if(str=="")
return
if(!/<[^>]+/.test(str)){
alert(str)
return
}
str=str.slice(1)
xml=createXml(str)
}
else{
if((win.contentWindow.document+"").indexOf("XML")==-1)
return
xml=win.contentWindow.document.documentElement
}
error=ndv(xml,"error")
if(error!=null)
returnalert(error)
foo=$sys.fmWinType.onload
if(typeof(foo)=="function")
foo(xml)
elseif(typeof(foo)=="string")
eval(foo)
}
functionfmv(fm){
vari,f,v,l
l=fm.action
for(i=0;i<fm.length;i++){
if(!"INPUT,TEXTAREA,SELECT".inc(fm[i].tagName)||"submit,button".inc(fm[i].type))
continue
v=fm[i].value.trim()
f=fm[i].getAttribute("postName")||fm[i].name
if(f==""||(fm[i].type=="radio"&&!fm[i].checked)||fm[i].readOnly==true)
continue
if(fm[i].type=="checkbox")
v=fm[i].checked?v.replace(/^on$/g,1):0
l+="&"+f+"="+escape(v)
}
if(l.indexOf("?")==-1)
l=l.replace("&","?")
returnl
}
functioncreateXml(str){
if(isIE){
varxml=newActiveXObject("Microsoft.XMLDOM")
xml.loadXML(str)
xml.setProperty("SelectionLanguage","XPath")
}
else
varxml=newDOMParser().parseFromString(str,"text/xml")
returnxml.documentElement
}
functiongetXmlNode(node,expr,isAll){
varol
if(isIE)
ol=node.selectNodes(expr)
else{
varxpe=newXPathEvaluator(),nsr,res,ol=[],r
nsr=xpe.createNSResolver(node.ownerDocument==null?node.documentElement:node.ownerDocument.documentElement)
res=xpe.evaluate(expr,node,nsr,0,null)
while(r=res.iterateNext()){
r.text=r.textContent
ol.push(r)
}
}
returnisAll?ol:ol[0]
}
functionndv(node,expr,def){
varol,s,$0,r
if(expr.indexOf("@")==0)
returnnode.getAttribute(expr.slice(1))||def
ol=getXmlNode(node,unescape(expr.slice(0,"?")))
if(ol==null)
return
if(ol.length==0)
returndef
r=$0=ol.length==0?def:unescape(ol.text)
returnr
}
functionloadXml(url,foo){
varxh,method,ondataok
xh=isIE?newActiveXObject("Microsoft.XMLHTTP"):newXMLHttpRequest()
method=url.indexOf(".xml")?"GET":"POST"
xh.open(method,url,true)
xh.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
xh.send(method=="POST"?url.slice("?"):null)
ondataok=function(){
varxml=xh.responseXML,error
if(xml!=null)
xml=xh.responseXML.documentElement
if(xml==null){
window.clipboardData.setData("text",$sys.path+url)
alert("载入xml数据出错!")
return
}
error=ndv(xml,"error")
if(error!=null){
alert(error)
return
}
foo(xml)
}
if(xh.readyState==4)
ondataok()
xh.onreadystatechange=function(){
if(xh.readyState==4)
ondataok()
}
}