this.format = function() { var codeArr = new Array(); var word_index = 0; var htmlTxt = new Array(); if(this.isCompress){ this._deleteComment = true; }
//得到分割字符数组(分词) for (var i = 0; i < this._codetxt.length; i++) { if (this._wordDelimiters.indexOf(this._codetxt.charAt(i)) == -1) { //找不到关键字 if (codeArr[word_index] == null || typeof(codeArr[word_index]) == 'undefined') { codeArr[word_index] = ""; } codeArr[word_index] += this._codetxt.charAt(i); } else { if (typeof(codeArr[word_index]) != 'undefined' && codeArr[word_index].length > 0) word_index++; codeArr[word_index++] = this._codetxt.charAt(i); } }
} return htmlTxt.join(""); } this.isStartWith = function(str,code,index){ if(typeof(str)!="undefined"&&str.length>0){ var cc = new Array(); for(var i=index;i<index+str.length;i++){ cc[cc.length] = code[i]; } var c = cc.join(""); if(this._caseSensitive){ if(str.length>=code[index].length&&c.indexOf(str)==0){ return true; } }else{ if(str.length>=code[index].length&&c.toLowerCase().indexOf(str.toLowerCase())==0){ return true; } } return false; } else { return false; } } this.isFunction = function(val){ return this._function.contains(this._caseSensitive?val:val.toLowerCase()); }
this.isBlockElement = function(val) { return this._blockElement.contains(this._caseSensitive?val:val.toLowerCase()); } this.isChoiceElement = function(val) { return this._choiceElement.contains(this._caseSensitive?val:val.toLowerCase()); } this.isSingleEyeElement = function(val) { return this._singleEyeElement.contains(this._caseSensitive?val:val.toLowerCase()); } this.isNextElement = function(from,word){ for(var i=from;i<word.length;i++){ if(word[i]!=" "&&word[i]!="\t"&&word[i]!="\r"&&word[i]!="\n"){ return this.isChoiceElement(word[i]); } } return false; } this.getSkipLength = function(val){ var count = 0; for(var i=0;i<val.length;i++){ if(this._wordDelimiters.indexOf(val.charAt(i))>=0){ count++; } } if(count>0){ count=count-1; } return count; } this.getIdent=function(){ var n = []; for(var i=0;i<this._tabNum;i++){ n[n.length] = "\t"; } return n.join(""); } } function doformat(o){ var htmltxt = ""; if (o == null){ alert("domNode is null!"); return; } var _codetxt = "";
if(typeof(o)=="object"){ switch(o.tagName){ case "TEXTAREA": case "INPUT": _codetxt = o.value; break; case "DIV": case "SPAN": _codetxt = o.innerText; break; default: _codetxt = o.innerHTML; break; } }else{ _codetxt = o; } var _syn = new CLASS_FORMAT(_codetxt); htmltxt = _syn.format(); return htmltxt; }
function go() { var code = document.getElementById("code").value; var xx = new CLASS_FORMAT(code); var a = new Date(); if(document.getElementById('cboOperate').selectedIndex==1){ xx.isCompress=true; }else{ xx.style = parseInt(document.getElementById('cboStyle').value); } document.getElementById("display").value = xx.format(); alert("共花:" + (new Date().getTime()-a.getTime()) + "ms"); } //--> </SCRIPT> <TEXTAREA id=code rows=12 cols=100> /* 这个是一个类 */
function xx (num,str){//说明 var a = num;this.aa = a; this.bb = function(){alert(str);} this.cc = function(){for(var i=0;i<10;i++){document.title=i;}}}; xx.prototype.dd= function(){alert("d d kd");} var a = new xx(100,"hello"),b=new xx(0,"ttyp"); if(1>2) { alert(); } else { alert(" hell "); } a.bb(); b.dd(); alert(a.aa); </TEXTAREA> <BR> <select id="cboOperate" onchange="if(this.selectedIndex==1)document.getElementById('cboStyle').disabled=true;else document.getElementById('cboStyle').disabled=false;"> <option value="0">格式化</option>