javascript实现语法分色编辑器...(同时支持动态读取对象方法)[3]

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 yanwl 的 blog

    //基本object方法
    putmethods(methodlist, obj,"constructor,hasownproperty,isprototypeof,propertyisenumerable,tolocalestring,tostring,valueof");
    
    //基本array方法
    putmethods(methodlist, obj,"concat,join,length,pop,push,reverse,shift,slice,sort,splice,unshift");     

    //基本date方法
    putmethods(methodlist,obj,"getdate,getutcdate,getday,getutcday,getfullyear,getutcfullyear,gethours,getutchours,getmilliseconds,getutcmilliseconds,getminutes,getutcminutes,getmonth,getutcmonth,getseconds,getutcseconds,gettime,gettimezoneoffset,getyear");

    putmethods(methodlist,obj,"setdate,setutcdate,setfullyear,setutcfullyear,sethours,setutchours,setmilliseconds,setutcmilliseconds,setminutes,setutcminutes,setmonth,setutcmonth,setseconds,setutcseconds,settime,setyear,todatestring,togmtstring,tolocaledatestring,tolocaletimestring,tostring,totimestring,toutcstring,valueof,parse,utc");

    //基本math方法
    putmethods(methodlist,obj,"e,ln10,ln2,log10e,log2e,pi,sqrt1_2,sqrt2");
    putmethods(methodlist,obj,"abs,acos,asin,atan,atan2,ceil,cos,exp,floor,log,max,min,pow,random,round,sin,sqrt,tan");

    //基本function方法
    putmethods(methodlist,obj,"arguments,caller,length,prototype,apply,call,tostring");
    
    //基本number方法
    putmethods(methodlist,obj,"max_value,min_value,nan,negative_infinity,positive_infinity");
    putmethods(methodlist,obj,"tostring,tolocalstring,tofixed,toexponential,toprecision");

    //基本regexp方法
    putmethods(methodlist,obj,"global,ignorecase,lastindex,multiline,source,exec,test");

    //基本string方法
    putmethods(methodlist,obj,"charat,charcodeat,contact,indexof,lastindexof,match,replace,search,slice,split,substring,substr,tolowercase,tostring,touppercase,valueof,fromcharcode");
    putmethods(methodlist,obj,"anchor,big,blink,bold,fixed,fontcolor,fontsize,italics,link,small,strike,sub,sup");

   }
   for (each in obj)
   {
    methodlist.pushdistinct(each);
   }
   methodlist.sort();

   if (methodlist.length > 0)
   {
    methods.options.length = 0;
    for (var i = 0; i < methodlist.length; i++)
    {
     methods.options.add(new option(methodlist[i])); 
    }
    if (methods.options.length > 10)
    {
     methods.size = 10;
    }
    else
    {
     methods.size = methods.options.length;
    }
    methods.style.top = osel.offsettop;
    methods.style.left = osel.offsetleft;
    methods.style.display = "";
    methods.options[0].selected = true;
    methods.focus();
   }
  }
  catch(e){}
}

function selectmethod()
{
 var src = event.srcelement;
 if(event.keycode == 13)
 {
  selmethod(src);
 }

 if(event.keycode == 27 || event.keycode == 8 || event.keycode == 32)
 {
  src.style.display = "none";
  editbox.focus();
 }
}

function selmethod(src)
{
 clipboarddata.setdata('text',src.options[src.selectedindex].text);
 editbox.focus();
 editbox.document.execcommand('paste');
 src.style.display = "none";
 getcursorposition();
}
function getpos(text) //计算行数、列数
{
 var rows = 1;
 var cols = 1;
 var idx = 0;
 var subtext = text;
 while((idx = subtext.indexof("\n")) != -1)
 {
  subtext = subtext.substring(idx + 1);
  rows++;
 }
 return new array(rows, subtext.length + 1);
}
function getnullrows(src,osel) //计算空行
{
 var rows = 0;

 var offsetend = src.document.selection.createrange();

本文关键:javascript实现语法分色编辑器...(同时支持动态读取对象方法)
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top