/** * @file common.js * @author zero (zero@nzeo.com) * @brief 몇가지 유용한 & 기본적으로 자주 사용되는 자바스크립트 함수들 모음 **/ /** * @brief location.href에서 특정 key의 값을 return **/ String.prototype.getQuery = function(key) { var idx = this.indexOf('?'); if(idx == -1) return null; var query_string = this.substr(idx+1, this.length); var args = {} query_string.replace(/([^=]+)=([^&]*)(&|$)/g, function() { args[arguments[1]] = arguments[2]; }); var q = args[key]; if(typeof(q)=="undefined") q = ""; return q; } /** * @brief location.href에서 특정 key의 값을 return **/ String.prototype.setQuery = function(key, val) { var idx = this.indexOf('?'); var uri = this; uri = uri.replace(/#$/,''); if(idx != -1) { uri = this.substr(0, idx); var query_string = this.substr(idx+1, this.length); var args = new Array(); query_string.replace(/([^=]+)=([^&]*)(&|$)/g, function() { args[arguments[1]] = arguments[2]; }); args[key] = val; var q_list = new Array(); for(var i in args) { if( !args.hasOwnProperty(i) ) continue; var arg = args[i]; if(!arg.toString().trim()) continue; q_list[q_list.length] = i+'='+arg; } uri = uri+"?"+q_list.join("&"); } else { if(val.toString().trim()) uri = uri+"?"+key+"="+val; } uri = uri.replace(/^https:\/\//i,'http://'); if(typeof(ssl_actions)!='undefined' && typeof(ssl_actions.length)!='undefined' && uri.getQuery('act')) { var act = uri.getQuery('act'); for(i=0;i'; html += ''; for(var name in params) { if(params[name] != 'undefined' && params[name] != '') { html += ''; } } html += '' + '' + ''; } else if(/\.flv/i.test(src)) { html = ''; } else { html = ''; } document.writeln(html); } /** * @brief 에디터에서 사용되는 내용 여닫는 코드 (고정, zbxe용) **/ function zbxe_folder_open(id) { var open_text_obj = xGetElementById("folder_open_"+id); var close_text_obj = xGetElementById("folder_close_"+id); var folder_obj = xGetElementById("folder_"+id); open_text_obj.style.display = "none"; close_text_obj.style.display = "block"; folder_obj.style.display = "block"; } function zbxe_folder_close(id) { var open_text_obj = xGetElementById("folder_open_"+id); var close_text_obj = xGetElementById("folder_close_"+id); var folder_obj = xGetElementById("folder_"+id); open_text_obj.style.display = "block"; close_text_obj.style.display = "none"; folder_obj.style.display = "none"; } /** * @brief 에디터에서 사용하되 내용 여닫는 코드 (zb5beta beta 호환용으로 남겨 놓음) **/ function svc_folder_open(id) { var open_text_obj = xGetElementById("_folder_open_"+id); var close_text_obj = xGetElementById("_folder_close_"+id); var folder_obj = xGetElementById("_folder_"+id); open_text_obj.style.display = "none"; close_text_obj.style.display = "block"; folder_obj.style.display = "block"; } function svc_folder_close(id) { var open_text_obj = xGetElementById("_folder_open_"+id); var close_text_obj = xGetElementById("_folder_close_"+id); var folder_obj = xGetElementById("_folder_"+id); open_text_obj.style.display = "block"; close_text_obj.style.display = "none"; folder_obj.style.display = "none"; } /** * @brief 팝업의 경우 내용에 맞춰 현 윈도우의 크기를 조절해줌 * 팝업의 내용에 맞게 크기를 늘리는 것은... 쉽게 되지는 않음.. ㅡ.ㅜ * popup_layout 에서 window.onload 시 자동 요청됨. **/ function setFixedPopupSize() { if(xGetElementById('popBody')) { if(xHeight('popBody')>500) { xGetElementById('popBody').style.overflowY = 'scroll'; xGetElementById('popBody').style.overflowX = 'hidden'; xHeight('popBody', 500); } } var w = xWidth("popup_content"); var h = xHeight("popup_content"); var obj_list = xGetElementsByTagName('div'); for(i=0;iw) w = ww; } // 윈도우에서는 브라우저 상관없이 가로 픽셀이 조금 더 늘어나야 한다. if(xUA.indexOf('windows')>0) { if(xOp7Up) w += 10; else if(xIE4Up) w += 10; else w += 6; } window.resizeTo(w,h); var h1 = xHeight(window.document.body); window.resizeBy(0,h-h1); window.scrollTo(0,0); } /** * @brief 이름, 게시글등을 클릭하였을 경우 팝업 메뉴를 보여주는 함수 **/ xAddEventListener(window, 'load', createPopupMenu); xAddEventListener(document, 'click', chkPopupMenu); var loaded_popup_menus = new Array(); /* 멤버 팝업 메뉴 레이어를 생성하는 함수 (문서 출력이 완료되었을때 동작) */ function createPopupMenu(evt) { var area = xGetElementById("popup_menu_area"); if(area) return; area = xCreateElement("div"); area.id = "popup_menu_area"; area.style.visibility = 'hidden'; area.style.zIndex = 9999; document.body.appendChild(area); } /* 클릭 이벤트 발생시 이벤트가 일어난 대상을 검사하여 적절한 규칙에 맞으면 처리 */ function chkPopupMenu(evt) { // 이전에 호출되었을지 모르는 팝업메뉴 숨김 var area = xGetElementById("popup_menu_area"); if(!area) return; if(area.style.visibility != "hidden") area.style.visibility = "hidden"; // 이벤트 대상이 없으면 무시 var e = new xEvent(evt); if(!e) return; // 대상의 객체 구함 var obj = e.target; if(!obj) return; // obj의 nodeName이 div나 span이 아니면 나올대까지 상위를 찾음 if(obj && obj.nodeName != 'DIV' && obj.nodeName != 'SPAN' && obj.nodeName != 'A') obj = obj.parentNode; if(!obj || (obj.nodeName != 'DIV' && obj.nodeName != 'SPAN' && obj.nodeName != 'A')) return; // 객체의 className값을 구함 var class_name = obj.className; if(!class_name) return; // className을 분리 var class_name_list = class_name.split(' '); var menu_id = ''; var menu_id_regx = /^([a-zA-Z]+)_([0-9]+)$/; for(var i=0,c=class_name_list.length;i0 ? e.pageX : GetObjLeft(obj); params["page_y"] = e.pageY >0 ? e.pageY : GetObjTop(obj)+ xHeight(obj); var response_tags = new Array("error","message","menus"); if(loaded_popup_menus[menu_id]) { displayPopupMenu(params, response_tags, params); return; } show_waiting_message = false; exec_xml(module_name, action_name, params, displayPopupMenu, response_tags, params); show_waiting_message = true; } function GetObjTop(obj) { if(obj.offsetParent == document.body) return xOffsetTop(obj); else return xOffsetTop(obj) + GetObjTop(obj.offsetParent); } function GetObjLeft(obj) { if(obj.offsetParent == document.body) return xOffsetLeft(obj); else return xOffsetLeft(obj) + GetObjLeft(obj.offsetParent); } function displayPopupMenu(ret_obj, response_tags, params) { var target_srl = params["target_srl"]; var menu_id = params["menu_id"]; var menus = ret_obj['menus']; var html = ""; if(loaded_popup_menus[menu_id]) { html = loaded_popup_menus[menu_id]; } else { if(menus) { var item = menus['item']; if(typeof(item.length)=='undefined' || item.length<1) item = new Array(item); if(item.length) { for(var i=0;i'+str+' '; } } } loaded_popup_menus[menu_id] = html; } // 레이어 출력 if(html) { var area = xGetElementById("popup_menu_area"); xInnerHtml(area, '
    '+html+'
'); xLeft(area, params["page_x"]); xTop(area, params["page_y"]); if(xWidth(area)+xLeft(area)>xClientWidth()+xScrollLeft()) xLeft(area, xClientWidth()-xWidth(area)+xScrollLeft()); if(xHeight(area)+xTop(area)>xClientHeight()+xScrollTop()) xTop(area, xClientHeight()-xHeight(area)+xScrollTop()); area.style.visibility = "visible"; } } /** * @brief 추천/비추천,스크랩,신고기능등 특정 srl에 대한 특정 module/action을 호출하는 함수 **/ function doCallModuleAction(module, action, target_srl) { var params = new Array(); params['target_srl'] = target_srl; params['cur_mid'] = current_mid; exec_xml(module, action, params, completeCallModuleAction); } function completeCallModuleAction(ret_obj, response_tags) { if(ret_obj['message']!='success') alert(ret_obj['message']); location.reload(); } function completeMessage(ret_obj) { alert(ret_obj['message']); location.reload(); } /** * @brief 날짜 선택 (달력 열기) **/ function open_calendar(fo_id, day_str, callback_func) { if(typeof(day_str)=="undefined") day_str = ""; var url = "./common/tpl/calendar.php?"; if(fo_id) url+="fo_id="+fo_id; if(day_str) url+="&day_str="+day_str; if(callback_func) url+="&callback_func="+callback_func; popopen(url, 'Calendar'); } /* 언어코드 (lang_type) 쿠키값 변경 */ function doChangeLangType(obj) { if(typeof(obj)=="string") { setLangType(obj); } else { var val = obj.options[obj.selectedIndex].value; setLangType(val); } location.reload(); } function setLangType(lang_type) { var expire = new Date(); expire.setTime(expire.getTime()+ (7000 * 24 * 3600000)); xSetCookie('lang_type', lang_type, expire); } /* 미리보기 */ function doDocumentPreview(obj) { var fo_obj = obj; while(fo_obj.nodeName != "FORM") { fo_obj = fo_obj.parentNode; } if(fo_obj.nodeName != "FORM") return; var editor_sequence = fo_obj.getAttribute('editor_sequence'); var content = editorGetContent(editor_sequence); var win = window.open("","previewDocument","toolbars=no,width=700px;height=800px,scrollbars=yes,resizable=yes"); var dummy_obj = xGetElementById("previewDocument"); if(!dummy_obj) { var fo_code = '
'+ ''+ ''+ ''+ '
'; var dummy = xCreateElement("DIV"); xInnerHtml(dummy, fo_code); window.document.body.insertBefore(dummy,window.document.body.lastChild); dummy_obj = xGetElementById("previewDocument"); } if(dummy_obj) { dummy_obj.content.value = content; dummy_obj.submit(); } } /* 게시글 저장 */ function doDocumentSave(obj) { var editor_sequence = obj.form.getAttribute('editor_sequence'); var prev_content = editorRelKeys[editor_sequence]['content'].value; if(typeof(editor_sequence)!='undefined' && editor_sequence && typeof(editorRelKeys)!='undefined' && typeof(editorGetContent)=='function') { var content = editorGetContent(editor_sequence); editorRelKeys[editor_sequence]['content'].value = content; } var oFilter = new XmlJsFilter(obj.form, "member", "procMemberSaveDocument", completeDocumentSave); oFilter.addResponseItem("error"); oFilter.addResponseItem("message"); oFilter.addResponseItem("document_srl"); oFilter.proc(); editorRelKeys[editor_sequence]['content'].value = prev_content; return false; } function completeDocumentSave(ret_obj) { xGetElementsByAttribute('input', 'name', 'document_srl')[0].value = ret_obj['document_srl']; alert(ret_obj['message']); } /* 저장된 게시글 불러오기 */ var objForSavedDoc = null; function doDocumentLoad(obj) { // 저장된 게시글 목록 불러오기 objForSavedDoc = obj.form; popopen(request_uri.setQuery('module','member').setQuery('act','dispSavedDocumentList')); } /* 저장된 게시글의 선택 */ function doDocumentSelect(document_srl) { if(!opener || !opener.objForSavedDoc) { window.close(); return; } // 게시글을 가져와서 등록하기 opener.location.href = opener.current_url.setQuery('document_srl', document_srl).setQuery('act', 'dispBoardWrite'); window.close(); } /* 스킨 정보 */ function viewSkinInfo(module, skin) { popopen("./?module=module&act=dispModuleSkinInfo&selected_module="+module+"&skin="+skin, 'SkinInfo'); } /* 체크박스 선택 */ function checkboxSelectAll(form, name, option){ var value; var fo_obj = xGetElementById(form); for ( var i = 0 ; i < fo_obj.length ; i++ ){ if(typeof(option) == "undefined") { var select_mode = fo_obj[i].checked; if ( select_mode == 0 ){ value = true; select_mode = 1; }else{ value = false; select_mode = 0; } } else if(option == true) value = true else if(option == false) value = false if(fo_obj[i].name == name) fo_obj[i].checked = value; } } /* 체크박스를 실행 */ function clickCheckBoxAll(form, name) { var fo_obj = xGetElementById(form); for ( var i = 0 ; i < fo_obj.length ; i++ ){ if(fo_obj[i].name == name) fo_obj[i].click(); } } /* 관리자가 문서를 관리하기 위해서 선택시 세션에 넣음 */ var addedDocument = new Array(); function doAddDocumentCart(obj) { var srl = obj.value; addedDocument[addedDocument.length] = srl; setTimeout(function() { callAddDocumentCart(addedDocument.length); }, 100); } function callAddDocumentCart(document_length) { if(addedDocument.length<1 || document_length != addedDocument.length) return; var params = new Array(); params["srls"] = addedDocument.join(","); exec_xml("document","procDocumentAdminAddCart", params, null); addedDocument = new Array(); } /* ff의 rgb(a,b,c)를 #... 로 변경 */ function transRGB2Hex(value) { if(!value) return value; if(value.indexOf('#') > -1) return value.replace(/^#/, ''); if(value.toLowerCase().indexOf('rgb') < 0) return value; value = value.replace(/^rgb\(/i, '').replace(/\)$/, ''); value_list = value.split(','); var hex = ''; for(var i = 0; i < value_list.length; i++) { var color = parseInt(value_list[i], 10).toString(16); if(color.length == 1) color = '0'+color; hex += color; } return hex; } /** * * Base64 encode / decode * http://www.webtoolkit.info/ * **/ var Base64 = { // private property _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", // public method for encoding encode : function (input) { var output = ""; var chr1, chr2, chr3, enc1, enc2, enc3, enc4; var i = 0; input = Base64._utf8_encode(input); while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4); } return output; }, // public method for decoding decode : function (input) { var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (i < input.length) { enc1 = this._keyStr.indexOf(input.charAt(i++)); enc2 = this._keyStr.indexOf(input.charAt(i++)); enc3 = this._keyStr.indexOf(input.charAt(i++)); enc4 = this._keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } } output = Base64._utf8_decode(output); return output; }, // private method for UTF-8 encoding _utf8_encode : function (string) { string = string.replace(/\r\n/g,"\n"); var utftext = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { utftext += String.fromCharCode(c); } else if((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); } } return utftext; }, // private method for UTF-8 decoding _utf8_decode : function (utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0; while ( i < utftext.length ) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i+1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; } } /* select - option의 disabled=disabled 속성을 IE에서도 체크하기 위한 함수 */ if(xIE4Up) { xAddEventListener(window, 'load', activateOptionDisabled); function activateOptionDisabled(evt) { var sels = xGetElementsByTagName('select'); for(var i=0; i < sels.length; i++){ var disabled_exists = false; var first_enable = new Array(); for(var j=0; j < sels[i].options.length; j++) { if(sels[i].options[j].disabled) { sels[i].options[j].style.color = '#CCCCCC'; disabled_exists = true; }else{ first_enable[i] = first_enable[i]>-1? first_enable[i] : j; } } if(!disabled_exists) continue; sels[i].oldonchange = sels[i].onchange; sels[i].onchange = function() { if(this.options[this.selectedIndex].disabled) { this.selectedIndex = first_enable[i]; /* if(this.options.length<=1) this.selectedIndex = -1; else if(this.selectedIndex < this.options.length - 1) this.selectedIndex++; else this.selectedIndex--; */ } else { if(this.oldonchange) this.oldonchange(); } } if(sels[i].selectedIndex >= 0 && sels[i].options[ sels[i].selectedIndex ].disabled) sels[i].onchange(); } } } /* 보안 로그인 모드로 전환 */ function toggleSecuritySignIn() { var href = location.href; if(/https:\/\//i.test(href)) location.href = href.replace(/^https/i,'http'); else location.href = href.replace(/^http/i,'https'); } /* 하위호환성 문제 */ if(typeof(resizeImageContents) == 'undefined') { function resizeImageContents() {} } function reloadDocument() { location.reload(); }