/** * @class LENSVil * * @date 2009-06-19 * * @modify 2009-11-06 * * @author Kim Jung Yong */ var isIE, isIE6, isIE7, isIE8, isOP, isFF, isSA, isChr; var LENSVil = { allMethods : [], globalMethods : [ 'getElmsByTag', 'getElmsByClass', 'getElmsByAttr', 'getTextNode' ], Initialize : function(){ this.applyMethod.call(window, 'getElm', this.getElm); this.applyMethod.call(window, 'getChildNodes', this.getChildNodes); this.applyMethod.call(window, 'DOCBODY', this.DOCBODY); this.attach(this); this.setBrowser(); }, attach : function(object){ var globalMethods = object.globalMethods || 'undefined'; if(typeof globalMethods == 'undefined'){ for(var m in object){ if(typeof m != 'function' && m != 'init'){ this.applyMethod.call(this.allMethods, m, object[m]); } } }else if(globalMethods.constructor == Array){ for(var i=0; (m=globalMethods[i]); i++){ this.applyMethod.call(this.allMethods, m, object[m]); } } if(typeof object.init == 'function'){ object.init(); } }, addMethodToElm : function(elm){ for(var method in this.allMethods){ if(typeof this.allMethods[method] == 'function'){ this.applyMethod.call(elm, method, this.allMethods[method]); } } }, applyMethod : function(method, func){ if(typeof this[method] != 'function'){ //Prototype ½ÊÀå»ýÀÌ array °´Ã¼¿¡ prototype À» ¼±¾ðÇØ³ö¼­ ¿¹¿Üó¸® ÇÔ. try{ this[method] = func; }catch(e){} } }, setBrowser : function(){ var ua = navigator.userAgent.toLowerCase(); isIE = (ua.indexOf('msie') != -1); isIE6 = (ua.indexOf('msie 6.0') != -1); isIE7 = (ua.indexOf('msie 7.0') != -1); isIE8 = (ua.indexOf('msie 8.0') != -1); isOP = (ua.indexOf('opera') != -1); isFF = (ua.indexOf('firefox') != -1); isSA = (ua.indexOf('safari') != -1); isChr = (ua.indexOf('chrome') != -1); }, /** * @brief Ŭ·¡½º Á¤ÀÇ * @param (string) name * @param (json) context */ defineClass : function(name, context){ this[name] = context; }, /** * @brief ¹®¼­ÀÇ body¿¤¸®¸ÕÆ®¸¦ ¹ÝȯÇÕ´Ï´Ù. * @param (object) doc * @return object */ DOCBODY : function(){ var doc = arguments[0] || document; return getElm(doc.body) || getElm(doc.documentElement); }, /** * @brief °Ë»öµÈ ¿¤¸®¸ÕÆ® ¹Ýȯ * @param (mixed) obj * @param (object) doc * @return object */ getElm : function(){ var obj = arguments[0]; var doc = arguments[1] || document; if(!obj) return null; if(typeof obj == 'object' && obj.tagName){ LENSVil.addMethodToElm(obj); return obj; } if(typeof obj == 'string'){ if(!doc.getElementById(obj)) return null; obj = doc.getElementById(obj); LENSVil.addMethodToElm(obj); return obj; } return null; }, /** * @brief ÀÚ½Ä ³ëµåµé ¹Ýȯ * @param (object) elm * @param (boolean) all true°ªÀÌ ¿Ã °æ¿ì ÅØ½ºÆ® ³ëµå±îÁö ¹Ýȯ * @return object */ getChildNodes : function(){ var elm = arguments[0]; var all = arguments[1] || false; var oChild = []; var tmp = elm.childNodes; for(var i=0; (oc = tmp[i]); i++){ if(all == true){ oChild.push(getElm(oc)); }else{ if(oc.nodeType == 1) oChild.push(getElm(oc)); } } if(oChild.length < 1) oChild = null; return oChild; }, /** * @brief ű׸íÀ» ÅëÇØ ¿¤¸®¸ÕÆ® °Ë»ö * @param (mixed) obj * @return object */ getElmsByTag : function(){ var obj = arguments[0] || '*'; if(typeof obj == 'object' && obj.length > 0){ for(var i=0; i]+>/ig; return this.innerHTML.replace(regEx, ""); } }; LENSVil.Initialize(); // // @class LENSVil.Dom Module // LENSVil.DOM = { _parent : LENSVil, globalMethods : [ 'createElm', 'appendElm', 'removeElm', 'replaceElm', 'setAttr', 'getAttr', 'nextElm', 'prevElm', 'firstChildElm', 'lastChildElm' ], /** * @brief ¿¤¸®¸ÕÆ® »ý¼º * @param (string) name * @param (json) attr * @param (string) context * @param (boolean) append * @param (object) doc * @return object */ createElm : function(name, attr, context, append, doc){ attr = attr || null; context = context || null; append = append || false; doc = doc || document; var obj = getElm(doc.createElement(name)); obj.setAttr(attr); if(context !== null){ obj.appendElm(context); } if(append === true) this.appendElm(obj); return obj; }, /** * @brief ¿¤¸®¸ÕÆ® Ãß°¡ (+innerHTML || appendChild) * @param (mixed) obj */ appendElm : function(obj){ if(typeof obj == 'object') this.appendChild(obj); else if(typeof obj == 'string') this.innerHTML += obj; }, /** * @brief ¿¤¸®¸ÕÆ® »èÁ¦ */ removeElm : function(){ if(typeof this.parentNode == 'object') this.parentNode.removeChild(this); }, /** * @brief ¿¤¸®¸ÕÆ® ±³Ã¼ * @param (mixed) newElm (number || object) - ¼ýÀÚ°¡ ¿À°Ô µÉ °æ¿ì ÇØ´ç À妽º¿¡ ÀÖ´Â Àڽijëµå¿Í ±³Ã¼ * @param (boolean) retOld - default set 'false' * @return object */ replaceElm : function(newElm, retOld){ retOld = retOld || false; if(typeof newElm == 'number'){ var tmp = getChildNodes(this.parentNode); if(typeof tmp[newElm] == 'undefined' || tmp[newElm] == this) return; var nextElm = this.nextSibling; var clone = tmp[newElm].cloneNode(true); if(nextElm){ this.parentNode.insertBefore(this, tmp[newElm]); this.parentNode.removeChild(tmp[newElm]); this.parentNode.insertBefore(clone, nextElm); }else{ this.parentNode.insertBefore(this, tmp[newElm]); this.parentNode.removeChild(tmp[newElm]); this.parentNode.appendChild(clone); } }else{ this.parentNode.replaceChild(newElm, this); } return retOld ? oldElm : getElm(newElm); }, /** * @brief ¼Ó¼º°ª ÁöÁ¤ * @param (mixed) data | name (ÀÎÀÚ°¡ ÇϳªÀÏ °æ¿ì´Â jsonµ¥ÀÌÅÍ, µÎ°³ÀÏ °æ¿ì´Â stringÀÌ ¿Í¾ßÇÔ) * @param (string) value */ setAttr : function(){ var data = null; if(typeof arguments[0] == 'object'){ data = arguments[0]; }else if(typeof arguments[0] == 'string'){ data = eval("({arguments[0] : arguments[1]})"); } for(var i in data){ this[i] = data[i]; } }, /** * @brief ¼Ó¼º°ª ¹Ýȯ * @param (string) name * @return mixed */ getAttr : function(){ var name = arguments[0]; return this.getAttribute(name) || null; }, /** * @brief ´ÙÀ½ ³ëµå¿¡ ÀÖ´Â ¿¤¸®¸ÕÆ® ¹Ýȯ * @return object */ nextElm : function(){ var elm = this; while ((elm = elm.nextSibling) && elm.nodeType !== 1) {} return getElm(elm || null); }, /** * @brief ÀÌÀü ³ëµå¿¡ ÀÖ´Â ¿¤¸®¸ÕÆ® ¹Ýȯ * @return object */ prevElm : function(){ var elm = this; while ((elm = elm.previousSibling) && elm.nodeType !== 1) {} return getElm(elm || null); }, /** * @brief ù¹øÂ° ÀÚ½Ä ¿¤¸®¸ÕÆ® ¹Ýȯ * @param (string) tagName (ÀÎÀÚ°¡ µé¾î¿À¸é ÇØ´ç ÅÂ±×¿Í ¸ÅÄ¡ÇÔ) * @return object */ firstChildElm : function(tagName){ tagName = tagName || null; var elm = this.getElmsByTag(tagName)[0]; return elm; }, /** * @brief ÀÌÀü ³ëµå¿¡ ÀÖ´Â ¿¤¸®¸ÕÆ® ¹Ýȯ * @param (string) tagName (ÀÎÀÚ°¡ µé¾î¿À¸é ÇØ´ç ÅÂ±×¿Í ¸ÅÄ¡ÇÔ) * @return object */ lastChildElm : function(tagName){ tagName = tagName || null; var elm = this.getElmsByTag(tagName); elm = elm[elm.length-1]; return elm; } }; LENSVil.attach(LENSVil.DOM); // // @class LENSVil.CSS Module // LENSVil.CSS = { _parent : LENSVil, globalMethods : [ 'addClass', 'removeClass', 'replaceClass', 'hasClass', 'setStyle', 'getStyle' ], /** * @brief Ŭ·¡½º Ãß°¡ * @param (string) className */ addClass : function(className){ if(this.hasClass(className) === false){ isSetClass = this.className ? true : false; this.className = this.className + (isSetClass ? " " : '') + className; } }, /** * @brief Ŭ·¡½º Á¦°Å * @param (string) className */ removeClass : function(className){ if(this.hasClass(className)){ var reg = new RegExp("(^|\\s)"+className+"(\\s|$)", "i"); this.className = this.className.replace(reg, ''); } }, /** * @brief Ŭ·¡½º ±³Ã¼ * @param (string) newClass * @param (string) oldClass */ replaceClass : function(newClass, oldClass){ if(this.hasClass(oldClass)){ var reg = new RegExp("\\b"+oldClass+"\\b", "i"); this.className = this.className.replace(reg, newClass); } }, /** * @brief Ŭ·¡½º Á¸Àç¿©ºÎ ÆÄ¾Ç * @param (string) className */ hasClass : function(className){ var reg = new RegExp("\\b"+className+"\\b", "i"); if(this.className.search(reg) != -1) return true; else return false; }, /** * @brief ½ºÅ¸ÀÏ ÁöÁ¤ * @param (string) styles */ setStyle : function(styles){ if(typeof styles != 'string') return; if(isIE){ this.style.setAttribute('cssText', styles); }else{ this.setAttribute('style', styles); } }, /** * @brief ÇØ´ç ¿¤¸®¸ÕÆ®¿¡ ÀζóÀÎÀ¸·Î ÁöÁ¤µÈ ½ºÅ¸ÀÏ ¹Ýȯ */ getStyle : function(){ if(this && this.style && this.style.cssText) return this.style.cssText; else return ''; } }; LENSVil.attach(LENSVil.CSS); // // @class LENSVil.Content Module // @brief Àü¿ª ¸â¹ö·Î Ȱµ¿ÇÏ´Â ¸Þ¼­µåµé.(´Üµ¶ »ç¿ë) // LENSVil.Content = { _parent : LENSVil, init : function(){ this._parent.applyMethod.call(window, 'exit', this.exit); this._parent.applyMethod.call(window, 'winOpen', this.winOpen); this._parent.applyMethod.call(window, 'winOpenPost', this.winOpenPost); this._parent.applyMethod.call(window, 'getByte', this.getByte); this._parent.applyMethod.call(window, 'getCoordiCenterByScr', this.getCoordiCenterByScr); this._parent.applyMethod.call(window, 'getCoordiCenterByDoc', this.getCoordiCenterByDoc); this._parent.applyMethod.call(window, 'getClientHeight', this.getClientHeight); this._parent.applyMethod.call(window, 'getClientWidth', this.getClientWidth); this._parent.applyMethod.call(window, 'getBodyHeight', this.getBodyHeight); this._parent.applyMethod.call(window, 'getBodyWidth', this.getBodyWidth); this._parent.applyMethod.call(window, 'getScrollTop', this.getScrollTop); this._parent.applyMethod.call(window, 'getScrollLeft', this.getScrollLeft); this._parent.applyMethod.call(window, 'getElmCoordi', this.getElmCoordi); this._parent.applyMethod.call(window, 'getURLArgs', this.getURLArgs); this._parent.applyMethod.call(window, 'getURLtail', this.getURLtail); this._parent.applyMethod.call(window, 'getMetaText', this.getMetaText); this._parent.applyMethod.call(window, 'removeGetArgs', this.removeGetArgs); this._parent.applyMethod.call(window, 'setCookie', this.setCookie); this._parent.applyMethod.call(window, 'getCookie', this.getCookie); this._parent.applyMethod.call(window, 'rmCookie', this.rmCookie); this._parent.applyMethod.call(window, 'trim', this.trim); this._parent.applyMethod.call(window, 'htmlspecialchars', this.htmlspecialchars); this._parent.applyMethod.call(window, 'getHtmlTranslationTable', this.getHtmlTranslationTable); this._parent.applyMethod.call(window, 'stripTags', this.stripTags); this._parent.applyMethod.call(window, 'jsonEncode', this.jsonEncode); this._parent.applyMethod.call(window, 'jsonDecode', this.jsonDecode); }, /** * @brief EXIT */ exit : function(){ if(window.addEventListener){ window.addEventListener('error', function(e){ e.preventDefault(); e.stopPropagation(); }, false); }else if(window.attchEvent){ window.attachEvent('onerror', function(e){ e.returnValue = false; e.cancelBubble = true; }); } if(window.stop) window.stop(); throw ''; }, /** * @brief À©µµ¿ì ¿ÀÇ (GET) */ winOpen : function(){ var url = arguments[0].url; var height = arguments[0].height ? arguments[0].height : null; var width = arguments[0].width ? arguments[0].width : null; var top = arguments[0].top ? arguments[0].top : null; var left = arguments[0].left ? arguments[0].left : null; var name = arguments[0].name ? arguments[0].name : 'openWindow'; if(top == null) top = 50; if(left == null) left = 200; var opt = "width="+width+",height="+height+",status=no,resizable=yes,scrollbars=no,menubar=no,location=no,top="+top+",left="+left; var openWin = window.open(url, name, opt); return openWin; }, /** * @brief À©µµ¿ì ¿ÀÇ (POST) */ winOpenPost : function(){ var url = arguments[0].url; var height = arguments[0].height ? arguments[0].height : null; var width = arguments[0].width ? arguments[0].width : null; var top = arguments[0].top ? arguments[0].top : null; var left = arguments[0].left ? arguments[0].left : null; var name = arguments[0].name ? arguments[0].name : 'openWindow'; var postData = arguments[1] || null; if(top == null) top = 50; if(left == null) left = 200; var opt = "width="+width+",height="+height+",status=no,resizable=yes,scrollbars=no,menubar=no,location=no,top="+top+",left="+left; if(top == null) top = 50; if(left == null) left = 200; var openWin = window.open('', name, opt); var targetForm = DOCBODY().createElm('form', { id : 'LENSVil_openForm', name : 'LENSVil_openForm', method :'post', target : name, action : url }, null, true); if(postData !== null){ for(var i in postData){ targetForm.createElm('input', { type : 'hidden', name : i, value : postData[i] }, null, true); } } targetForm.submit(); return openWin; }, /** * @brief ¹ÙÀÌÆ® °è»ê */ getByte : function(str){ var encode = encodeURIComponent(str); var totalBytes = 0; var chr; var bytes; var code; for(var i = 0; i < encode.length; i++) { chr = encode.charAt(i); if(chr != "%") totalBytes++; else { code = parseInt(encode.substr(i+1,2),16); if(!(code & 0x80)) totalBytes++; else { if((code & 0xE0) == 0xC0) bytes = 2; else if((code & 0xF0) == 0xE0) bytes = 3; else if((code & 0xF8) == 0xF0) bytes = 4; else return -1; i += 3 * (bytes - 1); if(document.charset == "utf-8") totalBytes += bytes; else totalBytes += 2; } i += 2; } } return totalBytes; }, /** * @brief È­¸éÀÇ Áß¾Ó¿¡ À§Ä¡ ÇÒ¼ö ÀÖµµ·Ï Çϴ âÀÇ ÁÂÇ¥°ªÀ» ¹Ýȯ * @param int w (â °¡·Î) * @param int h (â ¼¼·Î) * @return array(x, y); */ getCoordiCenterByScr : function(w, h){ var result = []; var _scrWidth = window.screen.availWidth; var _srcHeight = window.screen.availHeight; var centerX = _scrWidth / 2; var centerY = _srcHeight / 2; var halfW = w / 2; var halfH = h / 2; var x = centerX - halfW; var y = centerY - halfH; result.x = parseInt(x); result.y = parseInt(y); return result; }, /** * @brief ¹®¼­ Áß¾Ó¿¡ À§Ä¡ ÇÒ ¼ö ÀÖµµ·Ï ÇÏ´Â ¿¤¸®¸ÕÆ®ÀÇ ÁÂÇ¥°ª ¹Ýȯ * @param int w(´ë»ó °¡·Î) * @param int h(´ë»ó ¼¼·Î) * @return array(x, y); */ getCoordiCenterByDoc : function(w, h){ var result = []; var _docWidth = getClientWidth(); var _docHeight = getClientHeight(); var centerX = _docWidth / 2; var centerY = _docHeight / 2; var halfW = w / 2; var halfH = h / 2; var x = centerX - halfW; var y = centerY - halfH; result.x = parseInt(x); result.y = parseInt(y); return result; }, /** * @brief º¸ÀÌ´Â ºÎºÐÀÇ ¹®¼­³ôÀÌ */ getClientHeight : function(){ var win = arguments[0] ? arguments[0] : window; var doc = arguments[0] ? win.document : document; var h=0; if(doc.compatMode == 'CSS1Compat' && !isOP && doc.documentElement && doc.documentElement.clientHeight) h=doc.documentElement.clientHeight; else if(doc.body && doc.body.clientHeight) h=doc.body.clientHeight; else if(xDef(win.innerWidth,win.innerHeight,doc.width)) { h=win.innerHeight; if(doc.width>win.innerWidth) h-=16; } return h; }, /** * @brief º¸ÀÌ´Â ºÎºÐÀÇ ¹®¼­Æø */ getClientWidth : function(){ var win = arguments[0] ? arguments[0] : window; var doc = arguments[0] ? win.document : document; var w=0; if(doc.compatMode == 'CSS1Compat' && !isOP && doc.documentElement && doc.documentElement.clientWidth) w=doc.documentElement.clientWidth; else if(doc.body && doc.body.clientWidth) w=doc.body.clientWidth; else if(xDef(win.innerWidth,win.innerHeight,doc.height)) { w=win.innerWidth; if(doc.height>win.innerHeight) w-=16; } return w; }, /** * @brief ¹®¼­ Àüü ³ôÀÌ */ getBodyHeight : function(){ var win = arguments[0] ? arguments[0] : window; var doc = arguments[0] ? win.document : document; var ch = getClientHeight(win); var sh = doc.body.scrollHeight; return ch>sh?ch:sh; }, /** * @brief ¹®¼­ Àüü °¡·Î */ getBodyWidth : function(){ var win = arguments[0] ? arguments[0] : window; var doc = arguments[0] ? win.document : document; var cw = getClientWidth(win); var sw = doc.body.scrollWidth; return cw>sw?cw:sw; }, /** * @brief ÇöÀç ¼¼·Î ½ºÅ©·Ñ À§Ä¡ */ getScrollTop : function(){ if(document.documentElement && document.documentElement.scrollTop) return document.documentElement.scrollTop; else return document.body.scrollTop; }, /** * @brief ÇöÀç °¡·Î ½ºÅ©·Ñ À§Ä¡ */ getScrollLeft : function(){ if(document.documentElement && document.documentElement.scrollLeft) return document.documentElement.scrollLeft; else return document.body.scrollLeft; }, /** * @brief ÇØ´ç ¿¤¸®¸ÕÆ®ÀÇ ¹®¼­»ó ÁÂÇ¥°ªÀ» ¹Ýȯ */ getElmCoordi : function(elm){ if( typeof(elm) != 'string' && typeof(elm) != 'object' ) return; if( typeof(obj) == 'string' ) elm = getElm(elm); var parent = elm.offsetParent; var result = {}; result.top = elm.offsetTop + elm.offsetHeight; result.left = elm.offsetLeft; while(parent){ result.top += parent.offsetTop; result.left += parent.offsetLeft; parent = parent.offsetParent; } return result; }, /** * @brief urlÄõ¸®¸¦ ¹è¿­·Î ¹Ýȯ * @param (string) args * @return json */ getURLArgs : function(){ var getArgs = []; var args = (arguments[0] || location.search).replace(/\?/, '').split('&'); for(var i=0; (arg=args[i]); i++){ var tmp = arg.split('='); getArgs[tmp[0]] = tmp[1] || ''; } return getArgs; }, /** * @brief urlÁÖ¼ÒÀÇ ÆÄÀϸí°ú Äõ¸®ºÎºÐ¸¸ ¹®ÀÚ¿­·Î ¹Ýȯ * @return string (menu.php?component=aaaaa) */ getURLtail : function(){ var url = location.href; var idx = url.lastIndexOf('/'); if(idx == -1) return ''; return url.substr(idx+1); }, /** * @brief Á¤±Ô½Ä ¹®ÀÚ¸¦ escape ½ÃŲ °ªÀ» ¹Ýȯ. * @param (string) str * @return string */ getMetaText : function(){ var str = arguments[0]; var result = ''; for(var i = 0; i < str.length; i++){ if((/([\$\(\)\*\+\.\[\]\?\\\^\{\}\|]{1})/).test(str.charAt(i))){ result += str.charAt(i).replace((/([\$\(\)\*\+\.\[\]\?\\\^\{\}\|]{1})/), "\\$1"); }else{ result += str.charAt(i); } } return result; }, /** * @brief URLÁÖ¼ÒÇü½ÄÀÇ ¹®ÀÚ¿­¿¡¼­ get°ªÀ¸·Î ³Ñ¾î¿Â °ªÀ» ¹®ÀÚ¿­¿¡¼­ »èÁ¦½ÃÄÑÁØ´Ù. * @param (string) url * @param (string) name * @return string */ removeGetArgs : function(url, name){ var reg = new RegExp("([&|?])("+name+"=[^&]+)", "ig"); //@brief &name=aaa ³ª ?name=aaa ¿ä·±½ÄÀÇ ¹®ÀÚ¿­À» ã¾Æ³½´Ù. var reg_a = new RegExp("\\?&", "ig"); var reg_b = new RegExp("(\\?$|&$)", "ig"); url = url.replace(reg, "$1"); url = url.replace(reg_a, "?"); url = url.replace(reg_b, ""); return url; }, /** * @brief Äí۱Á±â * @param (string) name Äí۸í * @param (string) value Äí۰ª * @param (int) expire À¯È¿±â°£(ÀϱâÁØ) * @param (string) path À¯È¿ÆÐ¾² * @param (string) domain À¯È¿µµ¸ÞÀÎ * @param (boolean) secure ÄíŰ Çã¿ë ÇÁ·ÎÅäÄÝ ÁöÁ¤(trueÀÏ °æ¿ì https³ª ±âŸ º¸¾È ÇÁ·ÎÅäÄݸ¸ Äí۸¦ »ç¿ëÇÒ¼ö ÀÖÀ½) */ setCookie : function(name, value, expire, path, domain, secure){ var cookie = name + '=' + encodeURIComponent(value); if(expire || expire == 0){ cookie += '; max-age=' + (expire * 24 * 60 * 60); } if(path) cookie += '; path=' + path; if(domain) cookie += '; domain=' + domain; if(secure) cookie += '; secure'; document.cookie = cookie; }, /** * @brief Äí۰ªÀ» ¹Ýȯ * @param (string) name */ getCookie : function(name){ var allcookie = document.cookie; if(allcookie === '') return; var cookie = null; var cookies = allcookie.split(';'); for(var i=0; i < cookies.length; i++){ var tmp = cookies[i].split('='); if(trim(tmp[0]) == trim(name)){ cookie = trim(tmp[1]); break; } } if(cookie == null) return; return decodeURIComponent(cookie); }, /** * @brief ÄíŰ Á¦°Å */ rmCookie : function(name, path, domain, secure){ setCookie(name, '', 0, path, domain, secure); }, /** * @brief ¹®ÀÚ¿­ÀÇ ¾ÕµÚ °ø¹é Á¦°Å * @param (string) str */ trim : function(str){ if(typeof str != 'string') return; return str.replace(/(^\s*)|(\s*$)/g, ''); }, /** * @brief HTML ¹®ÀÚ¿­ º¯È¯ * @param string string * @param string quote_style * @return string */ htmlspecialchars : function(string, quote_style){ var histogram = {}, symbol = '', tmp_str = '', i = 0; tmp_str = string.toString(); if (false === (histogram = getHtmlTranslationTable('HTML_SPECIALCHARS', quote_style))) { return false; } for (symbol in histogram) { entity = histogram[symbol]; tmp_str = tmp_str.split(symbol).join(entity); } return tmp_str; }, /** * @brief HTML ÄÚµå º¯È¯ */ getHtmlTranslationTable : function(table, quote_style){ var entities = {}, histogram = {}, decimal = 0, symbol = ''; var constMappingTable = {}, constMappingQuoteStyle = {}; var useTable = {}, useQuoteStyle = {}; useTable = (table ? table.toUpperCase() : 'HTML_SPECIALCHARS'); useQuoteStyle = (quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT'); // Translate arguments constMappingTable[0] = 'HTML_SPECIALCHARS'; constMappingTable[1] = 'HTML_ENTITIES'; constMappingQuoteStyle[0] = 'ENT_NOQUOTES'; constMappingQuoteStyle[2] = 'ENT_COMPAT'; constMappingQuoteStyle[3] = 'ENT_QUOTES'; // Map numbers to strings for compatibilty with PHP constants if (!isNaN(useTable)) { useTable = constMappingTable[useTable]; } if (!isNaN(useQuoteStyle)) { useQuoteStyle = constMappingQuoteStyle[useQuoteStyle]; } if (useTable == 'HTML_SPECIALCHARS') { // ascii decimals for better compatibility entities['60'] = '<'; entities['62'] = '>'; entities['38'] = '&'; } else if (useTable == 'HTML_ENTITIES') { // ascii decimals for better compatibility entities['38'] = '&'; entities['60'] = '<'; entities['62'] = '>'; entities['160'] = ' '; entities['161'] = '¡'; entities['162'] = '¢'; entities['163'] = '£'; entities['164'] = '¤'; entities['165'] = '¥'; entities['166'] = '¦'; entities['167'] = '§'; entities['168'] = '¨'; entities['169'] = '©'; entities['170'] = 'ª'; entities['171'] = '«'; entities['172'] = '¬'; entities['173'] = '­'; entities['174'] = '®'; entities['175'] = '¯'; entities['176'] = '°'; entities['177'] = '±'; entities['178'] = '²'; entities['179'] = '³'; entities['180'] = '´'; entities['181'] = 'µ'; entities['182'] = '¶'; entities['183'] = '·'; entities['184'] = '¸'; entities['185'] = '¹'; entities['186'] = 'º'; entities['187'] = '»'; entities['188'] = '¼'; entities['189'] = '½'; entities['190'] = '¾'; entities['191'] = '¿'; entities['192'] = 'À'; entities['193'] = 'Á'; entities['194'] = 'Â'; entities['195'] = 'Ã'; entities['196'] = 'Ä'; entities['197'] = 'Å'; entities['198'] = 'Æ'; entities['199'] = 'Ç'; entities['200'] = 'È'; entities['201'] = 'É'; entities['202'] = 'Ê'; entities['203'] = 'Ë'; entities['204'] = 'Ì'; entities['205'] = 'Í'; entities['206'] = 'Î'; entities['207'] = 'Ï'; entities['208'] = 'Ð'; entities['209'] = 'Ñ'; entities['210'] = 'Ò'; entities['211'] = 'Ó'; entities['212'] = 'Ô'; entities['213'] = 'Õ'; entities['214'] = 'Ö'; entities['215'] = '×'; entities['216'] = 'Ø'; entities['217'] = 'Ù'; entities['218'] = 'Ú'; entities['219'] = 'Û'; entities['220'] = 'Ü'; entities['221'] = 'Ý'; entities['222'] = 'Þ'; entities['223'] = 'ß'; entities['224'] = 'à'; entities['225'] = 'á'; entities['226'] = 'â'; entities['227'] = 'ã'; entities['228'] = 'ä'; entities['229'] = 'å'; entities['230'] = 'æ'; entities['231'] = 'ç'; entities['232'] = 'è'; entities['233'] = 'é'; entities['234'] = 'ê'; entities['235'] = 'ë'; entities['236'] = 'ì'; entities['237'] = 'í'; entities['238'] = 'î'; entities['239'] = 'ï'; entities['240'] = 'ð'; entities['241'] = 'ñ'; entities['242'] = 'ò'; entities['243'] = 'ó'; entities['244'] = 'ô'; entities['245'] = 'õ'; entities['246'] = 'ö'; entities['247'] = '÷'; entities['248'] = 'ø'; entities['249'] = 'ù'; entities['250'] = 'ú'; entities['251'] = 'û'; entities['252'] = 'ü'; entities['253'] = 'ý'; entities['254'] = 'þ'; entities['255'] = 'ÿ'; } else { throw Error("Table: "+useTable+' not supported'); return false; } if (useQuoteStyle != 'ENT_NOQUOTES') { entities['34'] = '"'; } if (useQuoteStyle == 'ENT_QUOTES') { entities['39'] = '''; } // ascii decimals to real symbols for (decimal in entities) { symbol = String.fromCharCode(decimal); histogram[symbol] = entities[decimal]; } return histogram; }, /** * @brief ÅÂ±× Á¦°Å * @param string str * @param string allowed_tags (ex : ) * @return string */ stripTags : function(str, allowed_tags){ var key = '', tag = '', allowed = false; var matches = allowed_array = []; var allowed_keys = {}; var replacer = function(search, replace, str) { return str.split(search).join(replace); }; // Build allowes tags associative array if (allowed_tags) { allowed_array = allowed_tags.match(/([a-zA-Z]+)/gi); } str += ''; // Match tags matches = str.match(/(<\/?[^>]+>)/gi); // Go through all HTML tags for (key in matches) { if (isNaN(key)) { // IE7 Hack continue; } // Save HTML tag html = matches[key].toString(); // Is tag not in allowed list? Remove from str! allowed = false; // Go through all allowed tags for (k in allowed_array) { // Init allowed_tag = allowed_array[k]; i = -1; if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');} if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');} if (i != 0) { i = html.toLowerCase().indexOf(''; doc.loadXML(text); } return doc; } }, /** * @brief ÅØ½ºÆ®·Î ¹ÞÀº ÀÎÀÚ¸¦ XML¹®¼­·Î ÆÄ½Ì */ parse : function(text){ if(typeof DOMParser != 'undefined'){ return (new DOMParser()).parseFromString(text, 'application/xml'); }else if(typeof ActiveXObject != 'undefined'){ var doc = this.create(); doc.loadXML(text); return doc; }else{ var url = 'data:text/xml;charset=utf-8,' + encodeURIComponent(text); var request = new XMLHttpRequest(); request.open('GET', url, false); request.send(null); return request.responseXML; } }, /** * @brief XML °´Ã¼¸¦ ¹®ÀÚ¿­·Î ¹Ýȯ * unserialize ´Â parse¸Þ¼­µå¸¦ ÀÌ¿ëÇÏÀÚ. */ serialize : function(xmlObj){ if(typeof XMLSerializer != 'undefined'){ return (new XMLSerializer()).serializeToString(xmlObj); }else if(xmlObj.xml){ return xmlObj.xml; }else{ throw 'LENSVil.XML.serialize is not supported or cant serialize ' + xmlObj; } } }; // // @class Ajax Module // LENSVil.AJAX = { _parent : LENSVil, READY_STATE_LOADING : 1, //@brief ¿äû READY_STATE_INTERACTIVE : 3, //@brief °á°ú°ªÀ» ¹Þ´Â Áß READY_STATE_COMPLEATE : 4, //@brief ¿Ï·á setRequest : function(){ var XMLhttp = null; if(window.XMLHttpRequest){ XMLhttp = new XMLHttpRequest(); }else if(window.ActiveXObject){ XMLhttp = new ActiveXObject("Microsoft.XMLHTTP"); } return XMLhttp; }, setCreateAjax : function(XMLhttp, createObj){ if(XMLhttp == null) return; var url = createObj.url; var method = createObj.method || 'GET'; var params = createObj.params; var callback = createObj.callback || null; var beforecallback = createObj.beforecallback || null; var headers = createObj.headers || null; var responseType = createObj.responseType || 'text'; var exception = createObj.exception || this.defaultError; if(method == 'GET'){ url = url + '?' + params; params = null; } XMLhttp.open(method, url, true); //POST if(method == 'POST'){ XMLhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); if(XMLhttp.overrideMimeType){ XMLhttp.overrideMimeType('text/xml'); XMLhttp.setRequestHeader("Connection", "close"); } } //JSON if(responseType == 'json'){ XMLhttp.setRequestHeader("Accept", "application/json, text/javascript, */*"); } //Çì´õ¼³Á¤ for(var i in headers){ if (typeof i === "string") { XMLhttp.setRequestHeader(i, headers[i]); } } //readyState ÄÄÇø®Æ®¿ë ÄݹéÇÔ¼ö if (typeof callback === "function") { XMLhttp.onreadystatechange = function(){ try{ if(XMLhttp.readyState == LENSVil.AJAX.READY_STATE_COMPLEATE){ try{ if(XMLhttp.status == 200){ var response = LENSVil.AJAX.getResponse(XMLhttp, responseType); callback.call(XMLhttp, response); } }catch(e){ exception.call(LENSVil.AJAX, e); }finally{ XMLHttp = null; } }else if(XMLhttp.readyState == LENSVil.AJAX.READY_STATE_LOADING){ if(typeof beforecallback === "function"){ try{ beforecallback.call(XMLhttp); }catch(e){ exception.call(LENSVil.AJAX, e); } } } }catch(e){ } } } XMLhttp.send(params); }, /** * @brief AJAX °´Ã¼ »ý¼º * @param (json) createObj * * ¾Æ·¡ ¸Þ¼­µå´Â JSON µ¥ÀÌÅ͸¦ ÀÎÀÚ·Î ¹Þ¾Æ AJAX °´Ã¼¸¦ »ý¼ºÇÕ´Ï´Ù. * ½ÇÁ¦ °´Ã¼ »ý¼ºÀº setCreateAjax ¸Þ¼­µå¿¡°Ô À§ÀÓÇϰí ÀÖ½À´Ï´Ù. */ create : function(createObj){ if(createObj.url){ var XMLhttp = this.setRequest(); this.setCreateAjax(XMLhttp, createObj); } }, /** * @brief ŸÀÔº°·Î °á°ú°ªÀ» º¯È¯½ÃÄÑ ¹Ýȯ * @param (string) type */ getResponse : function(XMLhttp, type){ var result = XMLhttp.responseText; type = type.toLowerCase() || 'text'; switch(type){ case 'json' : result = eval("("+result+")"); break; case 'xml' : result = XMLhttp.responseXML; break; } return result; }, /** * @brief ±âº» ¿¡·¯ Çڵ鷯 */ defaultError : function(){ alert("Error Fetching data! Callback function confirm plz!" + "\n\n status : " + this.getStatus() + "\n readyState : " + this.getReadyState() ); } }; // // @class Events Module // LENSVil.Events = { _parent : LENSVil, globalMethods : [ 'addEvent', 'removeEvent' ], init : function(){ this._parent.applyMethod('targetElm', this.targetElm); this._parent.applyMethod('preventDefault', this.preventDefault); this._parent.applyMethod('stopPropagation', this.stopPropagation); }, /** * @brief À̺¥Æ® Ãß°¡ * @param (string) e * @param (function) func */ addEvent : function(e, func){ var reg = new RegExp("^on", "i"); if(isIE) e = e.search(reg) != -1 ? e.toLowerCase() : 'on' + e.toLowerCase(); else e = e.toLowerCase().replace(reg, ''); if(window.addEventListener){ this.addEventListener(e, func, false); }else if(window.attachEvent){ this.attachEvent(e, func); } }, /** * @brief À̺¥Æ® Á¦°Å * @param (string) e * @param (function) func */ removeEvent : function(e, func){ var reg = new RegExp("^on", "i"); if(isIE) e = e.search(reg) != -1 ? e.toLowerCase() : 'on' + e.toLowerCase(); else e = e.toLowerCase().replace(reg, ''); if(window.removeEventListener){ this.removeEventListener(e, func, false); }else if(window.detachEvent){ this.detachEvent(e, func); } }, /** * @brief À̺¥Æ®°¡ ¹ß»ýµÈ ¿¤¸®¸ÕÆ® ¹Ýȯ * @param (event) e */ targetElm : function(e){ return e.target || e.srcElement; }, /** * @brief À̺¥Æ® Ãë¼Ò * @param (event) e */ preventDefault : function(e){ e = e || window.event; if (e.preventDefault) e.preventDefault(); else e.returnValue = false; }, /** * @brief À̺¥Æ® ÀüÆÄ ±ÝÁö * @param (event) e */ stopPropagation : function(e){ e = e || window.event; if (e.stopPropagation) e.stopPropagation(); else e.cancelBubble = true; } }; LENSVil.attach(LENSVil.Events); // // @class DOMLoad // @brief DOM¿¡ Á¢±Ù °¡´ÉÇÑ ½ÃÁ¡À» ¾Ë¾Æ³» ÄݹéÇÔ¼ö¸¦ ½ÇÇàÇÑ´Ù. // LENSVil.DOMLoad = { DOMLoaded : false, //@brief DOM·Îµå ½ÃÁ¡À» ÆÄ¾Ç execFuncs : [], //@brief ½ÇÇàµÉ Äݹé ÇÔ¼ö ¹è¿­ init : function(){ //Àͽº if(isIE){ document.write("