html/js编辑器

在找JS的POP,PUSH用法的时候,无意中发现的,感觉还不错,收藏一下.
  1 None.gif < html >
  2 None.gif  < head >
  3 None.gif   < title > Silverna Demo Ver  0.01 </ title >
  4 None.gif   < style >
  5 ExpandedBlockStart.gifContractedBlock.gif   div.silverna__ctr__editbox dot.gif {
  6InBlock.gif    margin:0 0 0 0;
  7InBlock.gif    padding:0 0 0 0;
  8InBlock.gif    font:16/18px Arial;
  9InBlock.gif    width:99%;
 10InBlock.gif    height:480px;
 11InBlock.gif    border:1px solid #000000;
 12InBlock.gif    overflow-y:scroll;
 13ExpandedBlockEnd.gif   }

 14 ExpandedBlockStart.gifContractedBlock.gif   p dot.gif {
 15InBlock.gif    margin:0 0 0 0;
 16InBlock.gif    padding:0 0 0 0;
 17ExpandedBlockEnd.gif   }

 18 None.gif   </ style >
 19 None.gif  </ head >
 20 None.gif
 21 None.gif  < body style = " margin:0 0 0 0;padding:0 0 0 0;word-break:break-all;overflow-x:hidden "  onload = " __silverna__ctr__editbox.focus() " >
 22 None.gif  < div id = " __silverna__ctr__editbox "  class = " silverna__ctr__editbox "  contentEditable = " true "  onkeyDown = " return KeyDown() "  onkeyUp = " KeyUp() "  onmouseup = " __silverna__ctr__methods.style.display='none';getCursorPosition(); " >
 23 None.gif  </ div >
 24 None.gif  < select size = " 6 "  style = " display:none;position:absolute "  id = " __silverna__ctr__methods "  onkeyup = " SelectMethod() "  onclick = " SelMethod(this) " >
 25 None.gif  </ body >
 26 None.gif </ html >
 27 None.gif
 28 None.gif
 29 None.gif </ select >
 30 None.gif < script language = JScript >
 31 None.gif function  KeyDown()
 32 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
 33InBlock.gif if(__silverna__ctr__methods.style.display != 'none')
 34ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
 35InBlock.gif  if (event.keyCode == 38 || event.keyCode == 40 || event.keyCode == 13
 36InBlock.gif   || event.keyCode == 33 || event.keyCode == 34
 37ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif{
 38InBlock.gif   __silverna__ctr__methods.focus();
 39ExpandedSubBlockEnd.gif  }

 40InBlock.gif  else
 41InBlock.gif   __silverna__ctr__methods.style.display = 'none';
 42ExpandedSubBlockEnd.gif }

 43InBlock.gif if(event.keyCode == 9
 44ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
 45InBlock.gif  clipboardData.setData('text',' '); 
 46InBlock.gif  event.srcElement.document.execCommand('paste'); 
 47InBlock.gif  return false;  
 48ExpandedSubBlockEnd.gif }

 49InBlock.gif if(event.keyCode == 8
 50ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
 51InBlock.gif  var oSel = document.selection.createRange();
 52InBlock.gif  var offset = event.srcElement.document.selection.createRange();
 53InBlock.gif  offset.moveToPoint(oSel.offsetLeft, oSel.offsetTop);
 54InBlock.gif  offset.moveStart('character', -4);
 55InBlock.gif  if(offset.text.length < 4return true;
 56InBlock.gif  for (var i = 0; i < offset.text.length; i++)
 57ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif{
 58InBlock.gif   if (offset.text.charAt(i) != " ")
 59ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{
 60InBlock.gif    return true;
 61ExpandedSubBlockEnd.gif   }

 62ExpandedSubBlockEnd.gif  }

 63InBlock.gif  offset.select();
 64InBlock.gif  event.srcElement.document.execCommand('Delete'); 
 65InBlock.gif  return false;  
 66ExpandedSubBlockEnd.gif }

 67InBlock.gif return true;
 68ExpandedBlockEnd.gif}

 69 None.gif
 70 None.gif function  KeyUp()
 71 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
 72InBlock.gif var oSel, offset;
 73InBlock.gif if(event.keyCode == 13)
 74ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
 75InBlock.gif  testStr = event.srcElement.innerText.substring(0, getCursorPosition());
 76InBlock.gif  var space = null;
 77InBlock.gif  for (var i = testStr.length - 1; i >= 0; i--)
 78ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif{
 79InBlock.gif   if (testStr.charAt(i) == "\n"break;
 80InBlock.gif   if (testStr.charAt(i) == " ")
 81ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{
 82InBlock.gif    if(space != null) space += " ";
 83ExpandedSubBlockEnd.gif   }

 84InBlock.gif   else
 85ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{
 86InBlock.gif    space = "";
 87ExpandedSubBlockEnd.gif   }

 88ExpandedSubBlockEnd.gif  }

 89InBlock.gif  var backupData = clipboardData.getData('text');
 90InBlock.gif  if(space != null)
 91ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif{
 92InBlock.gif   clipboardData.clearData();
 93InBlock.gif   clipboardData.setData('text',space); 
 94InBlock.gif   event.srcElement.document.execCommand('paste'); 
 95ExpandedSubBlockEnd.gif  }

 96InBlock.gif  if(backupData != null
 97ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif{
 98InBlock.gif   clipboardData.setData('text',backupData);
 99ExpandedSubBlockEnd.gif  }

100ExpandedSubBlockEnd.gif }

101InBlock.gif oSel = document.selection.createRange();
102InBlock.gif var left = oSel.offsetLeft;
103InBlock.gif var top = oSel.offsetTop;
104InBlock.gifvar token = getCurrentToken(event.srcElement);
105InBlock.gif var chars = getCursorPosition();
106InBlock.gif
107InBlock.gif if (event.keyCode == 38 || event.keyCode == 40
108InBlock.gif  || event.keyCode == 33 || event.keyCode == 34
109ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
110InBlock.gif  return true;
111ExpandedSubBlockEnd.gif }

112InBlock.gif parseSyntax(event.srcElement);
113InBlock.gif offset = event.srcElement.document.selection.createRange();
114InBlock.gif offset.moveToPoint(left, top);
115InBlock.gif offset.select();
116InBlock.gif
117InBlock.gif if(!event.shiftKey && event.keyCode == 190
118ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
119InBlock.gif  setMethods(token.posSent.slice(0-1)); 
120ExpandedSubBlockEnd.gif }

121ExpandedBlockEnd.gif}

