仿DW8代码折叠的HTML编辑器

王朝html/css/js·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

测试版(仅支持ie5.5+,且一个页面里只能放一个)

收集意见

功能:

1.动态分析,智能折叠,ctrl+Enter强制重建

2.tab键输出两个空格(若选区为多行,各行前加入两空格,同时按shift键反之),Ctrl+T替换\t为俩空格

3.回车自动缩进

4.Ctrl+W预览

限制:

1.取消了右键菜单(复制剪切粘贴可使用键盘)

2.暂不支持文本拖放

3.Ctrl+Z将撤销所有操作

4.块起止测试并不严格,且未考虑vbscript

5.运行效率有待改进

<style>

body{

text-align:center;

}

#oTxt,#oBox{

height:440px;

border:none;

border:1px solid #666666;

}

#oTxt{

width:740px;

color:#333333;

background-color:#f0f0f0;

font-family:verdana;

font-size:11px;

line-height:13px;

margin-left:16px;

overflow:auto;

border-left:none;

scrollbar-arrow-color:#666666;

scrollbar-base-color:#666666;

scrollbar-darkshadow-color:#f0f0f0;

scrollbar-face-color:#f0f0f0;

}

#oBox{

position:absolute;

width:15px;

overflow-y:hidden;

background-color:#e0e0e0;

padding-top:1px;

margin-top:1px;

padding-bottom:19px;

border-right:none;

}

</style>

<script>

/*

测试版(仅支持ie5.5+,且一个页面里只能放一个)

收集意见

功能:

1.动态分析,智能折叠,ctrl+Enter强制重建

2.tab键输出两个空格(若选区为多行,各行前加入两空格,同时按shift键反之),Ctrl+T替换\t为俩空格

3.回车自动缩进

4.Ctrl+W预览

限制:

1.取消了右键菜单(复制剪切粘贴可使用键盘)

2.暂不支持文本拖放

3.Ctrl+Z将撤销所有操作

4.块起止测试并不严格,且未考虑vbscript

5.运行效率有待改进

*/

window.onload=function(){

oBox.mLine="http://free.txd.cn/mozart0/img/line.gif";

oBox.mPlus="http://free.txd.cn/mozart0/img/plus.gif";

oBox.mMinus="http://free.txd.cn/mozart0/img/minus.gif";

oBox.mEnd="http://free.txd.cn/mozart0/img/end.gif";

oBox.isPlus=function(o){

return /plus\./.test(o.src);

}

oBox.isMinus=function(o){

return /minus\./.test(o.src);

}

oBox.isLine=function(o){

return /line\./.test(o.src);

}

oBox.isEnd=function(o){

return /end\./.test(o.src);

}

oBox.childrenVisible=function(index){

var t=this.children[index];

while(t.style.display=="none")

t=t.nextSibling;

var x=t.offsetTop/t.height;

while(x<index){

t=t.nextSibling;

if(t.style.display!="none")

x++;

}

return t;

}

oBox.hideBlock=function(index){

var n=1,x=1;

var c=this.children;

c[index].src=this.mPlus;

while(++index<c.length&&n){

var t=c[index];

if(t.style.display!="none"){

x++;

t.style.display="none";

}

if(this.isEnd(t))

n--;

else if(!this.isLine(t))

n++;

}

return x;

}

oBox.showBlock=function(index,b){

var index0=index,c=oBox.children;

c[index].src=b?this.mMinus:this.mPlus;

c[index].style.display="block";

index++;

if(b)

while(index<c.length){

var t=c[index];

if(this.isLine(t)){

t.style.display="block";

index++;

}

else if(this.isEnd(t)){

t.style.display="block";

break;

}

else

index+=this.showBlock(index,this.isMinus(t))

}

else{

var n=1;

while(index<c.length){

var t=c[index];

t.style.display=="none";

if(this.isEnd(t)){

if(--n==0)

break;

}

else if(!this.isLine(t))

n++;

index++;

}

}

return index-index0+1;

}

oBox.refresh=function(o,str){

o.src=this.judge(str);

o.storeText=str;

}

oBox.judge=function(s){

var l=/\{/.test(s),r=/\}/.test(s);

if(l&&!r)

return this.mMinus;

if(!l&&r)

return this.mEnd;

s=s.replace(/<(\w+).*<\/\1>/g,"<$1/>");

l=/^\s*<\w+[^\/]+[>\r]/.test(s);

r=/\/>/.test(s);

if(l&&!r)

return this.mMinus;

r=/<\/\w+>/.test(s);

if(r)

return this.mEnd;

return this.mLine;

}

oBox.onclick=function(){

var o=event.srcElement;

if(o==this)

return;

var vIndex=(o.offsetTop-1)/oTxt.lineHeight;

var index=vIndex;

var t=this.children[vIndex];

while(t!=o){

t=t.nextSibling;

index++;

}

if(this.isMinus(o))

oTxt.hideLines(vIndex,this.hideBlock(index));

else if(this.isPlus(o))

oTxt.showLines(vIndex,this.showBlock(index,true));

oBox.scrollTop=oTxt.scrollTop;

}

oTxt.lineHeight=13;

oTxt.strSpecial="......";

oTxt.regSpecial=/\.{6}\r?$/;

oTxt.strTab=" ";

oTxt.bFixed=false;

oTxt.originalValue=oTxt.value;

oTxt.trueValue=function(){

for(var s="",c=oBox.children,i=0;i<c.length-1;i++)

s+=c[i].storeText+"\n";

return s+c[i].storeText;

}

oTxt.lineNumber=function(r){

var t=this.createTextRange();

return Math.round((r.boundingTop-t.boundingTop)/this.lineHeight);

}

oTxt.rngAtHome=function(r){

var t=this.createTextRange();

return r.boundingLeft==t.boundingLeft&&r.boundingTop==t.boundingTop;

}

oTxt.rngAtEnd=function(r){

var t=this.createTextRange();

t.collapse(false);

return r.boundingLeft==t.boundingLeft&&r.boundingTop==t.boundingTop;

}

oTxt.hideLines=function(ifrom,n){

var a=this.value.match(/.+/mg);

for(var i=1;i<n;i++)

a[ifrom+i]="";

a[ifrom]=a[ifrom].replace(/\r/,this.strSpecial);

if(ifrom+n<a.length)

a[ifrom]+="\r";

this.value=a.join("");

}

oTxt.showLines=function(ifrom,n){

var a=this.value.match(/.+/mg);

var t=oBox.childrenVisible(ifrom).nextSibling;

for(var s="",i=0;t&&i<n-1;i++,t=t.nextSibling)

if(t.style.display!="none"){

if(!oBox.isPlus(t))

s+=t.storeText;

else

s+=t.storeText.replace(/\r?$/,this.strSpecial+"\r");

}

a[ifrom]=a[ifrom].replace(this.regSpecial,"\r"+s);

this.value=a.

[1] [2] [3] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航