// 1. Object.assign if (typeof Object.assign != 'function') { // Must be writable: true, enumerable: false, configurable: true Object.defineProperty(Object, "assign", { value: function assign(target, varArgs) { // .length of function is 2 'use strict'; if (target == null) { // TypeError if undefined or null throw new TypeError('Cannot convert undefined or null to object'); } var to = Object(target); for (var index = 1; index < arguments.length; index++) { var nextSource = arguments[index]; if (nextSource != null) { // Skip over if undefined or null for (var nextKey in nextSource) { // Avoid bugs when hasOwnProperty is shadowed if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { to[nextKey] = nextSource[nextKey]; } } } } return to; }, writable: true, configurable: true }); } // 2. Array.from if (!Array.from) { Array.from = (function () { var toStr = Object.prototype.toString; var isCallable = function (fn) { return typeof fn === 'function' || toStr.call(fn) === '[object Function]'; }; var toInteger = function (value) { var number = Number(value); if (isNaN(number)) { return 0; } if (number === 0 || !isFinite(number)) { return number; } return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number)); }; var maxSafeInteger = Math.pow(2, 53) - 1; var toLength = function (value) { var len = toInteger(value); return Math.min(Math.max(len, 0), maxSafeInteger); }; // The length property of the from method is 1. return function from(arrayLike/*, mapFn, thisArg */) { // 1. Let C be the this value. var C = this; // 2. Let items be ToObject(arrayLike). var items = Object(arrayLike); // 3. ReturnIfAbrupt(items). if (arrayLike == null) { throw new TypeError('Array.from requires an array-like object - not null or undefined'); } // 4. If mapfn is undefined, then let mapping be false. var mapFn = arguments.length > 1 ? arguments[1] : void undefined; var T; if (typeof mapFn !== 'undefined') { // 5. else // 5. a If IsCallable(mapfn) is false, throw a TypeError exception. if (!isCallable(mapFn)) { throw new TypeError('Array.from: when provided, the second argument must be a function'); } // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined. if (arguments.length > 2) { T = arguments[2]; } } // 10. Let lenValue be Get(items, "length"). // 11. Let len be ToLength(lenValue). var len = toLength(items.length); // 13. If IsConstructor(C) is true, then // 13. a. Let A be the result of calling the [[Construct]] internal method // of C with an argument list containing the single item len. // 14. a. Else, Let A be ArrayCreate(len). var A = isCallable(C) ? Object(new C(len)) : new Array(len); // 16. Let k be 0. var k = 0; // 17. Repeat, while k < len… (also steps a - h) var kValue; while (k < len) { kValue = items[k]; if (mapFn) { A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k); } else { A[k] = kValue; } k += 1; } // 18. Let putStatus be Put(A, "length", len, true). A.length = len; // 20. Return A. return A; }; }()); } // 3. Array.indexOf if (!Array.prototype.indexOf) { Array.prototype.indexOf = function (searchElement, fromIndex) { var k; // 1. 이 값을 인수로 전달하는 ToObject를 호출 한 결과를 // o라고합니다. if (this == null) { throw new TypeError('"this" is null or not defined'); } var o = Object(this); // 2. lenValue를 Get 함수를 호출 한 결과로 둡니다. // 인수가 "length"인 o의 내부 메소드. // 3. len을 ToUint32 (lenValue)로 지정합니다. var len = o.length >>> 0; // 4. len이 0이면 -1을 반환합니다. if (len === 0) { return -1; } // 5.Index에서 인수가 전달 된 경우 n을 // ToInteger (fromIndex); 그렇지 않으면 n은 0이됩니다. var n = fromIndex | 0; // 6. If n >= len, return -1. if (n >= len) { return -1; } // 7. n> = 0 인 경우 k를 n이라고 합니다. // 8. 그렇지 않으면 n <0, k는 len - abs (n)이됩니다. // k가 0보다 작은 경우 k를 0으로 만듭니다. k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); // 9. k >> 0; // Steps 6-7. var start = arguments[1]; var relativeStart = start >> 0; // Step 8. var k = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len); // Steps 9-10. var end = arguments[2]; var relativeEnd = end === undefined ? len : end >> 0; // Step 11. var final = relativeEnd < 0 ? Math.max(len + relativeEnd, 0) : Math.min(relativeEnd, len); // Step 12. while (k < final) { O[k] = value; k++; } // Step 13. return O; } }); } // 7. Array.prototype.distinct if (!Array.prototype.distinct) { Object.defineProperty(Array.prototype, 'distinct', { value: function() { // Steps 1-2. if (this == null) { throw new TypeError('this is null or not defined'); } var O = Object(this); // Steps 3. var len = O.length >>> 0; // Steps 4. if (len < 2) { return O } // Steps 8. return O.reduce(function (a, value) { // Steps 5. var f = false; typeof(value) === "object" ? t = JSON.stringify(value) : t = String(value); // Steps 6. f = a.some(function(va){ return (typeof(va) === "object" ? JSON.stringify(va) === t : String(va) === t)}) // Steps 7. if(!f) a.push(value) return a; }, []); } }); } // 8.Array.some if (!Array.prototype.some) { Array.prototype.some = function(fun/*, thisArg*/) { 'use strict'; if (this == null) { throw new TypeError('Array.prototype.some called on null or undefined'); } if (typeof fun !== 'function') { throw new TypeError(); } var t = Object(this); var len = t.length >>> 0; var thisArg = arguments.length >= 2 ? arguments[1] : void 0; for (var i = 0; i < len; i++) { if (i in t && fun.call(thisArg, t[i], i, t)) { return true; } } return false; }; } // 9.String.includes if (!String.prototype.includes) { String.prototype.includes = function(search, start) { 'use strict'; if (typeof start !== 'number') { start = 0; } if (start + search.length > this.length) { return false; } else { return this.indexOf(search, start) !== -1; } }; } // Array.includes if (!Array.prototype.includes) { Object.defineProperty(Array.prototype, 'includes', { value: function(searchElement, fromIndex) { if (this == null) { throw new TypeError('"this" is null or not defined'); } // 1. Let O be ? ToObject(this value). var o = Object(this); // 2. Let len be ? ToLength(? Get(O, "length")). var len = o.length >>> 0; // 3. If len is 0, return false. if (len === 0) { return false; } // 4. Let n be ? ToInteger(fromIndex). // (If fromIndex is undefined, this step produces the value 0.) var n = fromIndex | 0; // 5. If n ≥ 0, then // a. Let k be n. // 6. Else n < 0, // a. Let k be len + n. // b. If k < 0, let k be 0. var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); function sameValueZero(x, y) { return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y)); } // 7. Repeat, while k < len while (k < len) { // a. Let elementK be the result of ? Get(O, ! ToString(k)). // b. If SameValueZero(searchElement, elementK) is true, return true. if (sameValueZero(o[k], searchElement)) { return true; } // c. Increase k by 1. k++; } // 8. Return false return false; } }); } // Element.closest() if (!Element.prototype.matches) { Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector; } if (!Element.prototype.closest) { Element.prototype.closest = function(s) { var el = this; do { if (el.matches(s)) return el; el = el.parentElement || el.parentNode; } while (el !== null && el.nodeType === 1); return null; }; } // Array.findIndex if (!Array.prototype.findIndex) { Object.defineProperty(Array.prototype, 'findIndex', { value: function(predicate) { 'use strict'; if (this == null) { throw new TypeError('Array.prototype.findIndex called on null or undefined'); } if (typeof predicate !== 'function') { throw new TypeError('predicate must be a function'); } var list = Object(this); var length = list.length >>> 0; var thisArg = arguments[1]; var value; for (var i = 0; i < length; i++) { value = list[i]; if (predicate.call(thisArg, value, i, list)) { return i; } } return -1; }, enumerable: false, configurable: false, writable: false }); } //NodeList.forEach if (window.NodeList && !NodeList.prototype.forEach) { NodeList.prototype.forEach = function (callback, thisArg) { thisArg = thisArg || window; for (var i = 0; i < this.length; i++) { callback.call(thisArg, this[i], i, this); } }; } // Object.values if (typeof Object.values != 'function') { // Must be writable: true, enumerable: false, configurable: true Object.defineProperty(Object.prototype, "values", { value: function values(target) { // .length of function is 2 var a = [] for(var t in target) { a.push(target[t]) } return a; }, writable: true, configurable: true }); } // jQuery fn extend으로 기능 확장. jQuery.fn.extend({ // animation 후 remove remove_as_animate : function(obj,time) { this.animate(obj, time , function() { this.remove() }); } }) // Element.appendM() if (!Element.prototype.appendM) { Element.prototype.appendM = function(s) { var el = this; if(!Array.isArray(s)) s = [s]; for(var icnt=0;icnt < s.length;icnt++) { el.appendChild(s[icnt]); } return el; }; } // Object.filterkey if (typeof Object.filterkey != "func"){ Object.defineProperty(Object.prototype, "filterkey", { value: function filterkey(func) { // .length of function is 2 var thiskey = Object.keys(this); var len = (+thiskey.length), res = new Array(len), // preallocate array t = thiskey, c = 0, i = -1; while (++i !== len){ // checks to see if the key was set if (i in thiskey){ if (func(t[i], i, t)) res[c++] = t[i]; } } res.length = c; // shrink down array to proper size return res; }, writable: true, configurable: true }); } //jQuert loadScript /* if (typeof someObject == 'undefined') $.loadScript('url_to_someScript.js', function(){ //Stuff to do after someScript has loaded }); */ jQuery.loadScript = function (url, callback) { jQuery.ajax({ url: url, dataType: 'script', success: callback, error: function(x){ callback(x.responseText) }, async: false, cache:false }); } Date.prototype.format = function (f) { if (!this.valueOf()) return " "; var weekKorName = ["일요일", "월요일", "화요일", "수요일", "목요일", "금요일", "토요일"]; var weekKorShortName = ["일", "월", "화", "수", "목", "금", "토"]; var weekEngName = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; var weekEngShortName = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; var d = this; return f.replace(/(yyyy|yy|MM|dd|KS|KL|ES|EL|HH|hh|mm|ss|a\/p)/gi, function ($1) { switch ($1) { case "yyyy": return d.getFullYear(); // 년 (4자리) case "yy": return (d.getFullYear() % 1000).zf(2); // 년 (2자리) case "MM": return (d.getMonth() + 1).zf(2); // 월 (2자리) case "dd": return d.getDate().zf(2); // 일 (2자리) case "KS": return weekKorShortName[d.getDay()]; // 요일 (짧은 한글) case "KL": return weekKorName[d.getDay()]; // 요일 (긴 한글) case "ES": return weekEngShortName[d.getDay()]; // 요일 (짧은 영어) case "EL": return weekEngName[d.getDay()]; // 요일 (긴 영어) case "HH": return d.getHours().zf(2); // 시간 (24시간 기준, 2자리) case "hh": return ((h = d.getHours() % 12) ? h : 12).zf(2); // 시간 (12시간 기준, 2자리) case "mm": return d.getMinutes().zf(2); // 분 (2자리) case "ss": return d.getSeconds().zf(2); // 초 (2자리) case "a/p": return d.getHours() < 12 ? "오전" : "오후"; // 오전/오후 구분 default: return $1; } }); }; String.prototype.string = function (len) { var s = '', i = 0; while (i++ < len) { s += this; } return s; }; String.prototype.zf = function (len) { return "0".string(len - this.length) + this; }; Number.prototype.zf = function (len) { return this.toString().zf(len); }; Array.prototype.gmap = function(callback, thisArg) { /* return false가 아니면 배열에 추가 */ var T, A, k; var O = Object(this); var len = O.length >>> 0; if (typeof callback !== 'function') { throw new TypeError(callback + ' is not a function'); } if (arguments.length > 1) { T = thisArg; } A = []; k = 0; for(var i=0;i