122 None.gif
123 None.gif function  parseSyntax(src) 
124 ExpandedBlockStart.gifContractedBlock.gif dot.gif
125InBlock.gif var text = src.innerHTML;
126InBlock.gif text = text.replace(/<FONT[^<>]*>/gi, "").replace(/<\/FONT[^<>]*>/gi,"");
127InBlock.gif text = text.replace(/<BR>/gi,"\xff\xfe");
128InBlock.gif text = text.replace(/<P>/gi, "\xfe").replace(/<\/P>/gi, "\xff");
129InBlock.gif text = text.replace(//gi, "\xfd");
130InBlock.gif text = text.replace(/\</gi, "\xdf");
131InBlock.gif text = text.replace(/\>/gi, "\xdd");
132InBlock.gif text = text.replace(/\r\n/gi,"");
133InBlock.gif
134InBlock.gif for (var i = 0; i <SyntaxSet.All.length; i++)
135ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
136InBlock.gif  var syntaxes = SyntaxSet.All[i];
137InBlock.gif  for (var j = 0; j < syntaxes.rules.All.length; j++)
138ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif{
139InBlock.gif   text = parseRule(text, syntaxes.rules.All[j]); 
140ExpandedSubBlockEnd.gif  }

141ExpandedSubBlockEnd.gif }

142InBlock.gif
143InBlock.gif src.innerHTML = text.replace(/\xde/g,"").replace(/\xfc/g,"'").replace(/\xfe/g,"<P>").replace(/\xff/g,"</P>").replace(/\xfd/g," ").replace(/\xdf/g,"<").replace(/\xdd/g,">");
144ExpandedBlockEnd.gif}

145 None.gif function  parseRule(text, rule) 
146 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
147InBlock.gif var newText = "";
148InBlock.gif
149InBlock.gif var idx = text.search(rule.expr);
150InBlock.gif  
151InBlock.gif while (idx != -1)
152ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
153InBlock.gif  var remark = text.match(rule.expr);
154InBlock.gif  var subText = text.substring(0, idx + remark[0].length);
155InBlock.gif  if(rule.parent.fcons == null || (idx == 0 || rule.parent.fcons.test(text.charAt(idx-1))) && (idx + remark[0].length >= text.length || rule.parent.bcons.test(text.charAt(idx + remark[0].length))))
156ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif{
157InBlock.gif   var subToken = remark[0].replace(/<FONT[^<>]*>/gi, "").replace(/<\/FONT[^<>]*>/gi,"");
158InBlock.gif   for (var i = 0; i < rule.subRules.length; i++)
159ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{
160InBlock.gif    subToken = parseRule(subToken, rule.subRules[i]); 
161ExpandedSubBlockEnd.gif   }

162InBlock.gif   subText = subText.replace(remark[0], "<FONT \xdecolor=\xfc"+rule.parent.color+"\xfc>" + subToken + "</FONT>");
163ExpandedSubBlockEnd.gif  }

