var selection = null; var exCommand; var agentName; var agentVersion var defaultFontSize = 2; var defaultFontFace = "굴림"; var defaultFontColor = "#000000"; var spaceID = 0; function getHTMLEditDocument() { var htmlEditDocument; if ($("htmlEdit").contentDocument) htmlEditDocument = $("htmlEdit").contentDocument; // 파이어폭스 else htmlEditDocument = htmlEdit.document; return htmlEditDocument } function getSelection() { var sel; if (getHTMLEditDocument().selection) { sel = getHTMLEditDocument().selection; } else { sel = $("htmlEdit").contentWindow.getSelection(); } return sel; } function getSelectionElement() { var element; if (Prototype.Browser.IE) { var range = getRange(); range.select(); element = range.parentElement(); } else { element = getSelection().anchorNode; } return element; } function getRange() { var rng; if (getHTMLEditDocument().selection) { rng = getSelection().createRange(); } else { rng = getSelection().getRangeAt(0); } return rng; } function getRangeText() { var txt; if (getRange().text) txt = getRange().text; else txt = getRange().toString(); return txt; } function preview() { var profile = getHTML(); var profileWindow = window.open("", "PREVIEW", "toolbar=no,menubar=no,resizeable=yes,status=no,width=500,height=500,scrollbars=yes"); profileWindow.document.write(""); profileWindow.document.write(" "); profileWindow.document.write(" "); profileWindow.document.write(" "); profileWindow.document.write(" "); profileWindow.document.write("
"); profileWindow.document.write(profile); profileWindow.document.write("
"); profileWindow.document.write("

"); profileWindow.document.write("
"); profileWindow.document.write("
"); profileWindow.document.write(" "); profileWindow.document.write(""); } function checkImgFormat(fileName) { var bReturn = false; var imgFormat = new Array ("jpg", "jpeg", "jpe", "gif", "png"); var extention = getFileExtention(fileName); for (i = 0; i < imgFormat.length; i++) { if (extention == imgFormat[i]) { bReturn = true; break; } } return bReturn; } function getFileExtention(fileName) { var extention = ""; try { extention = fileName.substring( fileName.lastIndexOf(".")+1 ).toLowerCase(); }catch(exception){} return extention; } function getUserAgent() { var userAgent = navigator.userAgent; userAgent = userAgent.substring( userAgent.indexOf(";")+2, userAgent.indexOf(";", userAgent.indexOf(";")+1) ); agentName = userAgent.substring(0, userAgent.indexOf(" ")); agentVersion = parseFloat(userAgent.substring(agentName.length+1)); } function initHTMLEdit(isSet) { try { if (SetOnloadDextUpload != null) SetOnloadDextUpload(); if (isSet==null || isSet==true) setDisplayForm();//공지사항 수정폼에서 사용하기 위해 if (SetOnloadEvent != null) SetOnloadEvent(); } catch (exception) {} getUserAgent(); setSystemFont(); setDesignMode(); setDescription(); } function topBodyScroll() { window.focus(); } function setSystemFont() { try { var fontOption = $("eFont"); fontOption.innerHTML = ""; for (i = 1; i < $("dlgHelper").fonts.count; i++) { var fontName = $("dlgHelper").fonts(i); var newOption = document.createElement("OPTION"); fontOption.appendChild(newOption); newOption.text = fontName; newOption.value = fontName; if (fontName == defaultFontFace) { newOption.selected = true; } } } catch(e) { //alert(e); var fontOption = $("eFont"); var newOption1 = document.createElement("OPTION"); fontOption.appendChild(newOption1); newOption1.text = "굴림"; newOption1.value = "굴림"; newOption1.selected = true; var newOption1 = document.createElement("OPTION"); fontOption.appendChild(newOption1); newOption1.text = "바탕"; newOption1.value = "바탕"; var newOption1 = document.createElement("OPTION"); fontOption.appendChild(newOption1); newOption1.text = "돋움"; newOption1.value = "돋움"; var newOption1 = document.createElement("OPTION"); fontOption.appendChild(newOption1); newOption1.text = "궁서"; newOption1.value = "궁서"; } $("eSize").selectedIndex = defaultFontSize; } function setDesignMode() { var header = ""; getHTMLEditDocument().designMode = "On"; getHTMLEditDocument().open("text/html"); getHTMLEditDocument().write(header); getHTMLEditDocument().close(); getHTMLEditDocument().body.style.background = "#ffffff"; getHTMLEditDocument().body.style.fontSize = "10pt"; getHTMLEditDocument().body.style.fontFamily = defaultFontFace; getHTMLEditDocument().onmouseup = checkFontValue; getHTMLEditDocument().onkeyup = checkFontValue; getHTMLEditDocument().body.innerHTML = "

"; } function getSelectionFontBackColor() { var returnColor; var element = getSelectionElement(); returnColor = getFontBackColor(element); return returnColor; } function getFontBackColor(element) { var returnColor; if (element == null || element.tagName == "P" || element.tagName == "BODY") { returnColor = defaultFontColor; } else if (element.tagName == "FONT" && element.style.backgroundColor != "") { returnColor = element.style.backgroundColor; } else { returnColor = getFontColor(element.parentElement); } return returnColor; } function getSelectionFontColor() { var returnColor; var element = getSelectionElement(); returnColor = getFontColor(element); return returnColor; } function getFontColor(element) { var returnColor; if (element == null || element.tagName == "P" || element.tagName == "BODY") { returnColor = defaultFontColor; } else if (element.tagName == "FONT" && element.color != "") { returnColor = element.color; } else { returnColor = getFontColor(element.parentElement); } return returnColor; } function getFontSize(element) { var returnSize; if (element.tagName == "FONT" && element.size != "") { returnSize = element.size; } else if (element.tagName == "P" || element.tagName == "BODY") { //returnSize = defaultFontSize; returnSize = 0; } else { //returnSize = getFontSize(element.parentElement); returnSize = 0; } return returnSize; } function getFontFace(element) { var returnFace; if (element.tagName == "FONT" && element.face != "") { returnFace = element.face; } else if (element.tagName == "P" || element.tagName == "BODY") { //returnFace = defaultFontFace; returnFace = ''; } else { //returnFace = getFontFace(element.parentElement); returnFace = ''; } return returnFace; } function checkFontValue() { try { // var selection = getHTMLEditDocument().selection; // var range = selection.createRange(); // range.select(); // var element = range.parentElement(); var element = getSelectionElement(); $("eSize").selectedIndex = getFontSize(element); var fontFace = getFontFace(element); if (fontFace != '') { $("eFont").value = fontFace; } } catch(e) { } } function showColorDialog(initColor) { if (initColor == null) { var sColor = $("dlgHelper").choosecolordlg(); } else { var sColor = $("dlgHelper").choosecolordlg(initColor); } sColor = sColor.toString(16); if (sColor.length < 6) { var sTempString = "000000".substring(0, 6-sColor.length); sColor = sTempString.concat(sColor); } return sColor; } function editCommand(cmd, value, clickedObj) { if ( cmd != "" && value != "" ) { // selection = getHTMLEditDocument().selection.createRange(); exCommand = cmd; if (cmd == "ForeColor") { if (agentName == "MSIE" && agentVersion >= 6) { if (getRangeText().length > 0) { executeCommand(cmd, "", showColorDialog(getSelectionFontColor())); } } else { showColorTable(clickedObj, getSelectionFontColor()); // $("colorTable").style.display = ""; } } else if (cmd == "BackColor") { if (agentName == "MSIE" && agentVersion >= 6) { // if (selection.text.length > 0) if (getRangeText().length > 0) { executeCommand(cmd, "", showColorDialog(getSelectionFontBackColor())); } } else { showColorTable(clickedObj, getSelectionFontBackColor()); // $("colorTable").style.display = ""; } } // else if (cmd == "PageColor") // { // if (agentName == "MSIE" && agentVersion >= 6) // { // getHTMLEditDocument().body.style.background = showColorDialog(getHTMLEditDocument().body.style.background); // } // else // { // $("colorTable").style.display = ""; // } // } else if (cmd == "AddImage") { var addImageWND = window.open("/Common/HTMLImageFromFotoya.aspx", "IMAGE", "toolbar=no,menubar=no,resizeable=1,status=1,width=450,height=500,scrollbars=1"); } else if (cmd == "AddMedia") { var addMediaWND = window.open("/Common/HTMLMediaLink.htm", "MediaLink", "toolbar=no,menubar=no,resizeable=yes,status=no,width=450,height=320,scrollbars=1"); } else if (cmd == "CreateLink") { //if (selection.text.length > 0) var range = getRange(); if (range != null) { executeCommand(cmd, 1, value); // if (range.parentElement().tagName == "A") // { // range.parentElement().target = "_blank"; // } // else if (range.parentElement().tagName == "IMG") // { // if (range.parentElement().parentElement.tagName == "A") // { // range.parentElement().parentElement.target = "_blank"; // } // } if (getSelectionElement().tagName == "A") { getSelectionElement().target = "_blank"; } else if (getSelectionElement().tagName == "IMG") { if (getSelectionElement().parentElement.tagName == "A") { getSelectionElement().parentElement.target = "_blank"; } } } else { alert('링크할 부분을 선택하세요.'); } } else { executeCommand(cmd, '', value); } } } function resizeAddedImageWidth(imgElement, maxWidth) { if (imgElement != null) { if (imgElement.width > maxWidth) { var newWidth = maxWidth; var newHeight = (imgElement.height * newWidth) / imgElement.width; imgElement.style.width = newWidth; imgElement.style.height = newHeight; } } } function executeCommandAddImage(imgPath, width, height, imgText) { if (width > 350) { width = 350; } var imgAlign = "align='bottom'"; var imgTag = ""; getHTMLEditDocument().body.innerHTML = getHTMLEditDocument().body.innerHTML + "
" + imgTag + "
" + imgText + "
"; } function executeCommand(cmd, uinterface, value) { // if (cmd == "PageColor") // { // getHTMLEditDocument().body.style.background = value; // } // else if (cmd == "PageImage") // { // getHTMLEditDocument().body.style.background = "url("+value+")"; // } // else if (cmd == "AddImage" || cmd == "AddFotoyaImage") { var imgWidth = ""; // var imgAlign = ""; // if (uinterface == "left" || uinterface == "right") // { // imgAlign = "align='" + uinterface + "'"; // } var imgTag = ""; //imgTag = ""; var imgName = "tmpImage"; if (cmd == "AddFotoyaImage") { imgName = "fotoyaImage"; } if (typeof(value) == "string") { imgTag = "

"; } else { for (var i = 0; i < value.length; i++) { if (i > 0) imgTag += "

"; imgTag += "

"; } } if (uinterface == "top") { getHTMLEditDocument().body.innerHTML = imgTag + "
" + getHTMLEditDocument().body.innerHTML; } else if (uinterface == "bottom") { getHTMLEditDocument().body.innerHTML = getHTMLEditDocument().body.innerHTML + "
" + imgTag; } else { // if (selection.parentElement().all.htmlEdit == null) if (getSelectionElement().all.htmlEdit == null) { if (getSelectionElement().outerHTML.indexOf(' 0) { // htmlEdit 내부 getSelectionElement().innerHTML = imgTag + "
" + getSelectionElement().innerHTML; } else { // htmlEdit 외부 getHTMLEditDocument().body.innerHTML = imgTag + getHTMLEditDocument().body.innerHTML; } } else { // htmlEdit 외부 getHTMLEditDocument().body.innerHTML = imgTag + getHTMLEditDocument().body.innerHTML; } } } else if (cmd == 'AddMedia') { var sourceInfo = ""; if (uinterface.length > 0) { sourceInfo = "

<출처 : " + uinterface + ">"; } if (checkImgFormat(value)) { var imgWidth = ""; /* var imgWidth = null; var tempImg = new Image(); tempImg.src = value; if (tempImg.width > 550) { imgWidth = 550; } else { imgWidth = tempImg.width; } */ //var mediaTag = "
" + sourceInfo + "
"; var mediaTag = "
" + sourceInfo + "
"; } else { var mediaTag = "
" + sourceInfo + "
"; } getHTMLEditDocument().body.innerHTML = getHTMLEditDocument().body.innerHTML + mediaTag; } else { switch (cmd) { case "BackColor" : if (Prototype.Browser.Gecko) cmd = "HiliteColor"; break; case "CreateLink" : if (!Prototype.Browser.IE) { value = prompt("URL을 입력하세요"); uinterface = false; } break; } // if (getSelection() != null) // { // getSelection().select(); // } getSelectionElement(); getHTMLEditDocument().execCommand(cmd, uinterface, value); } hideFloatLayer(); // $("colorTable").style.display = "none"; } function getAttachHTMLFileList() { var elements = getHTMLEditDocument().getElementsByName("tmpImage"); var tmpImages = new Array(); var imgIndex = 0; for (i = 0; i < elements.length; i++) { if (elements[i].src.indexOf("ImageView.aspx") < 0) { tmpImages[imgIndex] = elements[i].src; imgIndex++; } } return tmpImages; } function getHTMLFileList() { var elements = getHTMLEditDocument().getElementsByName("tmpImage"); var tmpImages = new Array(elements.length); for (i = 0; i < elements.length; i++) { tmpImages[i] = elements[i].src; } return tmpImages; } function getLinkImageList() { var elements = getHTMLEditDocument().getElementsByName("linkImage"); var tmpImages = new Array(elements.length); for (i = 0; i < elements.length; i++) { tmpImages[i] = elements[i].src; } return tmpImages; } function setDescription() { // getHTMLEditDocument().body.innerHTML = ""; var textWindowObj = document.getElementById("textWindow"); if (textWindowObj != null) { getHTMLEditDocument().body.innerHTML = textWindowObj.value; } } function getHTML() { return getHTMLEditDocument().body.innerHTML; } function getTEXT() { // return getHTMLEditDocument().body.innerText; return getInnerText(getHTMLEditDocument().body); } function setHTML(bodyHTML, documentStyle) { var header = ""; if (documentStyle == "" || documentStyle == null || documentStyle.replace(/ /g).length < 1) header = ""; else header = ""; getHTMLEditDocument().designMode = "On"; getHTMLEditDocument().open("text/html"); getHTMLEditDocument().write(header); getHTMLEditDocument().close(); getHTMLEditDocument().body.style.background = "#ffffff"; getHTMLEditDocument().body.style.fontSize = "10pt"; getHTMLEditDocument().body.style.fontFamily = defaultFontFace; getHTMLEditDocument().onmouseup = checkFontValue; getHTMLEditDocument().onkeyup = checkFontValue; getHTMLEditDocument().body.innerHTML = bodyHTML; //getHTMLEditDocument().createStyleSheet("javascript:'"+" "+"'"); } function setFont(value) { editCommand('FontName', value); if (getHTMLEditDocument().contentWindow) getHTMLEditDocument().contentWindow.focus(); else $("htmlEdit").focus(); } function setFontSize(value) { editCommand('FontSize', value); if (getHTMLEditDocument().contentWindow) getHTMLEditDocument().contentWindow.focus(); else $("htmlEdit").focus(); } var _divFloatLayer; function showColorTable(clickedObj, initColor) { showFloatLayer(clickedObj); var colorTable = " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + "
        
        
[닫기]
"; _divFloatLayer.innerHTML = colorTable; _divFloatLayer.style.display = ""; } function showFloatLayer(clickedObj, offsetWidth, offsetHeight) { if (offsetWidth == null) offsetWidth = 0; if (offsetHeight == null) offsetHeight = 0; if (_divFloatLayer == null) { _divFloatLayer = document.createElement("DIV"); _divFloatLayer.style.position = "absolute"; _divFloatLayer.style.zIndex = 1000; document.body.appendChild(_divFloatLayer); } _divFloatLayer.style.top = (getObjectTop(clickedObj) + offsetHeight) +"px"; _divFloatLayer.style.left = (getObjectLeft(clickedObj) + offsetWidth) +"px"; _divFloatLayer.innerHTML = ""; _divFloatLayer.style.display = "none"; } function hideFloatLayer() { if (_divFloatLayer != null && _divFloatLayer.style.display == "") { _divFloatLayer.style.display = "none"; } } function getObjectTop(clickedObj) { var top = 0; var tmpObj = clickedObj; while (tmpObj.tagName != "BODY") { top += tmpObj.offsetTop; tmpObj = tmpObj.offsetParent; } top += clickedObj.offsetHeight; return top; } function getObjectLeft(clickedObj) { var left = 0; var tmpObj = clickedObj; while (tmpObj.tagName != "BODY") { left += tmpObj.offsetLeft; tmpObj = tmpObj.offsetParent; } return left; }