脚本吧 - 幻宇工作室用到js,超强推荐base.js


Posted in Javascript onDecember 23, 2006

base.js

browser_init() 
function browser_init(){ 
    window.isIE=navigator.appName.indexOf("Microsoft")==0 
    window.$sys={} 
    window.$my={} 
    String.prototype.trim=function(){return this.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(){return this.replace(/[^\x00-\xff]/g,"**").length} 
    String.prototype.leftB=function(len,isOmit){var s;s=this.replace(/\*/g," ").replace(/[^\x00-\xff]/g,"**");if(s.length>len&&isOmit){len-=3};return this.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,";"))return 1;var a=this.match(new RegExp("(^|;)"+str+":[^;]*"));return a==null||str==""?(def==null?"":def):a[0].replace(";","").slice(str.length+1)} 
    String.prototype._slice="".slice 
    String.prototype.slice=function(n1,n2){var v,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)+")")}return v} 
    Array.prototype.parseInt=function(){var i,count=this.length;for(i=0;i<count;i++){this[i]=parseInt(this[i])}} 
    Array.prototype.remove=function(item){var i,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(var i=0;i<this.length;i++){if(this[i]==item){return}}this.push(item)} 
    window.$=function(obj){return typeof(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(){return true}     $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)return false;do if(node==this){return true}while(node=node.parentNode){return false}} 
        HTMLElement.prototype.__defineSetter__("outerHTML",function(sHTML){var r=this.ownerDocument.createRange();r.setStartBefore(this);var df=r.createContextualFragment(sHTML);this.parentNode.replaceChild(df,this);return sHTML;}) 
        HTMLElement.prototype.__defineGetter__("innerText",function(){var r = this.ownerDocument.createRange();r.selectNodeContents(this);return r.toString()}) 
        Event.prototype.__defineGetter__("srcElement",function(){var node=this.target;while(node.nodeType!=1){node=node.parentNode}return node}) 
        Event.prototype.__defineGetter__("fromElement",function(){return this.relatedTarget}) 
        Event.prototype.__defineGetter__("toElement",function(){return this.relatedTarget}) 
        Event.prototype.__defineGetter__("offsetX",function(){return this.layerX}) 
        Event.prototype.__defineGetter__("offsetY",function(){return this.layerY}) 
    } 
    drag_init() 
    thd_init() 
    document_onload() 
} 
function document_onload(){ 
    var l 
    l="<div id=mcSystem style='position:absolute;left:-9000px;top:0'>" 
    l+="<iframe id=wForm name=wForm onload=fmWinOnLoad(this)></iframe>" 
    l+="<button id=btSysFocu></button>" 
    l+="</div>" 
    insHtm(document.body,l) 
    document.body.onmouseover=document.body.onmouseout=document.body.onmousedown=document.body.onmouseup=function(e){ 
        var ee 
        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){ 
        var ee 
        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() 
} 
function drag_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){ 
        var x,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" 
    } 
} 
function thd_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(){ 
        var ol=$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){ 
    var o,x=0 
    op=op||document.body 
    do{ 
        o=o==null?$(obj):o.parentNode 
        if(op==o) 
            break 
        x+=o.offsetLeft 
    }while(op.contains(o)) 
    return x 
} 
function $y(obj,op){ 
    var o,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)) 
    return y 
} 
function getPngBg(url){ 
    return document.all&&/\.png/i.test(url)?"filter:progid:dximagetransform.microsoft.alphaimageloader(src="+url+",sizingMethod=scale)":"background:url("+url+")" 
} 
function setHtm(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) 
} 
function insHtm(op,str,oRefer){ 
    var bx=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) 
} 
function btBinding(op){ 
    var ol,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="<img src='"+bg+"'><button style=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} 
    } 
} 
function fmBinding(op){ 
    var ol,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],"<input name=btSubmit type=submit style=visibility:hidden>",ol[i].firstChild) 
        ol[i].onkeydown=function(e){ 
            e=e||event 
            if(e.keyCode==13) 
                return false 
        } 
        ol[i].onsubmit=function(e){ 
            var fm=this 
            if(!fmCheck(fm)) 
                return false 
            sResult=1 
            try{ 
                foo=fm.getAttribute("onbeforeload") 
                if(typeof(foo)=="function") 
                    sResult=foo() 
                else if(typeof(foo)=="string") 
                    eval(foo.replace(/return /,"sResult=")) 
            }catch(e){alert(e.description)} 
            if(sResult==false) 
                return false 
            if(fm.method=="post"){ 
                fm.target="wForm" 
                $sys.fmWinType=fm 
                return true 
            } 
            loadXml(fmv(fm),function(xml){ 
                var foo=fm.getAttribute("onload") 
                if(typeof(foo)=="function") 
                    foo(xml) 
                else if(typeof(foo)=="string") 
                    eval(foo) 
            }) 
            return false 
        } 
    } 
} 
function fmWinOnLoad(win){ 
    var xml,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) 
        return alert(error) 
    foo=$sys.fmWinType.onload 
    if(typeof(foo)=="function") 
        foo(xml) 
    else if(typeof(foo)=="string") 
        eval(foo) 
} 
function fmv(fm){ 
    var i,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("&","?") 
    return l 
} 
function createXml(str){ 
    if(isIE){ 
        var xml=new ActiveXObject("Microsoft.XMLDOM") 
            xml.loadXML(str) 
        xml.setProperty("SelectionLanguage","XPath") 
    } 
    else 
        var xml=new DOMParser().parseFromString(str,"text/xml") 
    return xml.documentElement 
} 
function getXmlNode(node,expr,isAll){ 
    var ol 
    if(isIE) 
        ol=node.selectNodes(expr) 
    else{ 
        var xpe=new XPathEvaluator(),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) 
        } 
    } 
    return isAll?ol:ol[0] 
} 
function ndv(node,expr,def){ 
    var ol,s,$0,r 
    if(expr.indexOf("@")==0) 
        return node.getAttribute(expr.slice(1))||def 
    ol=getXmlNode(node,unescape(expr.slice(0,"?"))) 
    if(ol==null) 
        return 
    if(ol.length==0) 
        return def 
    r=$0=ol.length==0?def:unescape(ol.text) 
    return r 
} 
function loadXml(url,foo){ 
    var xh,method,ondataok 
    xh=isIE?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest() 
    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(){ 
        var xml=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() 
    } 
}
Javascript 相关文章推荐
限制复选框的最大可选数
Jul 01 Javascript
共享自己写一个框架DreamScript
Jan 20 Javascript
jquery设置按钮停顿3秒不可用
Mar 07 Javascript
AngularJS初始化过程分析(引导程序)
Dec 06 Javascript
jQuery动态效果显示人物结构关系图的方法
May 07 Javascript
浅析在javascript中创建对象的各种模式
May 06 Javascript
基于jQuery倒计时插件实现团购秒杀效果
May 13 Javascript
Javascript中for循环语句的几种写法总结对比
Jan 23 Javascript
angular-tree-component的使用详解
Jul 30 Javascript
vue2.0+vue-router构建一个简单的列表页的示例代码
Feb 13 Javascript
layui 图片上传+表单提交+ Spring MVC的实例
Sep 21 Javascript
Vue双向数据绑定(MVVM)的原理
Oct 03 Javascript
实现复选框全选/全不选切换
Dec 23 #Javascript
Javascript实例教程(19) 使用HoTMetal(7)
Dec 23 #Javascript
Javascript实例教程(19) 使用HoTMetal(6)
Dec 23 #Javascript
Javascript实例教程(19) 使用HoTMetal(5)
Dec 23 #Javascript
Javascript实例教程(19) 使用HoTMetal(4)
Dec 23 #Javascript
Javascript实例教程(19) 使用HoTMetal(3)
Dec 23 #Javascript
Javascript实例教程(19) 使用HoTMetal(2)
Dec 23 #Javascript
You might like
PHP通过正则表达式下载图片到本地的实现代码
2011/09/19 PHP
PHP在引号前面添加反斜杠(PHP去除反斜杠)
2013/09/28 PHP
php获取文件类型和文件信息的方法
2015/07/10 PHP
php实现的网页版剪刀石头布游戏示例
2016/11/25 PHP
PHP实现可添加水印与生成缩略图的图片处理工具类
2018/01/16 PHP
yii2 上传图片的示例代码
2018/11/02 PHP
JS option location 页面跳转实现代码
2008/12/27 Javascript
JavaScript 基于原型的对象(创建、调用)
2009/10/16 Javascript
EasyUI 中 MenuButton 的使用方法
2012/07/14 Javascript
jquery使用append(content)方法注意事项分享
2014/01/06 Javascript
轻松创建nodejs服务器(4):路由
2014/12/18 NodeJs
浅谈$(document)和$(window)的区别
2015/07/15 Javascript
jQuery实现鼠标经过弹出提示信息的地图热点效果
2015/08/07 Javascript
JavaScript中的call方法和apply方法使用对比
2015/08/12 Javascript
JavaScript使用delete删除数组元素用法示例【数组长度不变】
2017/01/17 Javascript
详解React 16 中的异常处理
2017/07/28 Javascript
node.js的exports、module.exports与ES6的export、export default深入详解
2017/10/26 Javascript
js与jquery获取input输入框中的值实例讲解
2020/02/27 jQuery
vue同个按钮控制展开和折叠同个事件操作
2020/07/29 Javascript
JavaScript的一些小技巧分享
2021/01/06 Javascript
[46:49]完美世界DOTA2联赛PWL S3 access vs Rebirth 第二场 12.19
2020/12/24 DOTA
从django的中间件直接返回请求的方法
2018/05/30 Python
pandas把所有大于0的数设置为1的方法
2019/01/26 Python
Python字符串处理的8招秘籍(小结)
2019/08/13 Python
Python导入父文件夹中模块并读取当前文件夹内的资源
2020/11/19 Python
python多线程和多进程关系详解
2020/12/14 Python
SKECHERS官方旗舰店:美国舒适运动休闲品牌
2017/12/22 全球购物
Travelstart沙特阿拉伯:廉价航班、豪华酒店和实惠的汽车租赁优惠
2019/04/06 全球购物
节省高达65%的城市景点费用:Go City
2019/07/06 全球购物
关于爱情的广播稿
2014/01/16 职场文书
学风建设演讲稿
2014/09/12 职场文书
大学生暑期社会实践证明范本
2014/10/24 职场文书
失职检讨书大全
2015/01/26 职场文书
就业推荐表院系意见
2015/06/05 职场文书
MySQL pt-slave-restart工具的使用简介
2021/04/07 MySQL
自定义函数实现单词排序并运用于PostgreSQL(实现代码)
2021/04/22 PostgreSQL