164InBlock.gif  newText += subText;
165InBlock.gif  text = text.substring(idx + remark[0].length);
166InBlock.gif  idx = text.search(rule.expr);
167ExpandedSubBlockEnd.gif }

168InBlock.gif newText += text;
169InBlock.gif return newText; 
170ExpandedBlockEnd.gif}

171 None.gif
172 None.gif function  getCurrentToken(src)
173 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
174InBlock.gif var oSel = document.selection.createRange();
175InBlock.gif var offset = src.document.selection.createRange();
176InBlock.gif offset.moveToPoint(oSel.offsetLeft, oSel.offsetTop);
177InBlock.gif offset.moveStart("character"-99999);
178InBlock.gif
179ExpandedBlockStart.gifContractedBlock.gif var sentences = offset.text.split(/[;}
dot.gif {]/g);
180InBlock.gif var currentSentence = sentences[sentences.length - 1];
181InBlock.gif
182InBlock.gif var tokens = offset.text.split(/[\s\+\-\*\/]/); 
183InBlock.gif var currentToken = tokens[tokens.length - 1];
184InBlock.gif
185InBlock.gif var idx = offset.text.length;
186InBlock.gif
187InBlock.gif var fullSentence = src.innerText.substring(idx);
188InBlock.gif fullToken = fullSentence.replace(/[\n$]/,"@@@@");
189InBlock.gif idx = fullSentence.indexOf("@@@@");
190InBlock.gif if(idx != -1)
191InBlock.gif  fullSentence = fullSentence.substring(0, idx);
192InBlock.gif
193InBlock.gif var fullToken = src.innerText.substring(idx);
194InBlock.gif fullToken = fullToken.replace(/[\s\+\-\*\/$]/,"@@@@");
195InBlock.gif idx = fullToken.indexOf("@@@@");
196InBlock.gif if(idx != -1)
197InBlock.gif  fullToken = fullToken.substring(0, idx);
198InBlock.gif
199InBlock.gif var token = new Array(); 
200InBlock.gif
201InBlock.gif token.currentToken = currentToken + fullToken;
202InBlock.gif token.posTok = currentToken;
203InBlock.gif
204InBlock.gif token.posSent = currentSentence;
205InBlock.gif token.currentSentence = currentSentence + fullSentence;
206InBlock.gif
207InBlock.gif return token;
208ExpandedBlockEnd.gif}

209 None.gifArray.prototype.pushDistinct  =   function (obj)
210 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
211InBlock.gif for (var i = 0; i < this.length; i++)
212ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
213InBlock.gif  if (this[i] == obj)
214ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif{
215InBlock.gif   return null;
216ExpandedSubBlockEnd.gif  }

217ExpandedSubBlockEnd.gif }

218InBlock.gif this.push(obj);
219InBlock.gif return obj;
220ExpandedBlockEnd.gif}

221 None.gif
222 None.gif function  putMethods(methodList, obj, methods) 
223 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
224InBlock.gif var list = methods.split(",");
225InBlock.gif
226InBlock.gif for (var i = 0; i < list.length; i++)
227ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
228InBlock.gif  if (obj[list[i]] != null)
229ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif{
230InBlock.gif   methodList.pushDistinct(list[i]);
231ExpandedSubBlockEnd.gif  }

232ExpandedSubBlockEnd.gif }

233ExpandedBlockEnd.gif}

234 None.gif function  parseObj(objStr) 
235 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
236InBlock.gif var cont = 0
237InBlock.gif var sont = 0
238InBlock.gif for (var i = objStr.length - 1; i >= 0; i--)
239ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
240InBlock.gif  if (objStr.charAt(i) == ")")
241InBlock.gif   cont ++;
242InBlock.gif  if (objStr.charAt(i) == "(")
243InBlock.gif   cont --;
244InBlock.gif  if (objStr.charAt(i) == "]")
245InBlock.gif   sont ++;
246InBlock.gif  if (objStr.charAt(i) == "[")
247InBlock.gif   sont --;
248InBlock.gif  if (cont == 0 && sont == 0 && /[\+\-\*\/\=\,\;\&\|\>\<]/.test(objStr.charAt(i)))
249InBlock.gif   break;
250InBlock.gif  if (cont < 0 || sont < 0)
251InBlock.gif   break;
252ExpandedSubBlockEnd.gif }

