/* /js/missionicUtils.js Cummon Utils for globas uses... 2017-05-31오후 2:58 */ // 안드로이드 버그 주소창 없애기 window.addEventListener('load', function(){ document.body.style.height = (document.documentElement.clientHeight + 5) + 'px'; window.scrollTo(0, 1); }, false); // 모바일 디텍터 window.mobileAndTabletcheck = function() { var check = false; (function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera); return check; }; var isMobile = mobileAndTabletcheck(); var mobileCheck = mobileAndTabletcheck(); /* var md = new MobileDetect(window.navigator.userAgent); if(md.mobile()) { //mobile var isMobile = "check"; } else { //pc var isMobile = ""; } */ var mobileCheck = isMobile; // 파라메터 Value 를 리턴.. // Usage : var paramVal = findGetParameter(parameterName); function findGetParameter(parameterName) { var result = null, tmp = []; location.search .substr(1) .split("&") .forEach(function (item) { tmp = item.split("="); if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]); }); return result; } /* ******** Email validation **********/ function validateEmail(email) { var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; //var re = /\S+@\S+\.\S+/; return re.test(String(email).toLowerCase()); } /* ******** HPNum validation **********/ function validateHPNum(hpNum) { //console.log( "hpNum "+hpNum ); //console.log( "hpNum.replace(/[^0-9]/g, '') "+hpNum.replace(/[^0-9]/g, '') ); if (hpNum != hpNum.replace(/[^0-9]/g, '')) return false; if ( hpNum.toString().length <= 10 ) return false; return true; } // 배열의 밸류로 키 값을 찾아서 리턴한다. // integer 와 string 이 혼재할 때 작동하지 않는다. 모든 어레이 밸류와 컴페어 인자를 toString() 으로 타잎 바꿔서 매칭한다. // Usage : var ind = parseInt( findKey(thisPriceRangeArr, thisSelectedCharge) ); var findKey = function(obj, value) { var key = null; var val_ = value.toString(); //console.log( "typeof "+val_ +" = " + typeof val_ ); for (var prop in obj) { //console.log( "finding Key typeof "+obj[prop] +" = " + typeof obj[prop] ); if (obj.hasOwnProperty(prop)) { if ( obj[prop].toString() === val_) { key = prop; } } } return key; }; // 스트링이 numeric 인가를 체크 리턴 function is_numeric(str){ return /^\d+$/.test(str); } // PHP mb_strlen() 을 JS 로 구현... function mb_strlen(str) { var len = 0; for(var i = 0; i < str.length; i++) { len += str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255 ? 2 : 1; } return len; } // keyUp 의 딜레이를 주기위해, delay 를 설정하는 람다함수를 선언... var delay = (function(){ var timer = 0; return function(callback, ms){ clearTimeout (timer); timer = setTimeout(callback, ms); }; })(); // 쿠키핸들 펑션... setCookieValue / getCookieValue // 이름과 밸류 쌍을 받아서 신규 쿠리를 추가하거나 기존 밸류를 업데이트 한다. function setCookieValue(cname, cvalue, exdays) { deleteAllCookies(); var d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); var expires = "expires="+ d.toUTCString(); cookieList = document.cookie.split('; '); cookies = {}; for (i = cookieList.length - 1; i >= 0; i--) { cookie = cookieList[i].split('='); cookie[0].trim(); console.log(" 쿠킹... : " + cookie[0] );; if(cookie[0] !== cname) { cookies[cookie[0]] = cookie[1]; document.cookie = cookie[0] + "=" + cookie[1] + ";" + expires + ";path=/"; } else if( cookies[cookie[0]] =="" ) { console.log(" 이걸 잡아라.//// " + cname ); cookies[ cname ] = cvalue; //document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; document.cookie = cname + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;'; } else document.cookie = cookie[0] + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;'; } } // 특정 쿠키의 밸류를 리턴한다. function getCookieValue(cname) { var d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); var expires = "expires="+ d.toUTCString(); cookieList = document.cookie.split('; '); cookies = {}; for (i = cookieList.length - 1; i >= 0; i--) { cookie = cookieList[i].split('='); if(cookie[0] == cname) { return cookie[1]; } } } function deleteAllCookies() { var cookies = document.cookie.split(";"); for (var i = 0; i < cookies.length; i++) { var cookie = cookies[i]; var eqPos = cookie.indexOf("="); var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie; document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT"; } } function deleteCookieValue(cookieName) { var d = new Date(); d.setTime(d.getTime()); var cookieExpireDate = "expires=" + d.toString(); document.cookie = cookieName + "=expired;" + cookieExpireDate; } function getCookie(cname) { var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(';'); for(var i = 0; i options.minY ? top : options.minY); $.extend(props, {top: top+'px'}); } if (options.horizontal) { var left = ($(options.inside).width() - $(this).outerWidth()) / 2; if (options.withScrolling) left += $(options.inside).scrollLeft() || 0; left = (left > options.minX ? left : options.minX); $.extend(props, {left: left+'px'}); } if (options.transition > 0) $(this).animate(props, options.transition); else $(this).css(props); return $(this); }); } }); })(jQuery); */ // 숫자열을 전화번호형식으로 리턴.... function addDashesTohpNum(num,type) { var formatNum = ''; if(num.length==11){ if(type==0){ formatNum = num.replace(/(\d{3})(\d{4})(\d{4})/, '$1-****-$3'); }else{ formatNum = num.replace(/(\d{3})(\d{4})(\d{4})/, '$1-$2-$3'); } }else if(num.length==8){ formatNum = num.replace(/(\d{4})(\d{4})/, '$1-$2'); }else{ if(num.indexOf('02')==0){ if(type==0){ formatNum = num.replace(/(\d{2})(\d{4})(\d{4})/, '$1-****-$3'); }else{ formatNum = num.replace(/(\d{2})(\d{4})(\d{4})/, '$1-$2-$3'); } }else{ if(type==0){ formatNum = num.replace(/(\d{3})(\d{3})(\d{4})/, '$1-***-$3'); }else{ formatNum = num.replace(/(\d{3})(\d{3})(\d{4})/, '$1-$2-$3'); } } } return formatNum; } // 유닉스 타임스탬프를 날짜 형식으로 변환해 리턴 // 날짜 형식을 한국식에 맞게 좀 수정해줄 것!!! function timeConverter(UNIX_timestamp){ console.log("UNIX_timestamp - lastLogInTime : "+UNIX_timestamp); var a = new Date(UNIX_timestamp * 1000); var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; var year = a.getFullYear(); var month = months[a.getMonth()]; var date = a.getDate(); var hour = a.getHours(); var min = a.getMinutes(); var sec = a.getSeconds(); var time = year + ' ' + month + ' ' + date + ' ' + hour + ':' + min + ':' + sec ; return time; } // Object 를 콘솔로그 해준다. function consoleLogObject(obj) { seen = []; JSON.stringify(obj, function(key, val) { if (val != null && typeof val == "object") { if (seen.indexOf(val) >= 0) { return; } seen.push(val); } return val; }); console.log(seen); // Logs output to dev tools console. } // 로컬/세션 스토리지 전부를 콘솔로그 해준다. function consolLogStorages() { for (var i = 0; i < localStorage.length; i++){ // do something with localStorage.getItem(localStorage.key(i)); console.log( "localStorage "+i+" : "+ localStorage.getItem(localStorage.key(i)) ); } for (var i = 0; i < sessionStorage.length; i++){ // do something with localStorage.getItem(localStorage.key(i)); console.log( "sessionStorage "+i+" : "+ sessionStorage.key(i) ); console.log( "sessionStorage "+i+" : "+ sessionStorage.getItem(sessionStorage.key(i)) ); } } // Ajax Loading Spinner function ajaxLoadingScreenOn() { //console.log("ajaxLoadingScreenOn!!"); $('.wrap-loading').removeClass('display-none'); } function ajaxLoadingScreenOn2() { console.log("2nd ajaxLoadingScreenOn!!"); $('.wrap-loading2').removeClass('display-none'); } function ajaxLoadingScreenOff() { //console.log("ajaxLoadingScreenOff--"); $('.wrap-loading, .wrap-loading2').addClass('display-none'); } // Ajax Loading Spinner -- Light version function ajaxLoadingLightOn() { //console.log("ajaxLoadingScreenOn!!"); $('.light-wrap-loading').removeClass('display-none'); } function ajaxLoadingLightOff() { //console.log("ajaxLoadingScreenOn!!"); $('.light-wrap-loading').addClass('display-none'); } // div1 과 div2 의 디스플레이 상태를 맞바꾼다. function swapDisplay( div1, div2 ) { console.log("펑션 swapDisplay"); $(div1).slideUp(); $(div2).slideDown(); ajaxLoadingScreenOff(); } // 페이지를 이동시킨다. // 이걸 뭣에 쓰냐.. 하겠지만, 콜백펑션을 펑션명으로 사용할 경우에 요긴히 쓰인다. function movePage(moveToUrl) { document.location.href= moveToUrl; } // 첫글자를 대문자로 function capitalizeFirstLetter(string) { return string.charAt(0).toUpperCase() + string.slice(1); } // 오브젝트를 바운스 애니메이션 1회 해준다. // css 에서 클래스 정의가 필요하다. 필요한 css 는 basic.css 에서 정해둬서 모든 프로젝트에서 사용가능하도록 하자. // 매개변수는 "객체명"이다. "객체" 도 아니고 jQuery 오브젝트도 아니고, "이름" 이다. // ex) bounceElement( $(this).attr("id") ); function bounceElement( element ) { elem = document.getElementById(element); // -> removing the class elem.classList.remove("bounce"); // -> triggering reflow The actual magic // without this it wouldn't work. Try uncommenting the line and the transition won't be retriggered. // 풀리지 않은 수수께끼... // 이게 왜 필요한지도, 왜 jQuery 객체로는 작동 안하는지도 설명할 수 없다. // 심지어 우겨넣은 offsetWidth 의 값도 "undefined" 인데, 우겨넣지 않으면 retrigger 가 안된다. elem.offsetWidth = elem.offsetWidth; console.log("offsetWidth"+ elem.offsetWidth); // -> and re-adding the class elem.classList.add("bounce"); //setTimeout( elem.classList.remove("bounce") , 1500 ); } // 콜백 기능이 필요해져서..... jQuery 플러그인으로 시도해본다. // 엘리먼트를 바운스 해준다. 이벤트 발생시 호출된다. // ex) $("element").click( function() { $(this).bounce(); }); jQuery.fn.bounce = function() { //e.preventDefault; // -> removing the class $(this).removeClass("bounce"); // 풀리지 않은 수수께끼... // 이게 왜 필요한지도, 왜 jQuery 객체로는 작동 안하는지도 설명할 수 없다. // 심지어 우겨넣은 offsetWidth 의 값도 "undefined" 인데, 우겨넣지 않으면 retrigger 가 안된다. $(this).offsetWidth = document.getElementById( $(this).attr("id") ).offsetWidth; console.log("offsetWidth"+ $(this).offsetWidth); // -> and re-adding the class $(this).addClass("bounce"); } // jQuery.getJSON 을 POST 로 사용할 수 있도록 jQuery 메서드를 추가해준다. jQuery.extend({ postJSON: function( url, data, callback) { return jQuery.post(url, data, callback, "json"); } }); /* 외부 텍스트를 팝업해주는 Div 를 생성해서 팝업시킨다. 팝업 Div:textPopupDiv 는 seudo:before 로 클로즈 아이콘도 달아주고, basic.css 에서 선언해주자. */ // popUpExternalTxt("/txt/privacyRules.txt"); function popUpExternalTxt(src) { console.log("플레인 팝업을 만들어보자..."+src); console.log("typeof..."+typeof $("#textPopupDiv")); if( typeof $("#textPopupDiv") !== "undefined" ) { $("
close
").appendTo("body"); $("

").appendTo("#textPopupDiv"); console.log("#textPopupDiv 내용 : "+ $("#textPopupDiv").html() ); } $('.wrap-loading').removeClass('display-none'); $("#textPopupDivP").load(src); $("#textPopupDiv").center2(); }