/******************************************************************************/ /* ÆÄ ÀÏ ¸í: /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); }