253InBlock.gif return objStr.substring(i+1);
254ExpandedBlockEnd.gif}

255 None.gif // 将对象的方法放到Select Object中显示出来,并且初始化不可列举方法
256 None.gif function  setMethods(objStr)
257 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
258InBlock.gif  var oSel = document.selection.createRange();
259InBlock.gif  objStr = parseObj(objStr);
260InBlock.gif  objStr = objStr.replace(/alert/g,"Object");
261InBlock.gif  var funs = getObjects(event.srcElement);
262InBlock.gif  var vars = getVariables(event.srcElement);
263InBlock.gif
264InBlock.gif  for (var __silverna_i = 0; __silverna_i < funs.length; __silverna_i++)
265ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif{
266ExpandedSubBlockStart.gifContractedSubBlock.gif   trydot.gif{eval(funs[__silverna_i]);} catch(e)dot.gif{};
267ExpandedSubBlockEnd.gif  }

268InBlock.gif  for (var __silverna_i = 0; __silverna_i < vars.length; __silverna_i++)
269ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif{
270ExpandedSubBlockStart.gifContractedSubBlock.gif   trydot.gif{eval(vars[__silverna_i]);}catch(e)dot.gif{};
271ExpandedSubBlockEnd.gif  }

272InBlock.gif  if(event.srcElement.style.display == 'none')
273ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif{
274InBlock.gif   event.srcElement.style.display = '';
275InBlock.gif   event.srcElement.focus();
276ExpandedSubBlockEnd.gif  }

277InBlock.gif  try
278ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif{
279InBlock.gif   var methodList = new Array();
280InBlock.gif   var obj = eval(objStr);
281InBlock.gif
282InBlock.gif   if (obj.prototype != null)
283ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{
284InBlock.gif    methodList.pushDistinct("prototype");
285ExpandedSubBlockEnd.gif   }

286InBlock.gif   if (obj != null)
287ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{
288InBlock.gif
289InBlock.gif    //基本Object方法
290InBlock.gif    putMethods(methodList, obj,"constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf");
291InBlock.gif    
292InBlock.gif    //基本Array方法
293InBlock.gif    putMethods(methodList, obj,"concat,join,length,pop,push,reverse,shift,slice,sort,splice,unshift");     
294InBlock.gif
295InBlock.gif    //基本Date方法
296InBlock.gif    putMethods(methodList,obj,"getDate,getUTCDate,getDay,getUTCDay,getFullYear,getUTCFullYear,getHours,getUTCHours,getMilliseconds,getUTCMilliseconds,getMinutes,getUTCMinutes,getMonth,getUTCMonth,getSeconds,getUTCSeconds,getTime,getTimezoneoffset,getYear");
297InBlock.gif
298InBlock.gif    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");
299InBlock.gif
300InBlock.gif    //基本Math方法
301InBlock.gif    putMethods(methodList,obj,"E,LN10,LN2,LOG10E,LOG2E,PI,SQRT1_2,SQRT2");
302InBlock.gif    putMethods(methodList,obj,"abs,acos,asin,atan,atan2,ceil,cos,exp,floor,log,max,min,pow,random,round,sin,sqrt,tan");
303InBlock.gif
304InBlock.gif    //基本Function方法
305InBlock.gif    putMethods(methodList,obj,"arguments,caller,length,prototype,apply,call,toString");
306InBlock.gif    
307InBlock.gif    //基本Number方法
308InBlock.gif    putMethods(methodList,obj,"MAX_VALUE,MIN_VALUE,NaN,NEGATIVE_INFINITY,POSITIVE_INFINITY");
309InBlock.gif    putMethods(methodList,obj,"toString,toLocalString,toFixed,toExponential,toPrecision");
310InBlock.gif
311InBlock.gif    //基本RegExp方法
312InBlock.gif    putMethods(methodList,obj,"global,ignoreCase,lastIndex,multiline,source,exec,test");
313InBlock.gif
314InBlock.gif    //基本String方法
315InBlock.gif    putMethods(methodList,obj,"charAt,charCodeAt,contact,indexOf,lastIndexOf,match,replace,search,slice,split,substring,substr,toLowerCase,toString,toUpperCase,valueOf,fromCharCode");
316InBlock.gif    putMethods(methodList,obj,"anchor,big,blink,bold,fixed,fontcolor,fontsize,italics,link,small,strike,sub,sup");
317InBlock.gif
318ExpandedSubBlockEnd.gif   }

319InBlock.gif   for (each in obj)
320ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{
321InBlock.gif    methodList.pushDistinct(each);
322ExpandedSubBlockEnd.gif   }

323InBlock.gif   methodList.sort();
324InBlock.gif
325InBlock.gif   if (methodList.length > 0)
326ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{
327InBlock.gif    __silverna__ctr__methods.options.length = 0;
328InBlock.gif    for (var __silverna_i = 0; __silverna_i < methodList.length; __silverna_i++)
329ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
330InBlock.gif     __silverna__ctr__methods.options.add(new Option(methodList[__silverna_i])); 
331ExpandedSubBlockEnd.gif    }

332InBlock.gif    if (__silverna__ctr__methods.options.length > 6)
333ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
334InBlock.gif     __silverna__ctr__methods.size = 6;
335ExpandedSubBlockEnd.gif    }

