this.add=function(appendTo,text) { var seed =this.getSeed(); var editorId ='editor_'+ seed; var outer = Util.aE('div','outer_'+ seed,appendTo); this.setC(outer,'outer clearfix');
var itemType = Util.aE('div','item_type_'+ seed,outer); this.setC(itemType,'itemType'); for(var i=0;i<this.itemTypeElements.length;i++) { var el =this.itemTypeElements[i]; var lab = el.split(':'); var _item = Util.aE('input:radio:type_'+ seed,'type_'+ lab[0]+'_'+ seed,itemType,lab[1]|| lab[0]); _item.setAttribute('value',lab[0]); _item.onfocus=function() { setEditorActive(seed); } _item.onclick=function() { var el =this; Util.gE('item_type_dp_'+ EditorId).innerHTML= el.value; } Util.aE('br',null,itemType); } var itemTypeDp = Util.aE('span','item_type_dp_'+ seed,outer);
var iframe = Util.aE('iframe',editorId,outer); this.setC(iframe,'textbox'); var sourceId ='source_'+ seed; varsource= Util.aE('textarea',sourceId,outer); source.style.display='none'; source.setAttribute('rows',this.sourceRows); source.setAttribute('cols',this.sourceCols); if(Util.isIE()){ source.onfocus=function(){setEditorActive(seed);} }else{//fix firefox
//nothing todo
} varitem= Util.aE('div','item_outer_'+ seed,outer); this.setC(item,'item'); for(var i=0;i<this.itemElements.length;i++) { var el =this.itemElements[i]; var lab = el.split(':'); var _item = Util.aE('input','item_'+ lab[0]+'_'+ seed,item,lab[1]|| lab[0]); _item.onfocus=function() { setEditorActive(seed); } Util.aE('br',null,item); } iframe.contentWindow.document.designMode="On"; iframe.contentWindow.document.contentEditable=true; iframe.contentWindow.document.designMode="On"; iframe.contentWindow.document.open(); iframe.setAttribute('width',this.iframeWidth); iframe.setAttribute('height',this.iframeHeight); iframe.contentWindow.document.writeln('+this.backgroundColor+'">'+(text||'')+'
'); iframe.contentWindow.document.close();
iframe.onfocus=function() { setEditorActive(seed); } this.setSeed(seed); return seed; } this.getAllContent =function() { varcontent=""; var fs =document.getElementByTagName('div'); } this.debug =function(val) { for(var p in val) alert(p +'-->'+ val[p]); } //此方法不维护全局标识符.
this.showInfo =function() { if(!Util.gE('infouter_'+this.getEditorId())){ for(var p inthis.infoElements) { var infoout = Util.aE('div','info_uter_'+this.getEditorId(),this.infoId); this.setC(infoout,'info'); var info = Util.aE('div','infouter_'+ p +'_'+this.getEditorId(),infoout,this.infoElements[p].lab); info.setAttribute('type',p); for(var j=0;j<this.infoElements[p].length;j++) { var el =this.infoElements[p][j]; var lab = el.split(':'); Util.aE('input','info_'+ lab[0]+'_'+this.getEditorId(),info,lab[1]|| lab[0]); Util.aE('br','',info); } } }else{ Util.gE('infouter_'+this.getEditorId()).style.display=''; } } this.remove=function(id) { var el = Util.gE('outer_'+this.getEditorId()); return el.parentNode.removeChild(el); } //设置编辑框内容
this.blob =function() { if(this.model=='w') { var s = Util.gFR('editor_'+this.getEditorId()); s =''+ s +''; Util.sFR('editor_'+this.getEditorId(),s); }else{ var s = Util.gR('source_'+this.getEditorId()); this.saveH(s); Util.aT('source_'+this.getEditorId(),'',''); } } this.link=function() { varurl=prompt('请输入URL地址,以HTTP://开头','http://'); if(url!=null){ if(this.model=='w') { this.iframeDoc.execCommand('CreateLink',false,url); }else{ var s = Util.gR('source_'+this.getEditorId()); this.saveH(s); Util.aT('source_'+this.getEditorId(),'+url+'">',''); } } } this.unlink=function() { if(this.model=='w') { this.iframeDoc.execCommand('Unlink',false,null); }else{ var s = Util.gR('source_'+this.getEditorId()); this.saveH(s); s = s.replace(/<a.*?>(.*?)<\/a>/ig,'$$1'); Util.sR('source_'+this.getEditorId(),s); } } this.img =function() { varurl=prompt('请输入图片地址','http://'); if(url!=null){ if(this.model=='w') { this.iframeDoc.execCommand("InsertImage",false,url); }else{ var s = Util.gR('source_'+this.getEditorId()); this.saveH(s); Util.aT('source_'+this.getEditorId(),'+url+'"/>',''); } } } this.heading =function(size) { if(this.model=='w') { var s = Util.gFR('editor_'+this.getEditorId()); s ='+size+'>'+ s +'+size+'>'; Util.sFR('editor_'+this.getEditorId(),s); }else{ var s = Util.gR('source_'+this.getEditorId()); this.saveH(s); Util.aT('source_'+this.getEditorId(),'+size+'>','+size+'>'); } } this.ol =function() { if(this.model =='w') { this.iframeDoc.execCommand("InsertOrderedList",false,null);; }else{ var s = Util.gR('source_'+this.getEditorId()); this.saveH(s); Util.aT('source_'+this.getEditorId(),'
'
,''); } } this.ul =function() { if(this.model =='w') { this.iframeDoc.execCommand("InsertUnorderedList",false,null); }else{ var s = Util.gR('source_'+this.getEditorId()); this.saveH(s); Util.aT('source_'+this.getEditorId(),'
'
,''); } } this.notice =function() { if(this.model=='w') { var s = Util.gFR('editor_'+this.getEditorId()); s =''+ s +''; Util.sFR('editor_'+this.getEditorId(),s); }else{ var s = Util.gR('source_'+this.getEditorId()); this.saveH(s); Util.aT('source_'+this.getEditorId(),'',''); } } this.warn =function() { if(this.model=='w') { var s = Util.gFR('editor_'+this.getEditorId()); s =''+ s +''; Util.sFR('editor_'+this.getEditorId(),s); }else{ var s = Util.gR('source_'+this.getEditorId()); this.saveH(s); Util.aT('source_'+this.getEditorId(),'',''); } } this.undo =function() { if(this.model=='w') { this.iframeDoc.execCommand("Undo",false,null); }else{ Util.gE('source_'+this.getEditorId()).value=this.getH(); } } //多媒体信息会造成浏览预读.所以会出现假死状态
this.flash =function() { varurl=prompt('请输入FLASH地址','http://'); if(url!=null){ var s ='url+'"/>'; if(this.model=='w') { Util.sFR('editor_'+this.getEditorId(),s); }else{ Util.sR('source_'+this.getEditorId(),s); } } } this.clear=function() { if(this.model =='w') { var s = Util.gFC('editor_'+this.getEditorId()); s =this.filterHTML(s); this.iframeDoc.body.innerHTML= s; }else{ var s = Util.gE('source_'+this.getEditorId()).value; s =this.filterHTML(s); Util.gE('source_'+this.getEditorId()).value= s; } } this.save=function() { if(this.verifyData()) { var s =this.getContent(); alert(s); } } this.autoSave =function(time) { var editor =this; enableas =Math.abs(enableas-1); setInterval(function(){ if(enableas){ var s = editor.getContent(); alert(s); } },(time || 10)*1000); } ////////////////////////////////////////////// 功能定义结束 //////////////////////////////////
this.verifyData =function() { var success =true; var iframe =document.getElementsByTagName('iframe'); for(var i=0;i<iframe.length;i++) { //TODO
} return success; } this.getContent =function() { varcontent=''; varitem=''; var info =''; var iframe =document.getElementsByTagName('iframe'); if(Util.gE(this.infoId).innerHTML!=null){ for(var p inthis.infoElements) { info +='+ p +'">';//no type
for(var i=0;i<this.infoElements[p].length;i++) { var el =this.infoElements[p][i]; var lab = el.split(':'); varid='info_'+ lab[0]+'_0'; info +='
+
lab[0]+'"> +(Util.gE(id).value||'')+']]>
'; } info +=''; } }
for(var i=0;i<iframe.length;i++) { item+=''; item+='+ Util.gE('item_type_dp_'+ i).innerHTML+'">'; for(var j=0;j<this.itemElements.length;j++) { var el =this.itemElements[j]; var lab = el.split(':'); varid='item_'+ lab[0]+'_'+ i; item+='