From 98b8b8daf06ec93a292aadfdfd85c9e0b26c79f3 Mon Sep 17 00:00:00 2001 From: taggon Date: Mon, 26 Mar 2012 01:22:14 +0000 Subject: [PATCH] issue 568: Enchangement setQuery() function in JavaScript git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@10470 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- common/js/common.js | 94 ++++++++++++++++++++++----------------------- common/js/xe.js | 94 ++++++++++++++++++++++----------------------- common/js/xe.min.js | 67 ++++++++++++++++---------------- 3 files changed, 128 insertions(+), 127 deletions(-) diff --git a/common/js/common.js b/common/js/common.js index b35e42c50..392b313d5 100644 --- a/common/js/common.js +++ b/common/js/common.js @@ -192,19 +192,26 @@ jQuery(function($) { }); +(function(){ // String extension methods + +function isSameUrl(a,b) { + return (a.replace(/#.*$/, '') === b.replace(/#.*$/, '')); +} + +var isArray = Array.isArray || function(obj){ return Object.prototype.toString.call(obj)=='[object Array]' }; /** * @brief location.href에서 특정 key의 값을 return **/ String.prototype.getQuery = function(key) { - var idx = this.indexOf('?'); + var loc = isSameUrl(this, window.location.href) ? current_url : this; + var idx = loc.indexOf('?'); if(idx == -1) return null; - var query_string = this.substr(idx+1, this.length); - var args = {}; + var query_string = loc.substr(idx+1, this.length), args = {}; query_string.replace(/([^=]+)=([^&]*)(&|$)/g, function() { args[arguments[1]] = arguments[2]; }); var q = args[key]; - if(typeof(q)=="undefined") q = ""; + if(typeof(q)=='undefined') q = ''; return q; } @@ -213,67 +220,58 @@ String.prototype.getQuery = function(key) { * @brief location.href에서 특정 key의 값을 return **/ String.prototype.setQuery = function(key, val) { - var idx = this.indexOf('?'); - var uri = this.replace(/#$/, ''); + var loc = isSameUrl(this, window.location.href) ? current_url : this; + var idx = loc.indexOf('?'); + var uri = loc.replace(/#$/, ''); + var act, re, v; - if(idx != -1) { - var query_string = uri.substr(idx+1, this.length), args = {}, q_list = []; - uri = this.substr(0, idx); + if (typeof(val)=='undefined') val = ''; + + if (idx != -1) { + var query_string = uri.substr(idx+1, loc.length), args = {}, q_list = []; + uri = loc.substr(0, idx); query_string.replace(/([^=]+)=([^&]*)(&|$)/g, function(all,key,val) { args[key] = val; }); args[key] = val; - jQuery.each(args, function(key,val){ - if (!jQuery.trim(val)) return; - q_list.push(key+'='+decodeURI(val)); - }); + for (var prop in args) { + if (!args.hasOwnProperty(prop)) continue; + if (!(v = String(args[prop]).trim())) continue; + q_list.push(prop+'='+decodeURI(v)); + } query_string = q_list.join('&'); uri = uri+(query_string?'?'+query_string:''); } else { - if(val.toString().trim()) uri = uri+"?"+key+"="+val; + if (String(val).trim()) uri = uri+'?'+key+'='+val; } - var re = /https:\/\/([^:\/]+)(:\d+|)/i; - var check = re.exec(uri); - if(check) - { - var toReplace = "http://"+check[1]; - if(typeof(http_port)!='undefined' && http_port != 80) - { - toReplace += ":" + http_port; - } - uri = uri.replace(re,toReplace); + re = /^https:\/\/([^:\/]+)(:\d+|)/i; + if (re.test(uri)) { + var toReplace = 'http://'+RegExp.$1; + if (window.http_port && http_port != 80) toReplace += ':' + http_port; + uri = uri.replace(re, toReplace); } - var bUseSSL = false; - if(typeof(enforce_ssl)!='undefined' && enforce_ssl) - { - bUseSSL = true; - } - else if(typeof(ssl_actions)!='undefined' && typeof(ssl_actions.length)!='undefined' && uri.getQuery('act')) { - var act = uri.getQuery('act'); - for(i=0;ih.length&&(h=h[0]);(e["AFTER_"+b]||this["API_AFTER_"+b])&&this._cast(g,"AFTER_"+b,c);return!/^(?:AFTER|BEFORE)_/.test(b)?h:a.isArray(h)?0>a.inArray(!1,h):"undefined"==typeof h?!0:!!h}}}; -c={oApp:null,cast:function(a,b){if(this.oApp&&this.oApp._cast)return this.oApp._cast(this,a,b||[])},broadcast:function(a,b){this.oApp&&this.oApp.broadcast&&this.oApp.broadcast(this,mag,b||[])}};window.xe=a.extend(d,{getName:function(){return"Core"},createApp:function(g,c){var e=b();a.extend(e.prototype,d,c);e.prototype.getName=function(){return g};return e},createPlugin:function(g,d){var e=b();a.extend(e.prototype,c,d);e.prototype.getName=function(){return g};return e},getApps:function(){return a.makeArray(e)}, -getApp:function(a){a=(a||"").toLowerCase();return"undefined"!=typeof e[a]?e[a]:null},registerApp:function(b){var c=b.getName().toLowerCase();e.push(b);a.isArray(e[c])||(e[c]=[]);e[c].push(b);b.parent=this;a.isFunction(b.activate)&&b.activate()},unregisterApp:function(b){var c=b.getName().toLowerCase(),d=a.inArray(b,e);0<=d&&(e=e.splice(d,1));a.isArray(e[c])&&(d=a.inArray(b,e[c]),0<=d&&(e[c]=e[c].splice(d,1)));a.isFunction(b.deactivate)&&b.deactivate()},broadcast:function(a,b){this._broadcast(this, -a,b)},_broadcast:function(a,b,c){for(var d=0;dh.length&&(h=h[0]);(e["AFTER_"+c]||this["API_AFTER_"+c])&&this._cast(g,"AFTER_"+c,b);return!/^(?:AFTER|BEFORE)_/.test(c)?h:a.isArray(h)?0>a.inArray(!1,h):"undefined"==typeof h?!0:!!h}}}; +c={oApp:null,cast:function(a,c){if(this.oApp&&this.oApp._cast)return this.oApp._cast(this,a,c||[])},broadcast:function(a,c){this.oApp&&this.oApp.broadcast&&this.oApp.broadcast(this,mag,c||[])}};window.xe=a.extend(d,{getName:function(){return"Core"},createApp:function(g,c){var e=b();a.extend(e.prototype,d,c);e.prototype.getName=function(){return g};return e},createPlugin:function(g,d){var e=b();a.extend(e.prototype,c,d);e.prototype.getName=function(){return g};return e},getApps:function(){return a.makeArray(e)}, +getApp:function(a){a=(a||"").toLowerCase();return"undefined"!=typeof e[a]?e[a]:null},registerApp:function(c){var b=c.getName().toLowerCase();e.push(c);a.isArray(e[b])||(e[b]=[]);e[b].push(c);c.parent=this;a.isFunction(c.activate)&&c.activate()},unregisterApp:function(c){var b=c.getName().toLowerCase(),d=a.inArray(c,e);0<=d&&(e=e.splice(d,1));a.isArray(e[b])&&(d=a.inArray(c,e[b]),0<=d&&(e[b]=e[b].splice(d,1)));a.isFunction(c.deactivate)&&c.deactivate()},broadcast:function(a,c){this._broadcast(this, +a,c)},_broadcast:function(a,c,b){for(var d=0;dg.length)g=Array(g);if(g.length)for(var j=0;j"+m+" "}}this.loaded_popup_menus[c]= +if("undefined"==typeof g.length||1>g.length)g=Array(g);if(g.length)for(var i=0;i"+k+" "}}this.loaded_popup_menus[c]= b}b&&(c=a("#popup_menu_area").html("
    "+b+"
"),b=e.page_y,e=e.page_x,c.outerHeight()+b>a(window).height()+a(window).scrollTop()&&(b=a(window).height()-c.outerHeight()+a(window).scrollTop()),c.outerWidth()+e>a(window).width()+a(window).scrollLeft()&&(e=a(window).width()-c.outerWidth()+a(window).scrollLeft()),c.css({top:b,left:e}).show())}}})(jQuery); -jQuery(function(a){a.browser.msie&&a("select").each(function(a,b){for(var g=!1,d=[],k=0;k';else if(/\.flv$/i.test(a)||/\.mov$/i.test(a)||/\.moov$/i.test(a)||/\.m4v$/i.test(a))g='';else if(/\.swf/i.test(a)){var g='',g=g+(''),j;for(j in c)"undefined"!=c[j]&&""!=c[j]&&(g+='');g+=''}else{if(jQuery.browser.mozilla||jQuery.browser.opera)e=c.autostart&&"false"!=c.autostart?"1":"0";g='',g=g+(''),i;for(i in c)"undefined"!=c[i]&&""!=c[i]&&(g+='');g+=''}else{if(jQuery.browser.mozilla||jQuery.browser.opera)e=c.autostart&&"false"!=c.autostart?"1":"0";g='.popup"),d,c,e,g;g=a.css({overflow:"scroll"}).offset();d=a.width(10).height(1E4).get(0).scrollWidth+2*g.left;c=a.height(10).width(1E4).get(0).scrollHeight+2*g.top;600>d&&(d=600+2*g.left);e=b.width();b=b.height();d!=e&&window.resizeBy(d-e,0);c!=b&&window.resizeBy(0,c-b);a.width(d-2*g.left).css({overflow:"",height:""})} function doCallModuleAction(a,b,d){exec_xml(a,b,{target_srl:d,cur_mid:current_mid,mid:current_mid},completeCallModuleAction)}function completeCallModuleAction(a){"success"!=a.message&&alert(a.message);location.reload()}function completeMessage(a){alert(a.message);location.reload()}function doChangeLangType(a){"string"==typeof a?setLangType(a):setLangType(a.options[a.selectedIndex].value);location.href=location.href.setQuery("l","")} @@ -36,8 +37,8 @@ function doDocumentSelect(a){opener&&opener.objForSavedDoc&&(opener.location.hre function callAddDocumentCart(a){1>addedDocument.length||a!=addedDocument.length||(a=[],a.srls=addedDocument.join(","),exec_xml("document","procDocumentAddCart",a,null),addedDocument=[])} function transRGB2Hex(a){if(!a)return a;if(-1a.toLowerCase().indexOf("rgb"))return a;a=a.replace(/^rgb\(/i,"").replace(/\)$/,"");value_list=a.split(",");for(var a="",b=0;b>2,d=(d&3)<<4|c>>4,j=(c&15)<<2|e>>6,k=e&63,isNaN(c)?j=k=64:isNaN(e)&&(k=64),b=b+this._keyStr.charAt(g)+this._keyStr.charAt(d)+this._keyStr.charAt(j)+this._keyStr.charAt(k);return b},decode:function(a){for(var b="",d,c,e,g,j,k=0,a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");k< -a.length;)d=this._keyStr.indexOf(a.charAt(k++)),c=this._keyStr.indexOf(a.charAt(k++)),g=this._keyStr.indexOf(a.charAt(k++)),j=this._keyStr.indexOf(a.charAt(k++)),d=d<<2|c>>4,c=(c&15)<<4|g>>2,e=(g&3)<<6|j,b+=String.fromCharCode(d),64!=g&&(b+=String.fromCharCode(c)),64!=j&&(b+=String.fromCharCode(e));return b=Base64._utf8_decode(b)},_utf8_encode:function(a){for(var a=a.replace(/\r\n/g,"\n"),b="",d=0;dc?b+=String.fromCharCode(c):(127c?b+=String.fromCharCode(c>> +var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(a){for(var b="",d,c,e,g,i,j,k=0,a=Base64._utf8_encode(a);k>2,d=(d&3)<<4|c>>4,i=(c&15)<<2|e>>6,j=e&63,isNaN(c)?i=j=64:isNaN(e)&&(j=64),b=b+this._keyStr.charAt(g)+this._keyStr.charAt(d)+this._keyStr.charAt(i)+this._keyStr.charAt(j);return b},decode:function(a){for(var b="",d,c,e,g,i,j=0,a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");j< +a.length;)d=this._keyStr.indexOf(a.charAt(j++)),c=this._keyStr.indexOf(a.charAt(j++)),g=this._keyStr.indexOf(a.charAt(j++)),i=this._keyStr.indexOf(a.charAt(j++)),d=d<<2|c>>4,c=(c&15)<<4|g>>2,e=(g&3)<<6|i,b+=String.fromCharCode(d),64!=g&&(b+=String.fromCharCode(c)),64!=i&&(b+=String.fromCharCode(e));return b=Base64._utf8_decode(b)},_utf8_encode:function(a){for(var a=a.replace(/\r\n/g,"\n"),b="",d=0;dc?b+=String.fromCharCode(c):(127c?b+=String.fromCharCode(c>> 6|192):(b+=String.fromCharCode(c>>12|224),b+=String.fromCharCode(c>>6&63|128)),b+=String.fromCharCode(c&63|128))}return b},_utf8_decode:function(a){for(var b="",d=0,c=c1=c2=0;dc?(b+=String.fromCharCode(c),d++):191c?(c2=a.charCodeAt(d+1),b+=String.fromCharCode((c&31)<<6|c2&63),d+=2):(c2=a.charCodeAt(d+1),c3=a.charCodeAt(d+2),b+=String.fromCharCode((c&15)<<12|(c2&63)<<6|c3&63),d+=3);return b}}; if("undefined"==typeof resizeImageContents)var resizeImageContents=function(){};if("undefined"==typeof activateOptionDisabled)var activateOptionDisabled=function(){};objectExtend=jQuery.extend;function toggleDisplay(a){jQuery("#"+a).toggle()}function checkboxSelectAll(a,b,d){var c={};"undefined"!=typeof a&&(c.wrap=a);"undefined"!=typeof d&&(c.checked=d);XE.checkboxToggleAll(b,c)}function clickCheckBoxAll(a,b){var d={doClick:!0};"undefined"!=typeof a&&(d.wrap=a);XE.checkboxToggleAll(b,d)} function svc_folder_open(a){jQuery("#_folder_open_"+a).hide();jQuery("#_folder_close_"+a).show();jQuery("#_folder_"+a).show()}function svc_folder_close(a){jQuery("#_folder_open_"+a).show();jQuery("#_folder_close_"+a).hide();jQuery("#_folder_"+a).hide()}function open_calendar(a,b,d){"undefined"==typeof b&&(b="");var c="./common/tpl/calendar.php?";a&&(c+="fo_id="+a);b&&(c+="&day_str="+b);d&&(c+="&callback_func="+d);popopen(c,"Calendar")}var loaded_popup_menus=XE.loaded_popup_menus; @@ -46,29 +47,29 @@ function getCookie(a){if(a=document.cookie.match(RegExp(a+"=(.*?)(?:;|$)")))retu jQuery(function(a){a(".lang_code").each(function(){var b=a(this),d=b.attr("id");"undefined"==typeof d&&(d=b.attr("name"));"undefined"!=typeof d&&b.after("find_langcode")});a(document).click(function(b){var d=a("#popup_menu_area");d.length||(d=a('