336InBlock.gif    else
337ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
338InBlock.gif     __silverna__ctr__methods.size = __silverna__ctr__methods.options.length;
339ExpandedSubBlockEnd.gif    }

340InBlock.gif    __silverna__ctr__methods.style.top = oSel.offsetTop;
341InBlock.gif    __silverna__ctr__methods.style.left = oSel.offsetLeft;
342InBlock.gif    __silverna__ctr__methods.style.display = "";
343InBlock.gif    __silverna__ctr__methods.options[0].selected = true;
344ExpandedSubBlockEnd.gif   }

345InBlock.gif   return true;
346ExpandedSubBlockEnd.gif  }

347ExpandedSubBlockStart.gifContractedSubBlock.gif  catch(e)dot.gif{return false;}
348ExpandedBlockEnd.gif}

349 None.gif
350 None.gif function  SelectMethod()
351 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
352InBlock.gif var src = event.srcElement;
353InBlock.gif if(event.keyCode == 13 || event.keyCode == 32)
354ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
355InBlock.gif  SelMethod(src);
356ExpandedSubBlockEnd.gif }

357InBlock.gif
358InBlock.gif if(event.keyCode == 27 || event.keyCode == 8)
359ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
360InBlock.gif  src.style.display = "none";
361InBlock.gif  __silverna__ctr__editbox.focus();
362ExpandedSubBlockEnd.gif }

363ExpandedBlockEnd.gif}

364 None.gif function  SelMethod(src)
365 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
366InBlock.gif var backupData = clipboardData.getData('text');
367InBlock.gif clipboardData.setData('text',src.options[src.selectedIndex].text);
368InBlock.gif __silverna__ctr__editbox.focus();
369InBlock.gif __silverna__ctr__editbox.document.execCommand('paste'); 
370InBlock.gif src.style.display = "none";
371InBlock.gif getCursorPosition();
372InBlock.gif if(backupData != null
373ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
374InBlock.gif  clipboardData.setData('text',backupData);
375ExpandedSubBlockEnd.gif }

376ExpandedBlockEnd.gif}

377 None.gif
378 None.gif function  getPos(text) 
379 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
380InBlock.gif var rows = 1;
381InBlock.gif var cols = 1;
382InBlock.gif var idx = 0;
383InBlock.gif var subText = text;
384InBlock.gif while((idx = subText.indexOf("\n")) != -1)
385ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
386InBlock.gif  subText = subText.substring(idx + 1);
387InBlock.gif  rows++;
388ExpandedSubBlockEnd.gif }

389InBlock.gif return new Array(rows, subText.length + 1);
390ExpandedBlockEnd.gif}

391 None.gif function  getNullRows(src,oSel) 
392 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
393InBlock.gif var rows = 0;
394InBlock.gif
395InBlock.gif var offsetEnd = src.document.selection.createRange();
396InBlock.gif
397InBlock.gif var oldTop = 2;
398InBlock.gif var oldLeft = 2;
399InBlock.gif
400InBlock.gif while(1)
401ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
402InBlock.gif  offsetEnd.moveToPoint(oSel.offsetLeft, oSel.offsetTop);
403InBlock.gif  offsetEnd.moveStart("character",-1-rows);
404InBlock.gif
405InBlock.gif  if (offsetEnd.text.length > 0 || offsetEnd.offsetTop == oldTop && offsetEnd.offsetLeft == oldLeft)
406ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif{
407InBlock.gif   break;
408ExpandedSubBlockEnd.gif  }

409InBlock.gif
410InBlock.gif  rows ++;
411InBlock.gif  oldTop = offsetEnd.offsetTop;
412InBlock.gif  oldLeft = offsetEnd.offsetLeft;
413ExpandedSubBlockEnd.gif }

414InBlock.gif 
415InBlock.gif return rows;
416ExpandedBlockEnd.gif}

417 None.gif function  getCursorPosition()
418 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
419InBlock.gif var src = event.srcElement;
420InBlock.gif var offset = src.document.selection.createRange();
421InBlock.gif var oSel = document.selection.createRange();
422InBlock.gif
423InBlock.gif var textLength = src.innerText.length;
424InBlock.gif
425InBlock.gif offset.moveToPoint(oSel.offsetLeft, oSel.offsetTop);
426InBlock.gif offset.moveStart("character"-99999);
427InBlock.gif var rowSpans = offset.getClientRects();
428InBlock.gif
429InBlock.gif var pos = getPos(offset.text);
430InBlock.gif
431InBlock.gif var charCodes = offset.text.length; 
432InBlock.gif var chars = offset.text.replace(/\r\n/g,"").length + 1;
433InBlock.gif
434InBlock.gif var extRows = getNullRows(src,oSel);
435InBlock.gif if(extRows > 0)
436ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
437InBlock.gif  pos[0+= extRows;
438InBlock.gif  pos[1= 1;
439ExpandedSubBlockEnd.gif }

440InBlock.gif window.status = "行: " + pos[0+", 列: " + pos[1+ ", 第 " + chars + " 个字符" + " ("+ oSel.offsetTop +","+ 
441InBlock.gif oSel.offsetLeft +")";
442InBlock.gif return charCodes;
443ExpandedBlockEnd.gif}

444 None.gif
445 None.gif var  SyntaxSet  =   new  Array(); 
446 None.gifSyntaxSet.All  =   new  Array();
447 None.gif
448 None.gifSyntaxSet.parse  =   function (token) 
449 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
450InBlock.gif for (var i = 0; i < this.All.length; i++)
451ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
452InBlock.gif  var syntaxes = this.All[i];
453InBlock.gif  for (var j = 0; j < syntaxes.rules.All.length; j++)
454ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif{
455InBlock.gif   if (syntaxes.rules.All[j].test(token))
456ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{
457InBlock.gif    syntaxes.rules.All[j].color = syntaxes.color;
458InBlock.gif    return syntaxes.rules.All[j];
459ExpandedSubBlockEnd.gif   }

460ExpandedSubBlockEnd.gif  }

461ExpandedSubBlockEnd.gif }

462InBlock.gif
463InBlock.gif return null;
464ExpandedBlockEnd.gif}

465 None.gif
466 None.gifSyntaxSet.add  =   function (syntaxes)
467 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
468InBlock.gif if(this[syntaxes.name] != null)
469InBlock.gif  return;
470InBlock.gif this[syntaxes.name] = syntaxes;
471InBlock.gif this.All.push(syntaxes);
472ExpandedBlockEnd.gif}

473 None.gif
474 None.gif function  Syntaxes(name, color, fcons, bcons) 
475 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
476InBlock.gif this.name = name; 
477InBlock.gif this.color = color; 
478InBlock.gif this.rules = new Array(); 
479InBlock.gif this.rules.All = new Array();
480InBlock.gif this.fcons = fcons; 
481InBlock.gif if(bcons != null)
482InBlock.gif  this.bcons = bcons;
483InBlock.gif else
484InBlock.gif  this.bcons = fcons; 
485InBlock.gif
486InBlock.gif Syntaxes.prototype.addRule = function(rule)
487ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
488InBlock.gif  if(this.rules[rule.name] != null)
489InBlock.gif   return;
490InBlock.gif  this.rules[rule.name] = rule;
491InBlock.gif  this.rules.All.push(rule);
492InBlock.gif  rule.parent = this;
493ExpandedSubBlockEnd.gif }

494ExpandedBlockEnd.gif}

495 None.gif
496 None.gif function  SyntaxRule(name, regExp) 
497 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
498InBlock.gif this.name = name; 
499InBlock.gifthis.expr = regExp; 
500InBlock.gif this.subRules = new Array(); 
501InBlock.gif SyntaxRule.prototype.test = function(token)
502ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
503InBlock.gif  return this.expr.test(token);
504ExpandedSubBlockEnd.gif }

505InBlock.gif SyntaxRule.prototype.addSubRule = function(rule)
506ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
507InBlock.gif  this.subRules.push(rule);
508InBlock.gif  if (rule.parent == null)
509InBlock.gif   rule.parent = this;
510ExpandedSubBlockEnd.gif }

