?? editor.js
字號:
var clearTag=function(html){return html.toString().replace(/<[^>]+?>/g,'');};var htmlentities=function(html){return html?html.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'):'';};var _htmlentities=function(html){return html?html.replace(/</gi,'<').replace(/>/gi,'>').replace(/&/gi,'&'):'';};$('url_'+id).value=url;$('text_'+id).value=_htmlentities(clearTag(text));}
else{}};},createUnlink:function(toolbar,div){if(!this.icons.unlink[0])return;var unlink=this.buttons.unlink=this.createIcon(div,'unlink');unlink.onclick=function(){if(!cEditor.isWYSIWYG())return;cEditor.SetStyle('Unlink',false);toolbar.changeState(this,false);};},createFace:function(toolbar,div){if(!this.icons.face[0])return;var face=this.buttons.face=this.createIcon(div,'face');CSS.AddClass(face,'face');face.onclick=function(){if(cEditor.isXHTML())return;if(toolbar.facePanel){toolbar.faceNode.parentNode.removeChild(toolbar.faceNode);toolbar.facePanel.parentNode.removeChild(toolbar.facePanel);}
toolbar.facePanel=cEditor.Menu(window,365,0,'');CSS.AddClass(toolbar.facePanel,'face');toolbar.faceBlock(toolbar.facePanel);toolbar.facePanel.style.top=Global.GetOffsetTop(this)+this.offsetHeight+'px';toolbar.facePanel.style.left=Global.GetOffsetLeft(this)+'px';};},createTable:function(toolbar,div){if(!this.icons.table[0])return;var self=this;var table=this.buttons.table=this.createIcon(div,'table');var mask=CSS.AddBack();CSS.AddClass(mask,'table-mask');CSS.SetAlpha(mask,0);mask.Hide();var tip=new Tip();tip.css.tip='table-tip';tip.Condition=function(){return true};var t;var mousedown,mousemove,mouseup;if(Browser.IsIE){table.onmousedown=click;}
else{table.onclick=click;}
function click(){if(cEditor.isXHTML())return;t=toolbar.tablePanel=oNode.CreateNode(Browser.IsIE?'a':'div');oNode.AddNode(t);CSS.AddClass(t,'table-panel');t.href='javascript:void(0)';var x=Global.GetOffsetLeft(table);var y=Global.GetOffsetTop(table);t.style.left=x+'px';t.style.top=y+table.offsetHeight+'px';var tColor=oNode.CreateNode('span');oNode.AddNode(tColor,t);CSS.AddClass(tColor,'table-color');var tImage=oNode.CreateNode('span');oNode.AddNode(tImage,t);CSS.AddClass(tImage,'table-image');mask.Show();tip.Create();var xCount=yCount=0;var is_down=!false;var w=18,h=18;var isMouseUp=false;mousedown=function(e){var obj=$EO(e);while(obj){if(obj==t)break;obj=obj.parentNode;}
if(obj){is_down=true;x=e.clientX+Global.GetScrollLeft();y=e.clientY+Global.GetScrollTop();}
else{removeevent();}
Events.CancelAll(e);}
mousemove=function(e){if(is_down){var x_t=e.clientX+Global.GetScrollLeft();var y_t=e.clientY+Global.GetScrollTop();xCount=Math.ceil((x_t-x+w)/18-1);yCount=Math.ceil((y_t-y+h)/18-2);x_t=xCount*18;y_t=yCount*18;tColor.style.width=(x_t>0?x_t:0)+'px';tColor.style.height=(y_t>0?y_t:0)+'px';if(xCount<3){if(xCount<0)xCount=0;t.style.width=tImage.style.width=2*18+'px';}
else{t.style.width=tImage.style.width=x_t+'px';}
if(yCount<3){if(yCount<0)yCount=0;t.style.height=tImage.style.height=2*18+'px';}
else{t.style.height=tImage.style.height=y_t+'px';}
tip.isCreate&&tip.SetText(yCount+' x '+xCount);}
Events.CancelAll(e);}
mouseup=function(e){if(isMouseUp)return;isMouseUp=true;if(is_down)CreateTable(yCount,xCount);removeevent();try{Events.CancelAll(e);}catch(e){}}
Events.AttachEvent(document,'mousemove',mousemove);Events.AttachEvent(document,'mouseup',mouseup);Events.AttachEvent(window.top.document,'mouseup',mouseup);CSS.SelectOff();};table.onmouseup=function(){removeevent();};table.onmouseover=function(){if(cEditor.isXHTML())return;table.style.backgroundPosition=(typeof self.icons[table.type][1]=='string'?0:'-'+self.icons[table.type][1])+'px -'+self.yOffset+'px';};var _mouseout=table.onmouseout=function(){if(cEditor.isXHTML())return;if(table.overState)return;table.style.backgroundPosition=(typeof self.icons[table.type][1]=='string'?0:'-'+self.icons[table.type][1])+'px 0';};function removeevent(){is_down=false;Events.RemoveEvent(document,'mousemove',mousemove);Events.RemoveEvent(document,'mouseup',mouseup);Events.RemoveEvent(window.top.document,'mouseup',mouseup);oNode.RemoveNode(t);mask.Hide();tip.isCreate&&tip.Remove();_mouseout();CSS.SelectOn();}
function CreateTable(row,col){if(row==0||col==0)return;var str='';for(var r=0;r<row;r++){str+='<tr>';for(var c=0;c<col;c++){str+='<td> </td>';}
str+='</tr>';}
var table=cEditor.isUBB()?'[table]'+str.replace(/</g,'[').replace(/>/g,']').replace(/ /g,' ').replace(' ','\x01')+'[/table]':'<table cellspacing="1" border="1" width="100%">'+str+'</table>';if(cEditor.isWYSIWYG()){cEditor.SelectTextRange();cEditor.InsertContent(table);}
else{cEditor.SetUBBStyle(table);}}},createCode:function(toolbar,div){if(!this.icons.code[0])return;var code=this.buttons.code=this.createIcon(div,'code');code.onclick=function(){if(cEditor.isXHTML())return;if(cEditor.isUBB()){cEditor.SetUBBStyle('[code]\x01[/code]');return;}
var id=Global.Random();var panel=PopUp.Panel(['<div class="editwin-head">',' <h3>插入代碼</h3>','</div>','<div class="clearfix editwin-body editwin-code">',' <p>',' <textarea rows="10" cols="35" id="content_'+id+'"></textarea>',' </p>',' <p style="float:right">',' <span class="xbtn"><input type="button" value="確認" id="confirm_'+id+'" /></span>',' <span class="xbtn"><input type="button" value="取消" id="cancel_'+id+'" /></span>',' </p>','</div>','</div>'].join(''),200,100);CSS.AddClass(panel,'editwin');panel.style.zIndex=10;panel.style.left=Global.GetOffsetLeft(code)+'px';panel.style.top=Global.GetOffsetTop(code)+code.offsetHeight+'px';PopUp.AddPopUp(panel,true);PopUp.HideModal(panel);$('content_'+id).focus();$('confirm_'+id).onclick=function(){var content=$('content_'+id).value;PopUp.RemovePopUp(panel);if(content.replace(/\s*/g,'')=='')return;content=content.replace(/</g,'<').replace(/>/g,'>').replace(/\r\n|\r|\n/g,'<br />');content='[code]'+content+'[/code]';cEditor.SelectTextRange();cEditor.InsertContent(content);};$('cancel_'+id).onclick=function(){PopUp.RemovePopUp(panel);};};},createFree:function(toolbar,div){if(!this.icons.free[0])return;var free=this.buttons.free=this.createIcon(div,'free');free.onclick=function(){if(cEditor.isXHTML())return;if(cEditor.isUBB()){cEditor.SetUBBStyle('[free]\x01[/free]');return;}
if(cEditor.isWYSIWYG()){var text=Browser.IsIE?cEditor.TextRange.htmlText:cEditor.SelectRange;if(Browser.IsIE){cEditor.InsertContent('[free]'+text+'[/free]');}
else{var range=cEditor.SelectRange.getRangeAt(0);try{node=range.cloneContents();}
catch(e){node='';}
var n=cEditor.Document.createElement('div');oNode.AddNode(node,n);n.innerHTML='[free]'+n.innerHTML+'[/free]';cEditor.InsertContentGecko(n);while(n.firstChild){var fc=n.removeChild(n.firstChild);oNode.InsertBefore(fc,n);}
n.parentNode.removeChild(n);}}}},createHide:function(toolbar,div){if(!this.icons.hide[0])return;var hide=this.buttons.hide=this.createIcon(div,'hide');hide.onclick=function(){if(cEditor.isXHTML())return;if(cEditor.isUBB()){cEditor.SetUBBStyle('[hide]\x01[/hide]');return;}
if(cEditor.isWYSIWYG()){var text=Browser.IsIE?cEditor.TextRange.htmlText:cEditor.SelectRange;if(Browser.IsIE){cEditor.InsertContent('[hide]'+text+'[/hide]');}
else{var range=cEditor.SelectRange.getRangeAt(0);node=range.cloneContents();var n=cEditor.Document.createElement('div');n.appendChild(node);n.innerHTML='[hide]'+n.innerHTML+'[/hide]';cEditor.InsertContentGecko(n);while(n.firstChild){var fc=n.removeChild(n.firstChild);oNode.InsertBefore(fc,n);}
n.parentNode.removeChild(n);}}
return;var id=Global.Random();var panel=PopUp.Panel(['<div class="editwin-head">',' <h3>插入隱藏內容</h3>','</div>','<div class="clearfix editwin-body editwin-hide">',' <p>',' <textarea rows="5" cols="35" id="content_'+id+'"></textarea>',' </p>',' <p>',' <input type="radio" name="select_'+id+'" id="one_'+id+'" checked="checked" /> 瀏覽者回復本帖后才顯示',' </p>',' <p>',' <input type="radio" name="select_'+id+'" id="two_'+id+'" /> 瀏覽者積分高于 <input type="text" class="text" size="4" id="score_'+id+'" /> 時才顯示',' </p>',' <p style="float:right">',' <span class="xbtn"><input type="button" value="確認" id="confirm_'+id+'" /></span>',' <span class="xbtn"><input type="button" value="取消" id="cancel_'+id+'" /></span>',' </p>','</div>'].join(''),200,100);CSS.AddClass(panel,'editwin');panel.style.zIndex=10;panel.style.left=Global.GetOffsetLeft(hide)+'px';panel.style.top=Global.GetOffsetTop(hide)+hide.offsetHeight+'px';PopUp.AddPopUp(panel,true);PopUp.HideModal(panel);$('content_'+id).focus();$('confirm_'+id).onclick=function(){var content=$('content_'+id).value;var score=$('score_'+id).value;var checked=$('two_'+id).checked;if(checked){if(score==''||!/^\d+$/.test(score)){alert('需要輸入一個分數值。');return;}
score='='+score;}
PopUp.RemovePopUp(panel);if(content.replace(/\s*/g,'')=='')return;content=content.replace(/</g,'<').replace(/>/g,'>').replace(/\r\n|\r|\n/g,'<br />');content='[hide'+score+']'+content+'[/hide]';cEditor.SelectTextRange();cEditor.InsertContent(content);};$('cancel_'+id).onclick=function(){PopUp.RemovePopUp(panel);};};},createQuote:function(toolbar,div){if(!this.icons.quote[0])return;var quote=this.buttons.quote=this.createIcon(div,'quote');quote.onclick=function(){if(cEditor.isXHTML())return;if(cEditor.isUBB()){cEditor.SetUBBStyle('[quote]\x01[/quote]');return;}
var id=Global.Random();var panel=PopUp.Panel(['<div class="editwin-head">',' <h3>插入引用</h3>','</div>','<div class="clearfix editwin-body editwin-code">',' <p>',' <textarea rows="10" cols="35" id="content_'+id+'"></textarea>',' </p>',' <p style="float:right">',' <span class="xbtn"><input type="button" value="確認" id="confirm_'+id+'" /></span>',' <span class="xbtn"><input type="button" value="取消" id="cancel_'+id+'" /></span>',' </p>','</div>','</div>'].join(''),200,100);CSS.AddClass(panel,'editwin');panel.style.zIndex=10;panel.style.left=Global.GetOffsetLeft(quote)+'px';panel.style.top=Global.GetOffsetTop(quote)+quote.offsetHeight+'px';PopUp.AddPopUp(panel,true);PopUp.HideModal(panel);$('content_'+id).focus();$('confirm_'+id).onclick=function(){var content=$('content_'+id).value;PopUp.RemovePopUp(panel);if(content.replace(/\s*/g,'')=='')return;content=content.replace(/</g,'<').replace(/>/g,'>').replace(/\r\n|\r|\n/g,'<br />');content='<div class="maxcode-quote">'+content+'</div>';cEditor.SelectTextRange();cEditor.InsertContent(content);};$('cancel_'+id).onclick=function(){PopUp.RemovePopUp(panel);};};},createFullScreen:function(toolbar,div){if(!this.icons.fullScreen[0]||this.FullScreen==false)return;var self=this;var fullScreen=this.buttons.fullScreen=this.createIcon(div,'fullScreen');CSS.AddClass(fullScreen,'fullscreen');var p;var w,h;var mousewheel;var isFullscreen=false;var switchToFullScreen=function(){var editor=cEditor.EditorWindow;editor.style.position=isFullscreen?'static':'absolute';if(!isFullscreen||typeof w=='undefined'||typeof h=='undefined'){w=editor.style.width;h=editor.offsetHeight;}
self.setResizable(isFullscreen);var html=parent.document.getElementsByTagName('html')[0];var body=parent.document.body;html.style.overflow=body.style.overflow=isFullscreen?'auto':'hidden';var _w,_h;if(isFullscreen){_w=w;_h=h+'px';if(Browser.IsOpera)mousewheel.RemoveEvent();}
else{editor.style.width='0';editor.style.height='0';editor.style.zIndex=1;editor.style.left=parent.Global.GetScrollLeft()+'px';editor.style.top=parent.Global.GetScrollTop()+'px';if(Browser.IsIE56){_w=parent.Global.GetClientWidth()+'px';_h=parent.Global.GetClientHeight()+'px';}
else{_w='100%';_h='100%';}
if(Browser.IsOpera)mousewheel=new MouseWheel();}
editor.style.width=_w;editor.style.height=_h;self.changeState(this,false);this.style.width=(isFullscreen?self.icons['fullScreen'][2]:70)+'px';this.innerHTML=isFullscreen?self.icons['fullScreen'][4]:'取消全屏';isFullscreen=!isFullscreen;};fullScreen.onclick=switchToFullScreen;this.SwitchToFullScreen=function(){switchToFullScreen.apply(fullScreen)};},createIcon:function(p,type){var icon=oNode.CreateNode('a');CSS.AddClass(icon,'icon');icon.appendChild(oNode.CreateTextNode(this.icons[type][4]||''));p.appendChild(icon);icon.type=type;icon.title=this.icons[type][3]||'';icon.href='javascript:;';var src,standone=false;if(typeof this.icons[type][1]=='string'){src=this.icons[type][1];standone=true;}
else{src=this.iconSrc;}
if(/http:\/\//i.test(src)){src='url('+src+') no-repeat 0 0';}
else{src='url('+this.iconsRoot+src+') no-repeat '+(standone?0:'-'+this.icons[type][1]+'px')+' 0';}
src='transparent '+src;icon.style.background=src;if(this.icons[type][2]){try{icon.style.width=this.icons[type][2]+'px';}
catch(e){}}
var self=this;icon.onmouseover=function(){if(cEditor.isXHTML())return;this.style.backgroundPosition=(typeof self.icons[this.type][1]=='string'?0:'-'+self.icons[this.type][1])+'px -'+self.yOffset+'px'};icon.onmouseout=function(){if(cEditor.isXHTML())return;if(this.overState)return;this.style.backgroundPosition=(typeof self.icons[this.type][1]=='string'?0:'-'+self.icons[this.type][1])+'px 0'};return icon;},colorList:function(type){this.colorType=type;if(this.colorNode)return this.colorNode;var toolbar=this;var element=oNode.CreateNode('div');element.style.width='216px';var custom=['#000000','#333333','#666666','#999999','#AAAAAA','#CCCCCC','#FFFFFF','#FFF000','#000000','#000FFF','#FF0000','#00FF00','#0000FF','#FFFF00','#00FFFF','#FF00FF','#ABCDEF','#123456'];for(var i=0;i<custom.length;i++){element.appendChild(toolbar.colorBlock(custom[i]));}
var L,M,N;var colors=['00','33','66','99','CC','FF'];var H=18;var V=12;var hV=Math.floor(V/2);for(var i=0;i<H*V;i++){var h=i%H;var v=Math.floor(i/H);if(h<hV&&v<hV){L=colors[0];}
else if(h<hV&&v>=hV){L=colors[3];}
else if(h<V&&v<hV){L=colors[1];}
else if(h<V&&v>=hV){L=colors[4];}
else if(h<H&&v<V){L=colors[2];}
else{L=colors[5];}
M=colors[h%hV];N=colors[v%hV];element.appendChild(toolbar.colorBlock('#'+L+M+N));}
toolbar.colorNode=element;return element;},colorBlock:function(_color){var toolbar=this;var color=oNode.CreateNode('a');color.style.margin='';color.style.display='block';color.style.overflow='hidden';color.style.width='10px';color.style.height='10px';color.style.backgroundColor=_color;color.alt=_color;color.title=_color;color.href='javascript:void(0);';color.appendChild(document.createTextNode(' '));color.onclick=function(){if(cEditor.isXHTML())return;if(cEditor.isWYSIWYG()){cEditor.SetStyle(toolbar.colorType,this.alt);}
else{colorType=toolbar.colorType.toLowerCase()=='forecolor'?'color':'bgcolor';cEditor.SetUBBStyle('['+colorType+'='+this.alt+']\x01[/'+colorType+']');}};var container=oNode.CreateNode('div');container.style.cssFloat='left';container.style.styleFloat='left';container.style.border='1px solid #fff';container.appendChild(color);container.onmouseover=function(){this.style.borderColor='#666';};container.onmouseout=function(){this.style.borderColor='#fff';};container.onclick=function(){toolbar.colorPanel.style.display='none';};return container;},createABlock:function(str){var oA=oNode.CreateNode('a');oA.style.display='block';oA.style.width='100%';oA.style.color='#000';oA.style.padding='4px';oA.style.fontSize='12px';oA.style.textDecoration='none';oA.href='javascript:void(0)';oA.onmouseover=function(){CSS.ReplaceClass(this,'menu-item-out','menu-item-over');};oA.onmouseout=function(){CSS.ReplaceClass(this,'menu-item-over','menu-item-out');};oA.appendChild(document.createTextNode(str));return oA;},justifyBlock:function(str,command){var toolbar=this;var oA=toolbar.createABlock(str);oA.onclick=function(){cEditor.SetStyle(command,false);toolbar.justifyPanel.style.display='none';}
return oA;},listBlock:function(str,command){var toolbar=this;var oA=toolbar.createABlock(str);oA.onclick=function(){cEditor.SetStyle(command,'');toolbar.listPanel.style.display='none';}
return oA;},indentBlock:function(str,command){var toolbar=this;var oA=toolbar.createABlock(str);oA.onclick=function(){cEditor.SetStyle(command,false);toolbar.indentPanel.style.display='none';}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -