/******************************************************************************/ /* 파 일 명: /common/editor.php /* 작업내용: 게시판의 HTML형식의 에디터 /* 작성일자: 2007-07-02 /* 작 성 자: (주)EXI인터넷그룹 이성준 /******************************************************************************/ var Config = { btn : null, btnList : { font : ["글자체","font.gif"], size : ["글자크기","size.gif"], undo : ["되돌리기","undo.gif"], redo : ["재실행","redo.gif"], bold : ["굵게","bold.gif"], italic : ["기울리기","italic.gif"], strike : ["취소선","strike.gif"], left : ["왼쪽 맞춤","left.gif"], center : ["가운데 맞춤","center.gif"], right : ["오른쪽 맞춤","right.gif"], justify : ["혼합정렬","justify.gif"], clean : ["스타일 지움","clean.gif"], del : ["선택삭제","del.gif"], color : ["글자색","color.gif"], hilite : ["글자 배경색","hilite.gif"], link : ["링크 삽입","link.gif"], unlink : ["링크 해제","unlink.gif"], ul1 : ["번호달기","ul1.gif"], ul2 : ["기호달기","ul2.gif"], outdent : ["내어쓰기","outdent.gif"], indent : ["들여쓰기","indent.gif"], hr : ["수평선 삽입","hr.gif"], all : ["전체선택","selectall.gif"], save : ["문서 저장","save.gif"], sup : ["윗첨자","sup.gif"], sub : ["아래첨자","sub.gif"], underline : ["밑줄","underline.gif"], source : ["소스보기","htmltext.gif"], media : ["미디어파일","media.gif"], table : ["테이블","table.gif"], image : ["이미지삽입","image.gif"], preview : ["미리보기","preview.gif"], dirImg : ["파일삽입","image.gif"], bar : ["구분선","bar.gif"] }, template : { all : ["save","preview","bar","all","undo","redo","bar", "font","size","bar","color","hilite","bar","bold","italic", "underline","strike","bar","sup","sub","bar","clean","del","bar","outdent","indent", "bar","ul1","ul2","bar","left","center","right","justify","bar","hr","link", "unlink","bar","table","image","bar","source"], bbs : ["source","bar","font","size","bar","bold","italic","underline","strike","color","hilite", "bar","ul1","ul2","bar","left","center","right","justify","bar","hr","link","unlink","bar","table", "image","media","bar","preview"], shop : ["source","bar","font","size","bar","bold","italic","underline","strike","color","hilite", "bar","ul1","ul2","bar","left","center","right","bar","hr","link","unlink","bar","table", "image","bar","preview"], simple : ["source","font","size","bar","bold","italic","underline","strike","color","hilite", "bar","ul1","ul2","bar","left","center","right","bar","hr","link","unlink","bar","table", "image","media"] } } var util = { _editor : null, _colorTable : null, _fontTable : null, _sizeTable : null, _linkTable : null, isIE : (window.showModalDialog) ? 1:0, _sendPost : null, order : "" } function editor(id, content, height) { if(typeof(document.execCommand)=="undefined") return; this._id = id; this.height = height; this.imagePath = "/common/editor"; this._button = Config.template["bbs"]; this.textarea = document.getElementById(content); this._div = document.createElement("div"); //전체 div this._divButton = document.createElement("div"); //버튼영역 div this._iFrame = document.createElement("iframe"); //iframe this._text = document.createElement("textarea"); //textarea(source) this._div.id = "editorDiv_"+id; this._divButton.id = "editorDivButton_"+id; this._iFrame.id = "editorIframe_"+id; this._text.id = "editorText_"+id; this.mode = "editor"; this.sel_html = ""; this.sel = null; this.range = null; } editor.prototype.init = function() { this.textarea.style.display="none"; //칼라테이블 CSS var s=""; document.write(s); //source this._text.style.width = "100%"; this._text.style.height= this.height; this._text.style.border= "none"; this._text.style.display="none"; this._text.style.font = "9pt 굴림"; this._text.style.padding="3px"; this._text.style.background = "#FFFFFF url("+this.imagePath+"/source_bg.gif) 0 -2px"; this._text.style.lineHeight = "150%"; //전체 div this._div.style.border = "1px solid #cdcdcd"; this._div.style.width = "100%"; //버튼 this._divButton.align = "center"; this._divButton.style.padding ="2px"; this._divButton.style.borderBottom = "1px solid #cdcdcd"; this._divButton.style.width = '100%'; this.textarea.parentNode.insertBefore(this._div, this.textarea); this.displayButton(); //iframe doc this._iFrame.style.width = '100%'; this._iFrame.style.cursor= 'auto'; this._iFrame.style.height= this.height; this._iFrame.scrolling = "auto"; this._iFrame.frameBorder = "no"; //출력 this._div.appendChild(this._divButton); this._div.appendChild(this._iFrame); this._div.appendChild(this._text); this._doc = this._iFrame.contentWindow.document; this._doc.designMode="on"; /*this.css = "body{font:normal 10pt 굴림;margin:5px;word-break:break-all;background-color:#FFFFFF} p{ margin:1 0 3 0;word-break:break-all;}";*/ this._doc.open(); /*this._doc.write(""+this.textarea.value+"");*/ this._doc.write(""+this.textarea.value+""); this._doc.close(); var self=this; this.addEvent(this._doc, "mousedown", this.hideDiv); } //공백제거 editor.prototype.trim = function(s) { return s.replace(/^\s+|\s+$/g,''); } //상단버튼출력 editor.prototype.displayButton = function() { var str=order=""; var button=elm=null; var self=this; var arr=this._button; for(var i=0;i"+link_text+""; //doc.execCommand("CreateLink", false, this._linkText.value); self.innerHTML(html); break; case "color": case "hilite": case "font": case "size": case "link": var div=null; if(order=="color") { order = "forecolor"; this.colorTable(order); div=util._colorTable; } else if(order=="hilite") { order = "hilitecolor"; this.colorTable(order); div=util._colorTable; } else if(order=="font") { order = "fontname"; this.fontTable(); div=util._fontTable; } else if(order=="size") { order = "fontsize"; this.sizeTable(); div=util._sizeTable; } else if(order=="link") { order = "hyperlink"; this.setLink(); div = util._linkTable; this._linkText.value = "http://"; self.setSelection(); } util._editor = self; util.order = order; this.showDiv(div); break; case "source": if(self.mode=="editor") { self._text.value = self.getHtml(); self._iFrame.style.display = "none"; self._text.style.display = ""; button.src = this.imagePath+"/texthtml.gif"; button.onmouseout = null; self.mode="text"; this.focus(); } else if(self.mode=="text") { doc.body.innerHTML = self.getHtml(); self._text.style.display = "none"; self._iFrame.style.display = ""; button.src = this.imagePath+"/htmltext.gif"; button.onmouseout = function() { this.style.border="1px solid #ffffff";this.style.backgroundColor=""; }; self.mode="editor"; this.focus(); } break; case "preview": var winLeft = (screen.width-700)/2; var winTop = (screen.height-500)/2; var w=window.open("","preview","width="+screen.width+",height="+screen.height+",top="+winTop+",left="+winLeft+",status=1,scrollbars=1,resizable=1"); w.document.open(); w.document.write("" + ""+self.getHtml()+""); w.document.close(); break; case "table": this.newWindow(this.imagePath+"/table.html?id="+this._id,"table","400","220","no","no"); break; case "image": this.newWindow(this.imagePath+"/upfile.php?op=1&id="+this._id,"table","300","150","no","no"); break; case "media": this.newWindow(this.imagePath+"/upfile.php?op=0&id="+this._id,"table","300","150","no","no"); break; case "dirImg": this.newWindow("../Module/dirImg.php?id="+this._id,"table","800","400","no","yes"); break; default: if(order=="strike") order = "strikethrough"; else if(order=="ul1") order = "insertorderedlist"; else if(order=="ul2") order = "insertunorderedlist"; else if(order=="hr") order = "inserthorizontalrule"; else if(order=="clean") order = "removeformat"; else if(order=="save") order = "saveas"; else if(order=="all") order = "selectall"; else if(order=="sup") order = "superscript"; else if(order=="sub") order = "subscript"; else if(order=="del") order = "delete"; else if(order=="justify") order = "justifyfull"; else if(order=="center"||order=="left"||order=="right") order = "justify"+order; else if(order=="hilitecolor" && util.isIE) order = "backcolor"; doc.execCommand(order, false, value); break; } } //포커스 editor.prototype.focus = function() { if(this.mode=="text") this._text.focus(); else this._iFrame.contentWindow.focus(); } //Html가져오기 editor.prototype.getHtml = function() { var html = ""; var doc = this._doc; if(this.mode=="text") html = this._text.value; else { for(i in doc.links) { if(!doc.links[i].target) doc.links[i].target = "_blank"; } html = doc.body.innerHTML; } this.textarea.value = html; return html; } //선택영역 editor.prototype.setSelection = function() { var _iFrame=this._iFrame; var sel=null,range=null,html=""; if(this._doc.selection) { sel = this._doc.selection; range = sel.createRange(); html = range.htmlText; } else if(_iFrame.contentWindow.getSelection) { sel=_iFrame.contentWindow.getSelection(); if (typeof(sel)!="undefined") range=sel.getRangeAt(0); else range=this._doc.createRange(); if(sel.rangeCount > 0 && window.XMLSerializer) { html=new XMLSerializer().serializeToString(range.cloneContents()); } } this.sel = sel; this.range = range; this.sel_html = html; } //Html삽입 editor.prototype.innerHTML = function(html) { if(this.mode=="text") return; if(util.isIE) { this.range = this._doc.selection.createRange(); this.range.pasteHTML(html); } else { this._doc.execCommand("inserthtml", false, html); } } //레이어 상단위치값 editor.prototype.layerTop = function(el) { var top = el.offsetTop; var parent = el.offsetParent; while(parent) { top += parent.offsetTop; parent = parent.offsetParent; } return top; } //레이어 좌측위치값 editor.prototype.layerLeft = function(el) { var left = el.offsetLeft + 1; var parent = el.offsetParent; while(parent) { left += parent.offsetLeft; parent = parent.offsetParent; } return left; } //레이어 생성 editor.prototype.getDiv = function(id, html) { var div = document.createElement("div"); div.id = id; div.className = "editorDiv"; div.style.position = "absolute"; div.style.backgroundColor = "#f5f5f5"; div.style.display = "none"; div.style.border = "1px solid #ccc"; div.style.padding = "5px"; div.innerHTML = html; return div; } //레이어 뷰 editor.prototype.showDiv = function(div) { var button = util._editor.button; div.style.top= this.layerTop(button) + button.offsetHeight + "px"; div.style.left = this.layerLeft(button) + "px"; div.style.display=""; } //레이어 히든 editor.prototype.hideDiv = function() { arrTable = new Array("color","font","size","link"); for(var i=0; i"+txt+" ("+font[i]+")
"; } var div = this.getDiv("_fontTable",s); div.style.padding = "5px"; document.body.appendChild(div); util._fontTable = div; } //폰트사이즈 editor.prototype.sizeTable = function() { if(this._sizeTable) return; var size = new Array(8,10,12,14,18,24,36); var s=""; for(var i=0; i가나다라 ("+size[i]+")
"; } var div = this.getDiv("_sizeTable",s); div.style.padding = "5px"; document.body.appendChild(div); util._sizeTable = div; } //칼라데이블 editor.prototype.colorTable = function(order) { if(this._colorTable) return; var colSample = "가나다라마바"; var col_SelList1 = new Array('#008000','#993366','#CC9900','#9B18C1','#FF9900','#0000FF','#FF0000','#177FCD','#FF3399','#8E8E8E'); var col_SelList2 = new Array('#FFDAED','#FF0000','#99DCFF','#0000FF','#A6FF4D','#009966','#E4FF75','#8E8E8E','#E4E4E4','#333333'); var col= new Array(); col[0] = new Array("#ffffff","#e5e4e4","#d9d8d8","#c0bdbd","#a7a4a4","#8e8a8b","#827e7f","#767173","#5c585a","#000000"); col[1] = new Array("#fefcdf","#fef4c4","#feed9b","#fee573","#ffed43","#f6cc0b","#e0b800","#c9a601","#ad8e00","#8c7301"); col[2] = new Array("#ffded3","#ffc4b0","#ff9d7d","#ff7a4e","#ff6600","#e95d00","#d15502","#ba4b01","#a44201","#8d3901"); col[3] = new Array("#ffd2d0","#ffbab7","#fe9a95","#ff7a73","#ff483f","#fe2419","#f10b00","#d40a00","#940000","#6d201b"); col[4] = new Array("#ffdaed","#ffb7dc","#ffa1d1","#ff84c3","#ff57ac","#fd1289","#ec0078","#d6006d","#bb005f","#9b014f"); col[5] = new Array("#fcd6fe","#fbbcff","#f9a1fe","#f784fe","#f564fe","#f546ff","#f328ff","#d801e5","#c001cb","#8f0197"); col[6] = new Array("#e2f0fe","#c7e2fe","#add5fe","#92c7fe","#6eb5ff","#48a2ff","#2690fe","#0162f4","#013add","#0021b0"); col[7] = new Array("#d3fdff","#acfafd","#7cfaff","#4af7fe","#1de6fe","#01deff","#00cdec","#01b6de","#00a0c2","#0084a0"); col[8] = new Array("#edffcf","#dffeaa","#d1fd88","#befa5a","#a8f32a","#8fd80a","#79c101","#3fa701","#307f00","#156200"); col[9] = new Array("#d4c89f","#daad88","#c49578","#c2877e","#ac8295","#c0a5c4","#969ac2","#92b7d7","#80adaf","#9ca53b"); var s=""; s = "
"; for( i = 0 ; i < 10 ; i++ ) { //alert(order); if(order == 'hilitecolor') { s += ""; if( i % 2 ) s += ""; s += colSample if( i % 2 ) s += ""; s += ""; if( i % s ) s += "
"; } else { s += ""; s += ""; s += colSample s += ""; if( i % s ) s += "
"; } } for(var i=0; i<10; i++) { for(var j=0; j<10; j++) { color = col[i][j]; s += " "; } s += "
"; } s += "
"; var div = this.getDiv("colorTable",s); document.body.appendChild(div); util._colorTable = div; } //하이퍼링크 editor.prototype.setLink = function() { if(util._linkTable) return; var id = "_linkText"; var s = "

"; s += "링크주소(URL)를 입력하세요 "; var div = this.getDiv("_linkTable",s); div.style.padding = "15px"; div.style.font = "8pt 돋움"; document.body.appendChild(div); util._linkTable = div; this._linkText = document.getElementById(id); } //센터새창 editor.prototype.newWindow = function(mypage,myname,w,h,tool,scroll){ var winl = (screen.width-w)/2; var wint = (screen.height-h)/2; var settings ='height='+h+','; settings +='width='+w+','; settings +='top='+wint+','; settings +='left='+winl+','; settings +='toolbar='+tool+','; settings +='scrollbars='+scroll+','; settings +='resizable=no'; win=window.open(mypage,myname,settings); if(parseInt(navigator.appVersion) >= 4){win.window.focus();} } // editor.prototype.sendPost = function() { if(this._sendPost) return; var wint = (document.body.clientWidth-250)/2; var winl = (document.body.clientHeight-170)/2; var id = "_sendPost"; var s = ""; s += ""; s += "
데이터 전송중입니다.

"; s += "잠시만 기다려 주세요~
1~2분 초과시 [새로고침]후 재시도 바랍니다.
"; var div = this.getDiv("sendPost",s); div.style.padding = "15px"; div.style.font = "8pt 돋움"; div.style.top= wint; div.style.left = winl; div.style.filter = "alpha(opacity=80)"; div.style.display=""; document.body.appendChild(div); }