511ExpandedBlockEnd.gif}

512 None.gif
513 ExpandedBlockStart.gifContractedBlock.gifSyntaxSet.add( new  Syntaxes( " keywords " " #0000ff " / [\;\s\.\xfe\xff\xfd\[\]\(\ dot.gif {\} \)\;\,] / ));  // 词法·关键词·蓝色
514 None.gif SyntaxSet[ " keywords " ].addRule( new  SyntaxRule( " Function " , / function / ));
515 None.gifSyntaxSet[ " keywords " ].addRule( new  SyntaxRule( " Variable " , / var / ));
516 None.gifSyntaxSet[ " keywords " ].addRule( new  SyntaxRule( " Return " , / return / ));
517 None.gifSyntaxSet[ " keywords " ].addRule( new  SyntaxRule( " Exception " , / ( try | catch | throw ) / ));
518 None.gifSyntaxSet[ " keywords " ].addRule( new  SyntaxRule( " Condition " , / ( if | else | switch ) / ));
519 None.gifSyntaxSet[ " keywords " ].addRule( new  SyntaxRule( " Cycle " , / ( for | while | do ) / ));
520 None.gifSyntaxSet[ " keywords " ].addRule( new  SyntaxRule( " Type " , / ( int | double | float | void | char ) / ));
521 None.gifSyntaxSet[ " keywords " ].addRule( new  SyntaxRule( " Right " , / (public | private | protected | static) / ));
522 None.gifSyntaxSet[ " keywords " ].addRule( new  SyntaxRule( " Constant " , / ( true | false | null | undefined | NaN | Infinity) / ));
523 None.gifSyntaxSet[ " keywords " ].addRule( new  SyntaxRule( " Construct " , / ( new | delete ) / ));
524 None.gif
525 ExpandedBlockStart.gifContractedBlock.gifSyntaxSet.add( new  Syntaxes( " objects " " #FF0000 " / [\;\s\.\xfe\xff\xfd\[\]\(\ dot.gif {\} \)\;\,] / ));  // 词法·对象·红色
526 None.gif SyntaxSet[ " objects " ].addRule( new  SyntaxRule( " Object " , / (Array | arguments | Boolean | Date | Error | Function | Object | Number | Math | RegExp | String) / ));
527 None.gif
528 ExpandedBlockStart.gifContractedBlock.gifSyntaxSet.add( new  Syntaxes( " global " " #800000 " / [\;\s\.\xfe\xff\xfd\[\]\(\ dot.gif {\} \)\;\,] / ));  // 词法·系统函数·红色
529 None.gif SyntaxSet[ " global " ].addRule( new  SyntaxRule( " SystemFunc " , / (alert | parseFloat | parseInt | eval | decodeURI | decodeURIComponent | encodeURI | encodeURIComponent | escape | eval | isFinite | isNaN | unescape) / ));
530 None.gif
531 None.gif // \xdf < \xdd >
532 None.gif SyntaxSet.add( new  Syntaxes( " tag " , " #0000ff " ));  // 词法·标签
533 None.gif SyntaxSet[ " tag " ].addRule( new  SyntaxRule( " startTag " , / \xdf[ ^ \xdd\'\ " \/\s\xfd\xff\xfe\xdf\?\!\%]+([\s\xfd]+[^\xdd\'\ " \ / \s\xfd\xff\xfe\xdf\ ? \ ! \ % ] + ([\s\xfd\ = ](\'[ ^ \'] * \') | (\ " [^\ " ] * \ " ))?)*[\s\xfd]*[\/]?\xdd/));
534 None.gifSyntaxSet[ " tag " ].addRule(new SyntaxRule( " endTag " ,/\xdf\/[^\xdd\'\ " \ / \s\xfd\xff\xfe\xdf\ ? \ ! \ % ] + \xdd / ));
535 None.gif
536 None.gif var  subRule  =   new  Syntaxes( " sub_tok " , " #808000 " , / [\xdf\ / ] / , / . / );
537 None.gifsubRule.addRule( new  SyntaxRule( " tagName " , / \w +/ ));
538 None.gifSyntaxSet[ " tag " ].rules[ " startTag " ].addSubRule(subRule.rules[ " tagName " ]);
539 None.gifSyntaxSet[ " tag " ].rules[ " endTag " ].addSubRule(subRule.rules[ " tagName " ]);
540 None.gif
541 None.gif var  subRule_2  =   new  Syntaxes( " sub_tok_2 " , " #800080 " , / [\xdd\xfd\s\ = \ + \ - \ * \ / \ / ] / );
542 None.gifsubRule_2.addRule( new  SyntaxRule( " attribute " , / \w +/ ));
543 None.gifSyntaxSet[ " tag " ].rules[ " startTag " ].addSubRule(subRule_2.rules[ " attribute " ]);
544 None.gif
545 ExpandedBlockStart.gifContractedBlock.gifSyntaxSet.add( new  Syntaxes( " String " " #ff00ff " / [\s\.\xfe\xff\xfd\[\]\(\ dot.gif {\} \)\;\,\ + \ - \ * \ / \ = \xdd] / ));  // 词法·字符串·粉色
546 None.gif SyntaxSet[ " String " ].addRule( new  SyntaxRule( " String " ,
547 None.gif        / ('((\\\') | [ ^ '\xff]) * ([ ^ \\\'] | (\\\'\xff))') | ( " ((\\\ " ) | [ ^ " \xff])*([^\\\ " \xff] | (\\\ " )) " ) / ));
548 None.gif
549 None.gifSyntaxSet.add( new  Syntaxes( " remarks " " #008000 " ));  // 词法·注释·绿色
550 None.gif SyntaxSet[ " remarks " ].addRule( new  SyntaxRule( " ShortRemark " , / \ / \ / [ ^ \xff] */ ));
551 None.gifSyntaxSet[ " remarks " ].addRule( new  SyntaxRule( " LongRemark " , / \ / \ * ((. * \ * \ / ) | (. * $)) / ));
552 None.gifSyntaxSet[ " remarks " ].addRule( new  SyntaxRule( " HTMLRemark " , / \xdf !-- (.( ?!-- \xdd)) * . -- \xdd / ));
553 None.gif
554 None.gif function  RegExprX(exprStr) 
555 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
556InBlock.gif this.expr = exprStr;
557ExpandedBlockEnd.gif}

558 None.gif
559 None.gif function  getObjects(src) 
560 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
561InBlock.gif var text = src.innerText;
562InBlock.gif var funs = null;
563InBlock.gif var funList = new Array();
564InBlock.gif
565InBlock.gif while((funs = text.match(funDef)) != null)
566ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
567InBlock.gif  
568InBlock.gif  var stIndex = funs.index + funs[0].length;
569InBlock.gif  var bont = 1;
570InBlock.gif  
571InBlock.gif  for (var i = stIndex; bont > 0 && i < text.length; i++)  
572ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif{
573InBlock.gif   if (text.charAt(i) == "{") bont ++;
574InBlock.gif   else if (text.charAt(i) == "}") bont--;
575ExpandedSubBlockEnd.gif  }

576InBlock.gif  
577InBlock.gif  funList.push(text.substring(funs.index, i));
578InBlock.gif
579InBlock.gif  text = text.substring(i);
580ExpandedSubBlockEnd.gif }

581InBlock.gif return funList;
582ExpandedBlockEnd.gif}

583 None.gif
584 None.gif function  getVariables(src) 
585 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
586InBlock.gif var text = src.innerText;
587InBlock.gif var vars = null;
588InBlock.gif var varList = new Array();
589InBlock.gif
590InBlock.gif while((vars = text.match(assignment)) != null)
591ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
592InBlock.gif
593InBlock.gif  var stIndex = vars.index + vars[0].length;
594InBlock.gif  var variable = text.substring(vars.index, stIndex);
595InBlock.gif  if (variable.indexOf("."== -1)
596InBlock.gif   variable = "var " + variable;
597InBlock.gif  varList.push(variable);
598InBlock.gif
599InBlock.gif  text = text.substring(stIndex);
600InBlock.gif  varList;
601ExpandedSubBlockEnd.gif }

602InBlock.gif return varList;
603ExpandedBlockEnd.gif}

604 None.gif
605 ExpandedBlockStart.gifContractedBlock.gif var  funDef  =   / function (([\s\xfd\n] * ) | ([\s\xfd\n] + [ ^ \s\xfd\n] + ))\(. * \)[\s\xfd\n] * dot.gif {/;
606InBlock.gifvar objDef = /new[\s\xfd\n]+[^\s\xfd\n$\;]+/g;
607InBlock.gifvar funCall = /[^\s\xfd\n\+\-\*\/\=]+[\s\xfd]*\(.*\)/g;
608InBlock.gifvar assignment = /[^\s\xfd\n\=\;]+[\s\xfd\n]*[=][^\;\xdd\xdf]+/
609InBlock.gif</script>

转载于:https://www.cnblogs.com/yushiro/archive/2006/08/13/475825.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值