ax5ui-formatter
Advanced tools
Comparing version 0.5.1 to 0.5.2
{ | ||
"name": "ax5ui-formatter", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "A formatter plugin that works with Bootstrap & jQuery", | ||
@@ -21,3 +21,3 @@ "authors": [ | ||
"jquery": "^1.11.0", | ||
"ax5core": "", | ||
"ax5core": ">=1.0.9", | ||
"bootstrap": "^3.3.6" | ||
@@ -24,0 +24,0 @@ }, |
@@ -5,477 +5,467 @@ "use strict"; | ||
(function () { | ||
/** | ||
* @class ax5.ui.formatter | ||
* @classdesc | ||
* @author tom@axisj.com | ||
* @example | ||
* ``` | ||
* var formatter = new ax5.ui.formatter(); | ||
* ``` | ||
*/ | ||
var ROOT = ax5.ui; | ||
var _SUPER_ = ax5.ui.root; | ||
var UI = ax5.ui; | ||
var U = ax5.util; | ||
var CLASS_NAME = "ax5formatter"; | ||
var VERSION = "0.5.1"; | ||
var TODAY = new Date(); | ||
var setSelectionRange = function setSelectionRange(input, pos) { | ||
if (typeof pos == "undefined") { | ||
pos = input.value.length; | ||
} | ||
if (input.setSelectionRange) { | ||
input.focus(); | ||
input.setSelectionRange(pos, pos); | ||
} else if (input.createTextRange) { | ||
var range = input.createTextRange(); | ||
range.collapse(true); | ||
range.moveEnd('character', pos); | ||
range.moveStart('character', pos); | ||
range.select(); | ||
} else if (input.selectionStart) { | ||
input.focus(); | ||
input.selectionStart = pos; | ||
input.selectionEnd = pos; | ||
} | ||
}; | ||
//== UI Class | ||
var ax5formatter = function ax5formatter() { | ||
var self = this, | ||
cfg; | ||
if (_SUPER_) _SUPER_.call(this); // 부모호출 | ||
this.name = CLASS_NAME; | ||
this.version = VERSION; | ||
this.instanceId = ax5.getGuid(); | ||
this.config = { | ||
animateTime: 250 | ||
UI.addClass({ | ||
className: "formatter", | ||
version: "0.5.2" | ||
}, function () { | ||
var TODAY = new Date(); | ||
var setSelectionRange = function setSelectionRange(input, pos) { | ||
if (typeof pos == "undefined") { | ||
pos = input.value.length; | ||
} | ||
if (input.setSelectionRange) { | ||
input.focus(); | ||
input.setSelectionRange(pos, pos); | ||
} else if (input.createTextRange) { | ||
var range = input.createTextRange(); | ||
range.collapse(true); | ||
range.moveEnd('character', pos); | ||
range.moveStart('character', pos); | ||
range.select(); | ||
} else if (input.selectionStart) { | ||
input.focus(); | ||
input.selectionStart = pos; | ||
input.selectionEnd = pos; | ||
} | ||
}; | ||
this.queue = []; | ||
this.openTimer = null; | ||
this.closeTimer = null; | ||
/** | ||
* @class ax5.ui.formatter | ||
* @classdesc | ||
* @author tom@axisj.com | ||
* @example | ||
* ``` | ||
* var formatter = new ax5.ui.formatter(); | ||
* ``` | ||
*/ | ||
var ax5formatter = function ax5formatter() { | ||
var self = this, | ||
cfg; | ||
cfg = this.config; | ||
this.config = { | ||
animateTime: 250 | ||
}; | ||
var ctrlKeys = { | ||
"18": "KEY_ALT", | ||
"8": "KEY_BACKSPACE", | ||
"17": "KEY_CONTROL", | ||
"46": "KEY_DELETE", | ||
"40": "KEY_DOWN", | ||
"35": "KEY_END", | ||
"187": "KEY_EQUAL", | ||
"27": "KEY_ESC", | ||
"36": "KEY_HOME", | ||
"45": "KEY_INSERT", | ||
"37": "KEY_LEFT", | ||
"189": "KEY_MINUS", | ||
"34": "KEY_PAGEDOWN", | ||
"33": "KEY_PAGEUP", | ||
// "190": "KEY_PERIOD", | ||
"13": "KEY_RETURN", | ||
"39": "KEY_RIGHT", | ||
"16": "KEY_SHIFT", | ||
// "32": "KEY_SPACE", | ||
"9": "KEY_TAB", | ||
"38": "KEY_UP", | ||
"91": "KEY_WINDOW" | ||
//"107" : "NUMPAD_ADD", | ||
//"194" : "NUMPAD_COMMA", | ||
//"110" : "NUMPAD_DECIMAL", | ||
//"111" : "NUMPAD_DIVIDE", | ||
//"12" : "NUMPAD_EQUAL", | ||
//"106" : "NUMPAD_MULTIPLY", | ||
//"109" : "NUMPAD_SUBTRACT" | ||
}, | ||
numKeys = { | ||
'48': 1, '49': 1, '50': 1, '51': 1, '52': 1, '53': 1, '54': 1, '55': 1, '56': 1, '57': 1, | ||
'96': 1, '97': 1, '98': 1, '99': 1, '100': 1, '101': 1, '102': 1, '103': 1, '104': 1, '105': 1 | ||
}, | ||
setEnterableKeyCodes = { | ||
"money": function money(opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'188': ',' | ||
}; | ||
this.queue = []; | ||
this.openTimer = null; | ||
this.closeTimer = null; | ||
if (opts.patternArgument == "int") { | ||
// 소수점 입력 안됨 | ||
} else { | ||
enterableKeyCodes['190'] = "."; // 소수점 입력 허용 | ||
} | ||
cfg = this.config; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
var ctrlKeys = { | ||
"18": "KEY_ALT", | ||
"8": "KEY_BACKSPACE", | ||
"17": "KEY_CONTROL", | ||
"46": "KEY_DELETE", | ||
"40": "KEY_DOWN", | ||
"35": "KEY_END", | ||
"187": "KEY_EQUAL", | ||
"27": "KEY_ESC", | ||
"36": "KEY_HOME", | ||
"45": "KEY_INSERT", | ||
"37": "KEY_LEFT", | ||
"189": "KEY_MINUS", | ||
"34": "KEY_PAGEDOWN", | ||
"33": "KEY_PAGEUP", | ||
// "190": "KEY_PERIOD", | ||
"13": "KEY_RETURN", | ||
"39": "KEY_RIGHT", | ||
"16": "KEY_SHIFT", | ||
// "32": "KEY_SPACE", | ||
"9": "KEY_TAB", | ||
"38": "KEY_UP", | ||
"91": "KEY_WINDOW" | ||
//"107" : "NUMPAD_ADD", | ||
//"194" : "NUMPAD_COMMA", | ||
//"110" : "NUMPAD_DECIMAL", | ||
//"111" : "NUMPAD_DIVIDE", | ||
//"12" : "NUMPAD_EQUAL", | ||
//"106" : "NUMPAD_MULTIPLY", | ||
//"109" : "NUMPAD_SUBTRACT" | ||
}, | ||
"number": function number(opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'190': '.' | ||
}; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
numKeys = { | ||
'48': 1, '49': 1, '50': 1, '51': 1, '52': 1, '53': 1, '54': 1, '55': 1, '56': 1, '57': 1, | ||
'96': 1, '97': 1, '98': 1, '99': 1, '100': 1, '101': 1, '102': 1, '103': 1, '104': 1, '105': 1 | ||
}, | ||
"date": function date(opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'189': '-', '191': '/' | ||
}; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"time": function time(opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'186': ':' | ||
}; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"bizno": function bizno(opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'189': '-' | ||
}; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"phone": function phone(opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'189': '-', '188': ',' | ||
}; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"custom": function custom(opts, optIdx) { | ||
if (opts.getEnterableKeyCodes) { | ||
opts.enterableKeyCodes = opts.getEnterableKeyCodes.call(opts, { $input: opts.$input }); | ||
} else { | ||
opts.enterableKeyCodes = null; | ||
} | ||
} | ||
}, | ||
getPatternValue = { | ||
"money": function money(opts, optIdx, e, val, eType) { | ||
var val = val.replace(/[^0-9^\.^\-]/g, ""), | ||
regExpPattern = new RegExp('([0-9])([0-9][0-9][0-9][,.])'), | ||
arrNumber = val.split('.'), | ||
returnValue; | ||
setEnterableKeyCodes = { | ||
"money": function money(opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'188': ',' | ||
}; | ||
arrNumber[0] += '.'; | ||
if (opts.patternArgument == "int") { | ||
// 소수점 입력 안됨 | ||
} else { | ||
enterableKeyCodes['190'] = "."; // 소수점 입력 허용 | ||
} | ||
do { | ||
arrNumber[0] = arrNumber[0].replace(regExpPattern, '$1,$2'); | ||
} while (regExpPattern.test(arrNumber[0])); | ||
if (arrNumber.length > 1) { | ||
if (U.isNumber(opts.maxRound)) { | ||
returnValue = arrNumber[0] + U.left(arrNumber[1], opts.maxRound); | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"number": function number(opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'190': '.' | ||
}; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"date": function date(opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'189': '-', '191': '/' | ||
}; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"time": function time(opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'186': ':' | ||
}; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"bizno": function bizno(opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'189': '-' | ||
}; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"phone": function phone(opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'189': '-', '188': ',' | ||
}; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"custom": function custom(opts, optIdx) { | ||
if (opts.getEnterableKeyCodes) { | ||
opts.enterableKeyCodes = opts.getEnterableKeyCodes.call(opts, { $input: opts.$input }); | ||
} else { | ||
returnValue = arrNumber.join(''); | ||
opts.enterableKeyCodes = null; | ||
} | ||
} else { | ||
returnValue = arrNumber[0].split('.')[0]; | ||
} | ||
return returnValue; | ||
}, | ||
"number": function number(opts, optIdx, e, val, eType) { | ||
val = val.replace(/[^0-9^\.^\-]/g, ""); | ||
var arrNumber = val.split('.'), | ||
returnValue; | ||
getPatternValue = { | ||
"money": function money(opts, optIdx, e, val, eType) { | ||
var val = val.replace(/[^0-9^\.^\-]/g, ""), | ||
regExpPattern = new RegExp('([0-9])([0-9][0-9][0-9][,.])'), | ||
arrNumber = val.split('.'), | ||
returnValue; | ||
if (arrNumber.length > 1) { | ||
if (U.isNumber(opts.maxRound)) { | ||
returnValue = arrNumber[0] + U.left(arrNumber[1], opts.maxRound); | ||
arrNumber[0] += '.'; | ||
do { | ||
arrNumber[0] = arrNumber[0].replace(regExpPattern, '$1,$2'); | ||
} while (regExpPattern.test(arrNumber[0])); | ||
if (arrNumber.length > 1) { | ||
if (U.isNumber(opts.maxRound)) { | ||
returnValue = arrNumber[0] + U.left(arrNumber[1], opts.maxRound); | ||
} else { | ||
returnValue = arrNumber.join(''); | ||
} | ||
} else { | ||
returnValue = arrNumber.join(''); | ||
returnValue = arrNumber[0].split('.')[0]; | ||
} | ||
} else { | ||
returnValue = arrNumber[0].split('.')[0]; | ||
} | ||
return returnValue; | ||
}, | ||
"date": function date(opts, optIdx, e, val, eType) { | ||
val = val.replace(/\D/g, ""); | ||
if (val == "") return val; | ||
var regExpPattern = /^([0-9]{4})\-?([0-9]{1,2})?\-?([0-9]{1,2})?.*$/; | ||
return returnValue; | ||
}, | ||
"number": function number(opts, optIdx, e, val, eType) { | ||
val = val.replace(/[^0-9^\.^\-]/g, ""); | ||
var arrNumber = val.split('.'), | ||
returnValue; | ||
if (opts.patternArgument == "time") { | ||
regExpPattern = /^([0-9]{4})\-?([0-9]{1,2})?\-?([0-9]{1,2})? ?([0-9]{1,2})?:?([0-9]{1,2})?:?([0-9]{1,2})?.*$/; | ||
} | ||
var matchedPattern = val.match(regExpPattern), | ||
returnValue = "", | ||
inspectValue = function inspectValue(val, format, inspect, data) { | ||
var _val = { | ||
'Y': function Y(v) { | ||
if (typeof v == "undefined") v = TODAY.getFullYear(); | ||
if (v == '' || v == '0000') v = TODAY.getFullYear(); | ||
return v.length < 4 ? U.setDigit(v, 4) : v; | ||
}, | ||
'M': function M(v) { | ||
if (typeof v == "undefined") v = TODAY.getMonth() + 1; | ||
return v > 12 ? 12 : v == 0 ? '01' : U.setDigit(v, 2); | ||
}, | ||
'D': function D(v) { | ||
if (typeof v == "undefined") v = TODAY.getDate() + 1; | ||
var dLen = U.daysOfMonth(data[1], data[2] - 1); | ||
return v > dLen ? dLen : v == 0 ? '01' : U.setDigit(v, 2); | ||
}, | ||
'h': function h(v) { | ||
if (!v) v = 0; | ||
return v > 23 ? 23 : U.setDigit(v, 2); | ||
}, | ||
'm': function m(v) { | ||
if (!v) v = 0; | ||
return v > 59 ? 59 : U.setDigit(v, 2); | ||
}, | ||
's': function s(v) { | ||
if (!v) v = 0; | ||
return v > 59 ? 59 : U.setDigit(v, 2); | ||
if (arrNumber.length > 1) { | ||
if (U.isNumber(opts.maxRound)) { | ||
returnValue = arrNumber[0] + U.left(arrNumber[1], opts.maxRound); | ||
} else { | ||
returnValue = arrNumber.join(''); | ||
} | ||
}; | ||
return inspect ? _val[format](val) : val; | ||
}; | ||
} else { | ||
returnValue = arrNumber[0].split('.')[0]; | ||
} | ||
returnValue = val.replace(regExpPattern, function (a, b) { | ||
var nval = [inspectValue(arguments[1], "Y", eType)]; | ||
if (arguments[2] || eType) nval.push('-' + inspectValue(arguments[2], "M", eType)); | ||
if (arguments[3] || eType) nval.push('-' + inspectValue(arguments[3], "D", eType, arguments)); | ||
return returnValue; | ||
}, | ||
"date": function date(opts, optIdx, e, val, eType) { | ||
val = val.replace(/\D/g, ""); | ||
if (val == "") return val; | ||
var regExpPattern = /^([0-9]{4})\-?([0-9]{1,2})?\-?([0-9]{1,2})?.*$/; | ||
if (opts.patternArgument == "time") { | ||
if (arguments[4] || eType) nval.push(' ' + inspectValue(arguments[4], "h", eType)); | ||
if (arguments[5] || eType) nval.push(':' + inspectValue(arguments[5], "m", eType)); | ||
if (arguments[6] || eType) nval.push(':' + inspectValue(arguments[6], "s", eType)); | ||
regExpPattern = /^([0-9]{4})\-?([0-9]{1,2})?\-?([0-9]{1,2})? ?([0-9]{1,2})?:?([0-9]{1,2})?:?([0-9]{1,2})?.*$/; | ||
} | ||
return nval.join(''); | ||
}); | ||
if (eType == 'blur' && !matchedPattern) { | ||
returnValue = function () { | ||
var nval = [inspectValue(returnValue, "Y", eType)]; | ||
nval.push('-' + inspectValue(0, "M", eType)); | ||
nval.push('-' + inspectValue(0, "D", eType, arguments)); | ||
var matchedPattern = val.match(regExpPattern), | ||
returnValue = "", | ||
inspectValue = function inspectValue(val, format, inspect, data) { | ||
var _val = { | ||
'Y': function Y(v) { | ||
if (typeof v == "undefined") v = TODAY.getFullYear(); | ||
if (v == '' || v == '0000') v = TODAY.getFullYear(); | ||
return v.length < 4 ? U.setDigit(v, 4) : v; | ||
}, | ||
'M': function M(v) { | ||
if (typeof v == "undefined") v = TODAY.getMonth() + 1; | ||
return v > 12 ? 12 : v == 0 ? '01' : U.setDigit(v, 2); | ||
}, | ||
'D': function D(v) { | ||
if (typeof v == "undefined") v = TODAY.getDate() + 1; | ||
var dLen = U.daysOfMonth(data[1], data[2] - 1); | ||
return v > dLen ? dLen : v == 0 ? '01' : U.setDigit(v, 2); | ||
}, | ||
'h': function h(v) { | ||
if (!v) v = 0; | ||
return v > 23 ? 23 : U.setDigit(v, 2); | ||
}, | ||
'm': function m(v) { | ||
if (!v) v = 0; | ||
return v > 59 ? 59 : U.setDigit(v, 2); | ||
}, | ||
's': function s(v) { | ||
if (!v) v = 0; | ||
return v > 59 ? 59 : U.setDigit(v, 2); | ||
} | ||
}; | ||
return inspect ? _val[format](val) : val; | ||
}; | ||
returnValue = val.replace(regExpPattern, function (a, b) { | ||
var nval = [inspectValue(arguments[1], "Y", eType)]; | ||
if (arguments[2] || eType) nval.push('-' + inspectValue(arguments[2], "M", eType)); | ||
if (arguments[3] || eType) nval.push('-' + inspectValue(arguments[3], "D", eType, arguments)); | ||
if (opts.patternArgument == "time") { | ||
nval.push(' ' + inspectValue(0, "h", eType)); | ||
nval.push(':' + inspectValue(0, "m", eType)); | ||
nval.push(':' + inspectValue(0, "s", eType)); | ||
if (arguments[4] || eType) nval.push(' ' + inspectValue(arguments[4], "h", eType)); | ||
if (arguments[5] || eType) nval.push(':' + inspectValue(arguments[5], "m", eType)); | ||
if (arguments[6] || eType) nval.push(':' + inspectValue(arguments[6], "s", eType)); | ||
} | ||
return nval.join(''); | ||
}(); | ||
} else if (!matchedPattern) returnValue = returnValue.length > 4 ? U.left(returnValue, 4) : returnValue; | ||
}); | ||
return returnValue; | ||
}, | ||
"time": function time(opts, optIdx, e, val, eType) { | ||
val = val.replace(/\D/g, ""); | ||
var regExpPattern = /^([0-9]{1,2})?:?([0-9]{1,2})?:?([0-9]{1,2})?.*$/; | ||
if (eType == 'blur' && !matchedPattern) { | ||
returnValue = function () { | ||
var nval = [inspectValue(returnValue, "Y", eType)]; | ||
nval.push('-' + inspectValue(0, "M", eType)); | ||
nval.push('-' + inspectValue(0, "D", eType, arguments)); | ||
if (opts.patternArgument == "time") { | ||
nval.push(' ' + inspectValue(0, "h", eType)); | ||
nval.push(':' + inspectValue(0, "m", eType)); | ||
nval.push(':' + inspectValue(0, "s", eType)); | ||
} | ||
return nval.join(''); | ||
}(); | ||
} else if (!matchedPattern) returnValue = returnValue.length > 4 ? U.left(returnValue, 4) : returnValue; | ||
var matchedPattern = val.match(regExpPattern), | ||
returnValue = val.replace(regExpPattern, function (a, b) { | ||
var nval = [arguments[1]]; | ||
if (arguments[2]) nval.push(':' + arguments[2]); | ||
if (arguments[3]) nval.push(':' + arguments[3]); | ||
return nval.join(''); | ||
}); | ||
return returnValue; | ||
}, | ||
"time": function time(opts, optIdx, e, val, eType) { | ||
val = val.replace(/\D/g, ""); | ||
var regExpPattern = /^([0-9]{1,2})?:?([0-9]{1,2})?:?([0-9]{1,2})?.*$/; | ||
if (!matchedPattern) returnValue = returnValue.length > 2 ? U.left(returnValue, 2) : returnValue; | ||
var matchedPattern = val.match(regExpPattern), | ||
returnValue = val.replace(regExpPattern, function (a, b) { | ||
var nval = [arguments[1]]; | ||
if (arguments[2]) nval.push(':' + arguments[2]); | ||
if (arguments[3]) nval.push(':' + arguments[3]); | ||
return nval.join(''); | ||
}); | ||
return returnValue; | ||
}, | ||
"bizno": function bizno(opts, optIdx, e, val, eType) { | ||
val = val.replace(/\D/g, ""); | ||
var regExpPattern = /^([0-9]{3})\-?([0-9]{1,2})?\-?([0-9]{1,5})?.*$/, | ||
returnValue = val.replace(regExpPattern, function (a, b) { | ||
var nval = [arguments[1]]; | ||
if (arguments[2]) nval.push(arguments[2]); | ||
if (arguments[3]) nval.push(arguments[3]); | ||
return nval.join("-"); | ||
}); | ||
if (!matchedPattern) returnValue = returnValue.length > 2 ? U.left(returnValue, 2) : returnValue; | ||
return returnValue; | ||
}, | ||
"phone": function phone(opts, optIdx, e, val, eType) { | ||
val = val.replace(/\D/g, ""); | ||
var regExpPattern3 = /^([0-9]{3})\-?([0-9]{1,4})?\-?([0-9]{1,4})?\-?([0-9]{1,4})?\-?([0-9]{1,4})?/, | ||
returnValue = val.replace(regExpPattern3, function (a, b) { | ||
var nval = [arguments[1]]; | ||
if (arguments[2]) nval.push(arguments[2]); | ||
if (arguments[3]) nval.push(arguments[3]); | ||
if (arguments[4]) nval.push(arguments[4]); | ||
if (arguments[5]) nval.push(arguments[5]); | ||
return nval.join("-"); | ||
}); | ||
return returnValue; | ||
}, | ||
"custom": function custom(opts, optIdx, e, val, eType) { | ||
if (opts.getPatternValue) { | ||
return opts.getPatternValue.call(opts, { event: e, $input: opts.$input, value: val }); | ||
return returnValue; | ||
}, | ||
"bizno": function bizno(opts, optIdx, e, val, eType) { | ||
val = val.replace(/\D/g, ""); | ||
var regExpPattern = /^([0-9]{3})\-?([0-9]{1,2})?\-?([0-9]{1,5})?.*$/, | ||
returnValue = val.replace(regExpPattern, function (a, b) { | ||
var nval = [arguments[1]]; | ||
if (arguments[2]) nval.push(arguments[2]); | ||
if (arguments[3]) nval.push(arguments[3]); | ||
return nval.join("-"); | ||
}); | ||
return returnValue; | ||
}, | ||
"phone": function phone(opts, optIdx, e, val, eType) { | ||
val = val.replace(/\D/g, ""); | ||
var regExpPattern3 = /^([0-9]{3})\-?([0-9]{1,4})?\-?([0-9]{1,4})?\-?([0-9]{1,4})?\-?([0-9]{1,4})?/, | ||
returnValue = val.replace(regExpPattern3, function (a, b) { | ||
var nval = [arguments[1]]; | ||
if (arguments[2]) nval.push(arguments[2]); | ||
if (arguments[3]) nval.push(arguments[3]); | ||
if (arguments[4]) nval.push(arguments[4]); | ||
if (arguments[5]) nval.push(arguments[5]); | ||
return nval.join("-"); | ||
}); | ||
return returnValue; | ||
}, | ||
"custom": function custom(opts, optIdx, e, val, eType) { | ||
if (opts.getPatternValue) { | ||
return opts.getPatternValue.call(opts, { event: e, $input: opts.$input, value: val }); | ||
} | ||
} | ||
} | ||
}, | ||
formatterEvent = { | ||
'focus': function focus(opts, optIdx, e) { | ||
if (!opts.$input.data("__originValue__")) opts.$input.data("__originValue__", opts.$input.val()); | ||
}, | ||
/* 키 다운 이벤트에서 입력할 수 없는 키 입력을 방어 */ | ||
'keydown': function keydown(opts, optIdx, e) { | ||
var isStop = false; | ||
if (!opts.enterableKeyCodes) {} else if (e.which && opts.enterableKeyCodes[e.which]) {} else if (!e.metaKey && !e.ctrlKey && !e.shiftKey) { | ||
//console.log(e.which, opts.enterableKeyCodes); | ||
isStop = true; | ||
} | ||
if (isStop) ax5.util.stopEvent(e); | ||
}, | ||
/* 키 업 이벤트에서 패턴을 적용 */ | ||
'keyup': function keyup(opts, optIdx, e) { | ||
var elem = opts.$input.get(0), | ||
elemFocusPosition, | ||
beforeValue, | ||
newValue, | ||
selection, | ||
selectionLength; | ||
formatterEvent = { | ||
'focus': function focus(opts, optIdx, e) { | ||
if (!opts.$input.data("__originValue__")) opts.$input.data("__originValue__", opts.$input.val()); | ||
}, | ||
/* 키 다운 이벤트에서 입력할 수 없는 키 입력을 방어 */ | ||
'keydown': function keydown(opts, optIdx, e) { | ||
var isStop = false; | ||
if (!opts.enterableKeyCodes) {} else if (e.which && opts.enterableKeyCodes[e.which]) {} else if (!e.metaKey && !e.ctrlKey && !e.shiftKey) { | ||
//console.log(e.which, opts.enterableKeyCodes); | ||
isStop = true; | ||
} | ||
if (isStop) ax5.util.stopEvent(e); | ||
}, | ||
/* 키 업 이벤트에서 패턴을 적용 */ | ||
'keyup': function keyup(opts, optIdx, e) { | ||
var elem = opts.$input.get(0), | ||
elemFocusPosition, | ||
beforeValue, | ||
newValue, | ||
selection, | ||
selectionLength; | ||
if ('selectionStart' in elem) { | ||
// Standard-compliant browsers | ||
elemFocusPosition = elem.selectionStart; | ||
} else if (document.selection) { | ||
// IE | ||
//elem.focus(); | ||
selection = document.selection.createRange(); | ||
selectionLength = document.selection.createRange().text.length; | ||
selection.moveStart('character', -elem.value.length); | ||
elemFocusPosition = selection.text.length - selectionLength; | ||
} | ||
if ('selectionStart' in elem) { | ||
// Standard-compliant browsers | ||
elemFocusPosition = elem.selectionStart; | ||
} else if (document.selection) { | ||
// IE | ||
//elem.focus(); | ||
selection = document.selection.createRange(); | ||
selectionLength = document.selection.createRange().text.length; | ||
selection.moveStart('character', -elem.value.length); | ||
elemFocusPosition = selection.text.length - selectionLength; | ||
} | ||
beforeValue = elem.value; | ||
newValue = getPatternValue[opts.pattern] ? getPatternValue[opts.pattern].call(this, opts, optIdx, e, elem.value) : beforeValue; | ||
beforeValue = elem.value; | ||
newValue = getPatternValue[opts.pattern] ? getPatternValue[opts.pattern].call(this, opts, optIdx, e, elem.value) : beforeValue; | ||
if (newValue != beforeValue) { | ||
opts.$input.val(newValue).trigger("change"); | ||
setSelectionRange(elem, elemFocusPosition + newValue.length - beforeValue.length); | ||
} | ||
}, | ||
'blur': function blur(opts, optIdx, e) { | ||
var elem = opts.$input.get(0), | ||
beforeValue, | ||
newValue; | ||
if (newValue != beforeValue) { | ||
opts.$input.val(newValue).trigger("change"); | ||
setSelectionRange(elem, elemFocusPosition + newValue.length - beforeValue.length); | ||
} | ||
}, | ||
'blur': function blur(opts, optIdx, e) { | ||
var elem = opts.$input.get(0), | ||
beforeValue, | ||
newValue; | ||
opts.$input.removeData("__originValue__"); | ||
opts.$input.removeData("__originValue__"); | ||
beforeValue = elem.value; | ||
newValue = getPatternValue[opts.pattern] ? getPatternValue[opts.pattern].call(this, opts, optIdx, e, elem.value, 'blur') : beforeValue; | ||
if (newValue != beforeValue) { | ||
opts.$input.val(newValue).trigger("change"); | ||
beforeValue = elem.value; | ||
newValue = getPatternValue[opts.pattern] ? getPatternValue[opts.pattern].call(this, opts, optIdx, e, elem.value, 'blur') : beforeValue; | ||
if (newValue != beforeValue) { | ||
opts.$input.val(newValue).trigger("change"); | ||
} | ||
} | ||
} | ||
}, | ||
bindFormatterTarget = function bindFormatterTarget(opts, optIdx) { | ||
}, | ||
bindFormatterTarget = function bindFormatterTarget(opts, optIdx) { | ||
if (!opts.pattern) { | ||
if (opts.$target.get(0).tagName == "INPUT") { | ||
opts.pattern = opts.$target.attr('data-ax5formatter'); | ||
} else { | ||
opts.pattern = opts.$target.find('input[type="text"]').attr('data-ax5formatter'); | ||
} | ||
if (!opts.pattern) { | ||
console.log(ax5.info.getError("ax5formatter", "501", "bind")); | ||
console.log(opts.target); | ||
return this; | ||
if (opts.$target.get(0).tagName == "INPUT") { | ||
opts.pattern = opts.$target.attr('data-ax5formatter'); | ||
} else { | ||
opts.pattern = opts.$target.find('input[type="text"]').attr('data-ax5formatter'); | ||
} | ||
if (!opts.pattern) { | ||
console.log(ax5.info.getError("ax5formatter", "501", "bind")); | ||
console.log(opts.target); | ||
return this; | ||
} | ||
} | ||
} | ||
var re = /[^\(^\))]+/gi, | ||
matched = opts.pattern.match(re); | ||
var re = /[^\(^\))]+/gi, | ||
matched = opts.pattern.match(re); | ||
opts.pattern = matched[0]; | ||
opts.patternArgument = matched[1] || ""; | ||
opts.pattern = matched[0]; | ||
opts.patternArgument = matched[1] || ""; | ||
// 함수타입 | ||
for (var key in setEnterableKeyCodes) { | ||
if (opts.pattern == key) { | ||
setEnterableKeyCodes[key].call(this, opts, optIdx); | ||
break; | ||
// 함수타입 | ||
for (var key in setEnterableKeyCodes) { | ||
if (opts.pattern == key) { | ||
setEnterableKeyCodes[key].call(this, opts, optIdx); | ||
break; | ||
} | ||
} | ||
} | ||
opts.$input.unbind('focus.ax5formatter').bind('focus.ax5formatter', formatterEvent.focus.bind(this, this.queue[optIdx], optIdx)); | ||
opts.$input.unbind('focus.ax5formatter').bind('focus.ax5formatter', formatterEvent.focus.bind(this, this.queue[optIdx], optIdx)); | ||
opts.$input.unbind('keydown.ax5formatter').bind('keydown.ax5formatter', formatterEvent.keydown.bind(this, this.queue[optIdx], optIdx)); | ||
opts.$input.unbind('keydown.ax5formatter').bind('keydown.ax5formatter', formatterEvent.keydown.bind(this, this.queue[optIdx], optIdx)); | ||
opts.$input.unbind('keyup.ax5formatter').bind('keyup.ax5formatter', formatterEvent.keyup.bind(this, this.queue[optIdx], optIdx)); | ||
opts.$input.unbind('keyup.ax5formatter').bind('keyup.ax5formatter', formatterEvent.keyup.bind(this, this.queue[optIdx], optIdx)); | ||
opts.$input.unbind('blur.ax5formatter').bind('blur.ax5formatter', formatterEvent.blur.bind(this, this.queue[optIdx], optIdx)); | ||
opts.$input.unbind('blur.ax5formatter').bind('blur.ax5formatter', formatterEvent.blur.bind(this, this.queue[optIdx], optIdx)); | ||
formatterEvent.blur.call(this, this.queue[optIdx], optIdx); | ||
formatterEvent.blur.call(this, this.queue[optIdx], optIdx); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
/** | ||
* Preferences of formatter UI | ||
* @method ax5.ui.formatter.setConfig | ||
* @param {Object} config - 클래스 속성값 | ||
* @returns {ax5.ui.formatter} | ||
* @example | ||
* ``` | ||
* ``` | ||
*/ | ||
this.init = function () {}; | ||
/** | ||
* Preferences of formatter UI | ||
* @method ax5.ui.formatter.setConfig | ||
* @param {Object} config - 클래스 속성값 | ||
* @returns {ax5.ui.formatter} | ||
* @example | ||
* ``` | ||
* ``` | ||
*/ | ||
this.init = function () {}; | ||
this.bind = function (opts) { | ||
var formatterConfig = {}, | ||
optIdx; | ||
this.bind = function (opts) { | ||
var formatterConfig = {}, | ||
optIdx; | ||
jQuery.extend(true, formatterConfig, cfg); | ||
if (opts) jQuery.extend(true, formatterConfig, opts); | ||
opts = formatterConfig; | ||
jQuery.extend(true, formatterConfig, cfg); | ||
if (opts) jQuery.extend(true, formatterConfig, opts); | ||
opts = formatterConfig; | ||
if (!opts.target) { | ||
console.log(ax5.info.getError("ax5formatter", "401", "bind")); | ||
return this; | ||
} | ||
opts.$target = jQuery(opts.target); | ||
if (opts.$target.get(0).tagName == "INPUT") { | ||
opts.$input = opts.$target; | ||
} else { | ||
opts.$input = opts.$target.find('input[type="text"]'); | ||
if (opts.$input.length > 1) { | ||
opts.$input.each(function () { | ||
opts.target = this; | ||
self.bind(opts); | ||
}); | ||
if (!opts.target) { | ||
console.log(ax5.info.getError("ax5formatter", "401", "bind")); | ||
return this; | ||
} | ||
} | ||
opts.$target = jQuery(opts.target); | ||
opts.$input = opts.$target.get(0).tagName == "INPUT" ? opts.$target : opts.$target.find('input[type="text"]'); | ||
if (!opts.id) opts.id = opts.$input.data("ax5-formatter"); | ||
if (opts.$target.get(0).tagName == "INPUT") { | ||
opts.$input = opts.$target; | ||
} else { | ||
opts.$input = opts.$target.find('input[type="text"]'); | ||
if (opts.$input.length > 1) { | ||
opts.$input.each(function () { | ||
opts.target = this; | ||
self.bind(opts); | ||
}); | ||
return this; | ||
} | ||
} | ||
if (!opts.id) { | ||
opts.id = 'ax5-formatter-' + ax5.getGuid(); | ||
opts.$input.data("ax5-formatter", opts.id); | ||
} | ||
optIdx = U.search(this.queue, function () { | ||
return this.id == opts.id; | ||
}); | ||
opts.$input = opts.$target.get(0).tagName == "INPUT" ? opts.$target : opts.$target.find('input[type="text"]'); | ||
if (!opts.id) opts.id = opts.$input.data("ax5-formatter"); | ||
if (optIdx === -1) { | ||
this.queue.push(opts); | ||
bindFormatterTarget.call(this, this.queue[this.queue.length - 1], this.queue.length - 1); | ||
} else { | ||
this.queue[optIdx] = opts; | ||
bindFormatterTarget.call(this, this.queue[optIdx], optIdx); | ||
} | ||
if (!opts.id) { | ||
opts.id = 'ax5-formatter-' + ax5.getGuid(); | ||
opts.$input.data("ax5-formatter", opts.id); | ||
} | ||
optIdx = U.search(this.queue, function () { | ||
return this.id == opts.id; | ||
}); | ||
return this; | ||
}; | ||
if (optIdx === -1) { | ||
this.queue.push(opts); | ||
bindFormatterTarget.call(this, this.queue[this.queue.length - 1], this.queue.length - 1); | ||
} else { | ||
this.queue[optIdx] = opts; | ||
bindFormatterTarget.call(this, this.queue[optIdx], optIdx); | ||
} | ||
// 클래스 생성자 | ||
this.main = function () { | ||
if (arguments && U.isObject(arguments[0])) { | ||
this.setConfig(arguments[0]); | ||
} | ||
}.apply(this, arguments); | ||
}; | ||
return this; | ||
}; | ||
ROOT.formatter = function () { | ||
if (U.isFunction(_SUPER_)) ax5formatter.prototype = new _SUPER_(); // 상속 | ||
// 클래스 생성자 | ||
this.main = function () { | ||
if (arguments && U.isObject(arguments[0])) { | ||
this.setConfig(arguments[0]); | ||
} | ||
}.apply(this, arguments); | ||
}; | ||
return ax5formatter; | ||
}(); // ax5.ui에 연결 | ||
}()); | ||
})(); | ||
@@ -482,0 +472,0 @@ |
@@ -1,1 +0,1 @@ | ||
"use strict";!function(){var t=ax5.ui,e=ax5.ui.root,n=ax5.util,r="ax5formatter",a="0.5.1",u=new Date,i=function(t,e){if("undefined"==typeof e&&(e=t.value.length),t.setSelectionRange)t.focus(),t.setSelectionRange(e,e);else if(t.createTextRange){var n=t.createTextRange();n.collapse(!0),n.moveEnd("character",e),n.moveStart("character",e),n.select()}else t.selectionStart&&(t.focus(),t.selectionStart=e,t.selectionEnd=e)},s=function(){var t,s=this;e&&e.call(this),this.name=r,this.version=a,this.instanceId=ax5.getGuid(),this.config={animateTime:250},this.queue=[],this.openTimer=null,this.closeTimer=null,t=this.config;var o={18:"KEY_ALT",8:"KEY_BACKSPACE",17:"KEY_CONTROL",46:"KEY_DELETE",40:"KEY_DOWN",35:"KEY_END",187:"KEY_EQUAL",27:"KEY_ESC",36:"KEY_HOME",45:"KEY_INSERT",37:"KEY_LEFT",189:"KEY_MINUS",34:"KEY_PAGEDOWN",33:"KEY_PAGEUP",13:"KEY_RETURN",39:"KEY_RIGHT",16:"KEY_SHIFT",9:"KEY_TAB",38:"KEY_UP",91:"KEY_WINDOW"},g={48:1,49:1,50:1,51:1,52:1,53:1,54:1,55:1,56:1,57:1,96:1,97:1,98:1,99:1,100:1,101:1,102:1,103:1,104:1,105:1},l={money:function(t,e){var n={188:","};"int"==t.patternArgument||(n[190]="."),t.enterableKeyCodes=$.extend(n,o,g)},number:function(t,e){var n={190:"."};t.enterableKeyCodes=$.extend(n,o,g)},date:function(t,e){var n={189:"-",191:"/"};t.enterableKeyCodes=$.extend(n,o,g)},time:function(t,e){var n={186:":"};t.enterableKeyCodes=$.extend(n,o,g)},bizno:function(t,e){var n={189:"-"};t.enterableKeyCodes=$.extend(n,o,g)},phone:function(t,e){var n={189:"-",188:","};t.enterableKeyCodes=$.extend(n,o,g)},custom:function(t,e){t.getEnterableKeyCodes?t.enterableKeyCodes=t.getEnterableKeyCodes.call(t,{$input:t.$input}):t.enterableKeyCodes=null}},c={money:function(t,e,r,a,u){var i,a=a.replace(/[^0-9^\.^\-]/g,""),s=new RegExp("([0-9])([0-9][0-9][0-9][,.])"),o=a.split(".");o[0]+=".";do o[0]=o[0].replace(s,"$1,$2");while(s.test(o[0]));return i=o.length>1?n.isNumber(t.maxRound)?o[0]+n.left(o[1],t.maxRound):o.join(""):o[0].split(".")[0]},number:function(t,e,r,a,u){a=a.replace(/[^0-9^\.^\-]/g,"");var i,s=a.split(".");return i=s.length>1?n.isNumber(t.maxRound)?s[0]+n.left(s[1],t.maxRound):s.join(""):s[0].split(".")[0]},date:function(t,e,r,a,i){if(a=a.replace(/\D/g,""),""==a)return a;var s=/^([0-9]{4})\-?([0-9]{1,2})?\-?([0-9]{1,2})?.*$/;"time"==t.patternArgument&&(s=/^([0-9]{4})\-?([0-9]{1,2})?\-?([0-9]{1,2})? ?([0-9]{1,2})?:?([0-9]{1,2})?:?([0-9]{1,2})?.*$/);var o=a.match(s),g="",l=function(t,e,r,a){var i={Y:function(t){return"undefined"==typeof t&&(t=u.getFullYear()),(""==t||"0000"==t)&&(t=u.getFullYear()),t.length<4?n.setDigit(t,4):t},M:function(t){return"undefined"==typeof t&&(t=u.getMonth()+1),t>12?12:0==t?"01":n.setDigit(t,2)},D:function(t){"undefined"==typeof t&&(t=u.getDate()+1);var e=n.daysOfMonth(a[1],a[2]-1);return t>e?e:0==t?"01":n.setDigit(t,2)},h:function(t){return t||(t=0),t>23?23:n.setDigit(t,2)},m:function(t){return t||(t=0),t>59?59:n.setDigit(t,2)},s:function(t){return t||(t=0),t>59?59:n.setDigit(t,2)}};return r?i[e](t):t};return g=a.replace(s,function(e,n){var r=[l(arguments[1],"Y",i)];return(arguments[2]||i)&&r.push("-"+l(arguments[2],"M",i)),(arguments[3]||i)&&r.push("-"+l(arguments[3],"D",i,arguments)),"time"==t.patternArgument&&((arguments[4]||i)&&r.push(" "+l(arguments[4],"h",i)),(arguments[5]||i)&&r.push(":"+l(arguments[5],"m",i)),(arguments[6]||i)&&r.push(":"+l(arguments[6],"s",i))),r.join("")}),"blur"!=i||o?o||(g=g.length>4?n.left(g,4):g):g=function(){var e=[l(g,"Y",i)];return e.push("-"+l(0,"M",i)),e.push("-"+l(0,"D",i,arguments)),"time"==t.patternArgument&&(e.push(" "+l(0,"h",i)),e.push(":"+l(0,"m",i)),e.push(":"+l(0,"s",i))),e.join("")}(),g},time:function(t,e,r,a,u){a=a.replace(/\D/g,"");var i=/^([0-9]{1,2})?:?([0-9]{1,2})?:?([0-9]{1,2})?.*$/,s=a.match(i),o=a.replace(i,function(t,e){var n=[arguments[1]];return arguments[2]&&n.push(":"+arguments[2]),arguments[3]&&n.push(":"+arguments[3]),n.join("")});return s||(o=o.length>2?n.left(o,2):o),o},bizno:function(t,e,n,r,a){r=r.replace(/\D/g,"");var u=/^([0-9]{3})\-?([0-9]{1,2})?\-?([0-9]{1,5})?.*$/,i=r.replace(u,function(t,e){var n=[arguments[1]];return arguments[2]&&n.push(arguments[2]),arguments[3]&&n.push(arguments[3]),n.join("-")});return i},phone:function(t,e,n,r,a){r=r.replace(/\D/g,"");var u=/^([0-9]{3})\-?([0-9]{1,4})?\-?([0-9]{1,4})?\-?([0-9]{1,4})?\-?([0-9]{1,4})?/,i=r.replace(u,function(t,e){var n=[arguments[1]];return arguments[2]&&n.push(arguments[2]),arguments[3]&&n.push(arguments[3]),arguments[4]&&n.push(arguments[4]),arguments[5]&&n.push(arguments[5]),n.join("-")});return i},custom:function(t,e,n,r,a){return t.getPatternValue?t.getPatternValue.call(t,{event:n,$input:t.$input,value:r}):void 0}},f={focus:function(t,e,n){t.$input.data("__originValue__")||t.$input.data("__originValue__",t.$input.val())},keydown:function(t,e,n){var r=!1;t.enterableKeyCodes&&(n.which&&t.enterableKeyCodes[n.which]||n.metaKey||n.ctrlKey||n.shiftKey||(r=!0)),r&&ax5.util.stopEvent(n)},keyup:function(t,e,n){var r,a,u,s,o,g=t.$input.get(0);"selectionStart"in g?r=g.selectionStart:document.selection&&(s=document.selection.createRange(),o=document.selection.createRange().text.length,s.moveStart("character",-g.value.length),r=s.text.length-o),a=g.value,u=c[t.pattern]?c[t.pattern].call(this,t,e,n,g.value):a,u!=a&&(t.$input.val(u).trigger("change"),i(g,r+u.length-a.length))},blur:function(t,e,n){var r,a,u=t.$input.get(0);t.$input.removeData("__originValue__"),r=u.value,a=c[t.pattern]?c[t.pattern].call(this,t,e,n,u.value,"blur"):r,a!=r&&t.$input.val(a).trigger("change")}},h=function(t,e){if(!t.pattern&&("INPUT"==t.$target.get(0).tagName?t.pattern=t.$target.attr("data-ax5formatter"):t.pattern=t.$target.find('input[type="text"]').attr("data-ax5formatter"),!t.pattern))return console.log(ax5.info.getError("ax5formatter","501","bind")),console.log(t.target),this;var n=/[^\(^\))]+/gi,r=t.pattern.match(n);t.pattern=r[0],t.patternArgument=r[1]||"";for(var a in l)if(t.pattern==a){l[a].call(this,t,e);break}return t.$input.unbind("focus.ax5formatter").bind("focus.ax5formatter",f.focus.bind(this,this.queue[e],e)),t.$input.unbind("keydown.ax5formatter").bind("keydown.ax5formatter",f.keydown.bind(this,this.queue[e],e)),t.$input.unbind("keyup.ax5formatter").bind("keyup.ax5formatter",f.keyup.bind(this,this.queue[e],e)),t.$input.unbind("blur.ax5formatter").bind("blur.ax5formatter",f.blur.bind(this,this.queue[e],e)),f.blur.call(this,this.queue[e],e),this};this.init=function(){},this.bind=function(e){var r,a={};if(jQuery.extend(!0,a,t),e&&jQuery.extend(!0,a,e),e=a,!e.target)return console.log(ax5.info.getError("ax5formatter","401","bind")),this;if(e.$target=jQuery(e.target),"INPUT"==e.$target.get(0).tagName)e.$input=e.$target;else if(e.$input=e.$target.find('input[type="text"]'),e.$input.length>1)return e.$input.each(function(){e.target=this,s.bind(e)}),this;return e.$input="INPUT"==e.$target.get(0).tagName?e.$target:e.$target.find('input[type="text"]'),e.id||(e.id=e.$input.data("ax5-formatter")),e.id||(e.id="ax5-formatter-"+ax5.getGuid(),e.$input.data("ax5-formatter",e.id)),r=n.search(this.queue,function(){return this.id==e.id}),-1===r?(this.queue.push(e),h.call(this,this.queue[this.queue.length-1],this.queue.length-1)):(this.queue[r]=e,h.call(this,this.queue[r],r)),this},this.main=function(){arguments&&n.isObject(arguments[0])&&this.setConfig(arguments[0])}.apply(this,arguments)};t.formatter=function(){return n.isFunction(e)&&(s.prototype=new e),s}()}(),ax5.ui.formatter_instance=new ax5.ui.formatter,$.fn.ax5formatter=function(){return function(t){return"undefined"==typeof t&&(t={}),$.each(this,function(){var e={target:this};t=$.extend(!0,t,e),ax5.ui.formatter_instance.bind(t)}),this}}(); | ||
"use strict";!function(){var t=ax5.ui,e=ax5.util;t.addClass({className:"formatter",version:"0.5.2"},function(){var t=new Date,n=function(t,e){if("undefined"==typeof e&&(e=t.value.length),t.setSelectionRange)t.focus(),t.setSelectionRange(e,e);else if(t.createTextRange){var n=t.createTextRange();n.collapse(!0),n.moveEnd("character",e),n.moveStart("character",e),n.select()}else t.selectionStart&&(t.focus(),t.selectionStart=e,t.selectionEnd=e)},r=function(){var r,a=this;this.config={animateTime:250},this.queue=[],this.openTimer=null,this.closeTimer=null,r=this.config;var u={18:"KEY_ALT",8:"KEY_BACKSPACE",17:"KEY_CONTROL",46:"KEY_DELETE",40:"KEY_DOWN",35:"KEY_END",187:"KEY_EQUAL",27:"KEY_ESC",36:"KEY_HOME",45:"KEY_INSERT",37:"KEY_LEFT",189:"KEY_MINUS",34:"KEY_PAGEDOWN",33:"KEY_PAGEUP",13:"KEY_RETURN",39:"KEY_RIGHT",16:"KEY_SHIFT",9:"KEY_TAB",38:"KEY_UP",91:"KEY_WINDOW"},i={48:1,49:1,50:1,51:1,52:1,53:1,54:1,55:1,56:1,57:1,96:1,97:1,98:1,99:1,100:1,101:1,102:1,103:1,104:1,105:1},s={money:function(t,e){var n={188:","};"int"==t.patternArgument||(n[190]="."),t.enterableKeyCodes=$.extend(n,u,i)},number:function(t,e){var n={190:"."};t.enterableKeyCodes=$.extend(n,u,i)},date:function(t,e){var n={189:"-",191:"/"};t.enterableKeyCodes=$.extend(n,u,i)},time:function(t,e){var n={186:":"};t.enterableKeyCodes=$.extend(n,u,i)},bizno:function(t,e){var n={189:"-"};t.enterableKeyCodes=$.extend(n,u,i)},phone:function(t,e){var n={189:"-",188:","};t.enterableKeyCodes=$.extend(n,u,i)},custom:function(t,e){t.getEnterableKeyCodes?t.enterableKeyCodes=t.getEnterableKeyCodes.call(t,{$input:t.$input}):t.enterableKeyCodes=null}},o={money:function(t,n,r,a,u){var i,a=a.replace(/[^0-9^\.^\-]/g,""),s=new RegExp("([0-9])([0-9][0-9][0-9][,.])"),o=a.split(".");o[0]+=".";do o[0]=o[0].replace(s,"$1,$2");while(s.test(o[0]));return i=o.length>1?e.isNumber(t.maxRound)?o[0]+e.left(o[1],t.maxRound):o.join(""):o[0].split(".")[0]},number:function(t,n,r,a,u){a=a.replace(/[^0-9^\.^\-]/g,"");var i,s=a.split(".");return i=s.length>1?e.isNumber(t.maxRound)?s[0]+e.left(s[1],t.maxRound):s.join(""):s[0].split(".")[0]},date:function(n,r,a,u,i){if(u=u.replace(/\D/g,""),""==u)return u;var s=/^([0-9]{4})\-?([0-9]{1,2})?\-?([0-9]{1,2})?.*$/;"time"==n.patternArgument&&(s=/^([0-9]{4})\-?([0-9]{1,2})?\-?([0-9]{1,2})? ?([0-9]{1,2})?:?([0-9]{1,2})?:?([0-9]{1,2})?.*$/);var o=u.match(s),g="",l=function(n,r,a,u){var i={Y:function(n){return"undefined"==typeof n&&(n=t.getFullYear()),(""==n||"0000"==n)&&(n=t.getFullYear()),n.length<4?e.setDigit(n,4):n},M:function(n){return"undefined"==typeof n&&(n=t.getMonth()+1),n>12?12:0==n?"01":e.setDigit(n,2)},D:function(n){"undefined"==typeof n&&(n=t.getDate()+1);var r=e.daysOfMonth(u[1],u[2]-1);return n>r?r:0==n?"01":e.setDigit(n,2)},h:function(t){return t||(t=0),t>23?23:e.setDigit(t,2)},m:function(t){return t||(t=0),t>59?59:e.setDigit(t,2)},s:function(t){return t||(t=0),t>59?59:e.setDigit(t,2)}};return a?i[r](n):n};return g=u.replace(s,function(t,e){var r=[l(arguments[1],"Y",i)];return(arguments[2]||i)&&r.push("-"+l(arguments[2],"M",i)),(arguments[3]||i)&&r.push("-"+l(arguments[3],"D",i,arguments)),"time"==n.patternArgument&&((arguments[4]||i)&&r.push(" "+l(arguments[4],"h",i)),(arguments[5]||i)&&r.push(":"+l(arguments[5],"m",i)),(arguments[6]||i)&&r.push(":"+l(arguments[6],"s",i))),r.join("")}),"blur"!=i||o?o||(g=g.length>4?e.left(g,4):g):g=function(){var t=[l(g,"Y",i)];return t.push("-"+l(0,"M",i)),t.push("-"+l(0,"D",i,arguments)),"time"==n.patternArgument&&(t.push(" "+l(0,"h",i)),t.push(":"+l(0,"m",i)),t.push(":"+l(0,"s",i))),t.join("")}(),g},time:function(t,n,r,a,u){a=a.replace(/\D/g,"");var i=/^([0-9]{1,2})?:?([0-9]{1,2})?:?([0-9]{1,2})?.*$/,s=a.match(i),o=a.replace(i,function(t,e){var n=[arguments[1]];return arguments[2]&&n.push(":"+arguments[2]),arguments[3]&&n.push(":"+arguments[3]),n.join("")});return s||(o=o.length>2?e.left(o,2):o),o},bizno:function(t,e,n,r,a){r=r.replace(/\D/g,"");var u=/^([0-9]{3})\-?([0-9]{1,2})?\-?([0-9]{1,5})?.*$/,i=r.replace(u,function(t,e){var n=[arguments[1]];return arguments[2]&&n.push(arguments[2]),arguments[3]&&n.push(arguments[3]),n.join("-")});return i},phone:function(t,e,n,r,a){r=r.replace(/\D/g,"");var u=/^([0-9]{3})\-?([0-9]{1,4})?\-?([0-9]{1,4})?\-?([0-9]{1,4})?\-?([0-9]{1,4})?/,i=r.replace(u,function(t,e){var n=[arguments[1]];return arguments[2]&&n.push(arguments[2]),arguments[3]&&n.push(arguments[3]),arguments[4]&&n.push(arguments[4]),arguments[5]&&n.push(arguments[5]),n.join("-")});return i},custom:function(t,e,n,r,a){return t.getPatternValue?t.getPatternValue.call(t,{event:n,$input:t.$input,value:r}):void 0}},g={focus:function(t,e,n){t.$input.data("__originValue__")||t.$input.data("__originValue__",t.$input.val())},keydown:function(t,e,n){var r=!1;t.enterableKeyCodes&&(n.which&&t.enterableKeyCodes[n.which]||n.metaKey||n.ctrlKey||n.shiftKey||(r=!0)),r&&ax5.util.stopEvent(n)},keyup:function(t,e,r){var a,u,i,s,g,l=t.$input.get(0);"selectionStart"in l?a=l.selectionStart:document.selection&&(s=document.selection.createRange(),g=document.selection.createRange().text.length,s.moveStart("character",-l.value.length),a=s.text.length-g),u=l.value,i=o[t.pattern]?o[t.pattern].call(this,t,e,r,l.value):u,i!=u&&(t.$input.val(i).trigger("change"),n(l,a+i.length-u.length))},blur:function(t,e,n){var r,a,u=t.$input.get(0);t.$input.removeData("__originValue__"),r=u.value,a=o[t.pattern]?o[t.pattern].call(this,t,e,n,u.value,"blur"):r,a!=r&&t.$input.val(a).trigger("change")}},l=function(t,e){if(!t.pattern&&("INPUT"==t.$target.get(0).tagName?t.pattern=t.$target.attr("data-ax5formatter"):t.pattern=t.$target.find('input[type="text"]').attr("data-ax5formatter"),!t.pattern))return console.log(ax5.info.getError("ax5formatter","501","bind")),console.log(t.target),this;var n=/[^\(^\))]+/gi,r=t.pattern.match(n);t.pattern=r[0],t.patternArgument=r[1]||"";for(var a in s)if(t.pattern==a){s[a].call(this,t,e);break}return t.$input.unbind("focus.ax5formatter").bind("focus.ax5formatter",g.focus.bind(this,this.queue[e],e)),t.$input.unbind("keydown.ax5formatter").bind("keydown.ax5formatter",g.keydown.bind(this,this.queue[e],e)),t.$input.unbind("keyup.ax5formatter").bind("keyup.ax5formatter",g.keyup.bind(this,this.queue[e],e)),t.$input.unbind("blur.ax5formatter").bind("blur.ax5formatter",g.blur.bind(this,this.queue[e],e)),g.blur.call(this,this.queue[e],e),this};this.init=function(){},this.bind=function(t){var n,u={};if(jQuery.extend(!0,u,r),t&&jQuery.extend(!0,u,t),t=u,!t.target)return console.log(ax5.info.getError("ax5formatter","401","bind")),this;if(t.$target=jQuery(t.target),"INPUT"==t.$target.get(0).tagName)t.$input=t.$target;else if(t.$input=t.$target.find('input[type="text"]'),t.$input.length>1)return t.$input.each(function(){t.target=this,a.bind(t)}),this;return t.$input="INPUT"==t.$target.get(0).tagName?t.$target:t.$target.find('input[type="text"]'),t.id||(t.id=t.$input.data("ax5-formatter")),t.id||(t.id="ax5-formatter-"+ax5.getGuid(),t.$input.data("ax5-formatter",t.id)),n=e.search(this.queue,function(){return this.id==t.id}),-1===n?(this.queue.push(t),l.call(this,this.queue[this.queue.length-1],this.queue.length-1)):(this.queue[n]=t,l.call(this,this.queue[n],n)),this},this.main=function(){arguments&&e.isObject(arguments[0])&&this.setConfig(arguments[0])}.apply(this,arguments)};return r}())}(),ax5.ui.formatter_instance=new ax5.ui.formatter,$.fn.ax5formatter=function(){return function(t){return"undefined"==typeof t&&(t={}),$.each(this,function(){var e={target:this};t=$.extend(!0,t,e),ax5.ui.formatter_instance.bind(t)}),this}}(); |
{ | ||
"name": "ax5ui-formatter", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "A formatter plugin that works with Bootstrap & jQuery", | ||
@@ -5,0 +5,0 @@ "license": "LGPLv3", |
// ax5.ui.formatter | ||
(function () { | ||
/** | ||
* @class ax5.ui.formatter | ||
* @classdesc | ||
* @author tom@axisj.com | ||
* @example | ||
* ``` | ||
* var formatter = new ax5.ui.formatter(); | ||
* ``` | ||
*/ | ||
var ROOT = ax5.ui; | ||
var _SUPER_ = ax5.ui.root; | ||
var UI = ax5.ui; | ||
var U = ax5.util; | ||
var CLASS_NAME = "ax5formatter"; | ||
var VERSION = "0.5.1"; | ||
var TODAY = new Date(); | ||
var setSelectionRange = function (input, pos) { | ||
UI.addClass({ | ||
className: "formatter", | ||
version: "0.5.2" | ||
}, (function () { | ||
var TODAY = new Date(); | ||
var setSelectionRange = function (input, pos) { | ||
if (typeof pos == "undefined") { | ||
@@ -42,478 +33,477 @@ pos = input.value.length; | ||
//== UI Class | ||
var ax5formatter = function () { | ||
var | ||
self = this, | ||
cfg; | ||
/** | ||
* @class ax5.ui.formatter | ||
* @classdesc | ||
* @author tom@axisj.com | ||
* @example | ||
* ``` | ||
* var formatter = new ax5.ui.formatter(); | ||
* ``` | ||
*/ | ||
var ax5formatter = function () { | ||
var | ||
self = this, | ||
cfg; | ||
if (_SUPER_) _SUPER_.call(this); // 부모호출 | ||
this.config = { | ||
animateTime: 250 | ||
}; | ||
this.name = CLASS_NAME; | ||
this.version = VERSION; | ||
this.instanceId = ax5.getGuid(); | ||
this.queue = []; | ||
this.openTimer = null; | ||
this.closeTimer = null; | ||
this.config = { | ||
animateTime: 250 | ||
}; | ||
cfg = this.config; | ||
this.queue = []; | ||
this.openTimer = null; | ||
this.closeTimer = null; | ||
var | ||
ctrlKeys = { | ||
"18": "KEY_ALT", | ||
"8": "KEY_BACKSPACE", | ||
"17": "KEY_CONTROL", | ||
"46": "KEY_DELETE", | ||
"40": "KEY_DOWN", | ||
"35": "KEY_END", | ||
"187": "KEY_EQUAL", | ||
"27": "KEY_ESC", | ||
"36": "KEY_HOME", | ||
"45": "KEY_INSERT", | ||
"37": "KEY_LEFT", | ||
"189": "KEY_MINUS", | ||
"34": "KEY_PAGEDOWN", | ||
"33": "KEY_PAGEUP", | ||
// "190": "KEY_PERIOD", | ||
"13": "KEY_RETURN", | ||
"39": "KEY_RIGHT", | ||
"16": "KEY_SHIFT", | ||
// "32": "KEY_SPACE", | ||
"9": "KEY_TAB", | ||
"38": "KEY_UP", | ||
"91": "KEY_WINDOW" | ||
//"107" : "NUMPAD_ADD", | ||
//"194" : "NUMPAD_COMMA", | ||
//"110" : "NUMPAD_DECIMAL", | ||
//"111" : "NUMPAD_DIVIDE", | ||
//"12" : "NUMPAD_EQUAL", | ||
//"106" : "NUMPAD_MULTIPLY", | ||
//"109" : "NUMPAD_SUBTRACT" | ||
}, | ||
numKeys = { | ||
'48': 1, '49': 1, '50': 1, '51': 1, '52': 1, '53': 1, '54': 1, '55': 1, '56': 1, '57': 1, | ||
'96': 1, '97': 1, '98': 1, '99': 1, '100': 1, '101': 1, '102': 1, '103': 1, '104': 1, '105': 1 | ||
}, | ||
setEnterableKeyCodes = { | ||
"money": function (opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'188': ',' | ||
}; | ||
cfg = this.config; | ||
if (opts.patternArgument == "int") { | ||
// 소수점 입력 안됨 | ||
} | ||
else { | ||
enterableKeyCodes['190'] = "."; // 소수점 입력 허용 | ||
} | ||
var | ||
ctrlKeys = { | ||
"18": "KEY_ALT", | ||
"8": "KEY_BACKSPACE", | ||
"17": "KEY_CONTROL", | ||
"46": "KEY_DELETE", | ||
"40": "KEY_DOWN", | ||
"35": "KEY_END", | ||
"187": "KEY_EQUAL", | ||
"27": "KEY_ESC", | ||
"36": "KEY_HOME", | ||
"45": "KEY_INSERT", | ||
"37": "KEY_LEFT", | ||
"189": "KEY_MINUS", | ||
"34": "KEY_PAGEDOWN", | ||
"33": "KEY_PAGEUP", | ||
// "190": "KEY_PERIOD", | ||
"13": "KEY_RETURN", | ||
"39": "KEY_RIGHT", | ||
"16": "KEY_SHIFT", | ||
// "32": "KEY_SPACE", | ||
"9": "KEY_TAB", | ||
"38": "KEY_UP", | ||
"91": "KEY_WINDOW" | ||
//"107" : "NUMPAD_ADD", | ||
//"194" : "NUMPAD_COMMA", | ||
//"110" : "NUMPAD_DECIMAL", | ||
//"111" : "NUMPAD_DIVIDE", | ||
//"12" : "NUMPAD_EQUAL", | ||
//"106" : "NUMPAD_MULTIPLY", | ||
//"109" : "NUMPAD_SUBTRACT" | ||
}, | ||
numKeys = { | ||
'48': 1, '49': 1, '50': 1, '51': 1, '52': 1, '53': 1, '54': 1, '55': 1, '56': 1, '57': 1, | ||
'96': 1, '97': 1, '98': 1, '99': 1, '100': 1, '101': 1, '102': 1, '103': 1, '104': 1, '105': 1 | ||
}, | ||
setEnterableKeyCodes = { | ||
"money": function (opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'188': ',' | ||
}; | ||
if (opts.patternArgument == "int") { | ||
// 소수점 입력 안됨 | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"number": function (opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'190': '.' | ||
}; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"date": function (opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'189': '-', '191': '/' | ||
}; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"time": function (opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'186': ':' | ||
}; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"bizno": function (opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'189': '-' | ||
}; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"phone": function (opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'189': '-', '188': ',' | ||
}; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"custom": function (opts, optIdx) { | ||
if (opts.getEnterableKeyCodes) { | ||
opts.enterableKeyCodes = opts.getEnterableKeyCodes.call(opts, {$input: opts.$input}); | ||
} | ||
else { | ||
opts.enterableKeyCodes = null; | ||
} | ||
} | ||
else { | ||
enterableKeyCodes['190'] = "."; // 소수점 입력 허용 | ||
} | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"number": function (opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'190': '.' | ||
}; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"date": function (opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'189': '-', '191': '/' | ||
}; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"time": function (opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'186': ':' | ||
}; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"bizno": function (opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'189': '-' | ||
}; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"phone": function (opts, optIdx) { | ||
var enterableKeyCodes = { | ||
'189': '-', '188': ',' | ||
}; | ||
opts.enterableKeyCodes = $.extend(enterableKeyCodes, ctrlKeys, numKeys); | ||
}, | ||
"custom": function (opts, optIdx) { | ||
if (opts.getEnterableKeyCodes) { | ||
opts.enterableKeyCodes = opts.getEnterableKeyCodes.call(opts, {$input: opts.$input}); | ||
} | ||
else { | ||
opts.enterableKeyCodes = null; | ||
} | ||
} | ||
}, | ||
getPatternValue = { | ||
"money": function (opts, optIdx, e, val, eType) { | ||
var | ||
val = val.replace(/[^0-9^\.^\-]/g, ""), | ||
regExpPattern = new RegExp('([0-9])([0-9][0-9][0-9][,.])'), | ||
arrNumber = val.split('.'), | ||
returnValue | ||
; | ||
getPatternValue = { | ||
"money": function (opts, optIdx, e, val, eType) { | ||
var | ||
val = val.replace(/[^0-9^\.^\-]/g, ""), | ||
regExpPattern = new RegExp('([0-9])([0-9][0-9][0-9][,.])'), | ||
arrNumber = val.split('.'), | ||
returnValue | ||
; | ||
arrNumber[0] += '.'; | ||
arrNumber[0] += '.'; | ||
do { | ||
arrNumber[0] = arrNumber[0].replace(regExpPattern, '$1,$2'); | ||
} while (regExpPattern.test(arrNumber[0])); | ||
do { | ||
arrNumber[0] = arrNumber[0].replace(regExpPattern, '$1,$2'); | ||
} while (regExpPattern.test(arrNumber[0])); | ||
if (arrNumber.length > 1) { | ||
if (U.isNumber(opts.maxRound)) { | ||
returnValue = arrNumber[0] + U.left(arrNumber[1], opts.maxRound); | ||
if (arrNumber.length > 1) { | ||
if (U.isNumber(opts.maxRound)) { | ||
returnValue = arrNumber[0] + U.left(arrNumber[1], opts.maxRound); | ||
} | ||
else { | ||
returnValue = arrNumber.join(''); | ||
} | ||
} | ||
else { | ||
returnValue = arrNumber.join(''); | ||
returnValue = arrNumber[0].split('.')[0]; | ||
} | ||
} | ||
else { | ||
returnValue = arrNumber[0].split('.')[0]; | ||
} | ||
return returnValue; | ||
}, | ||
"number": function (opts, optIdx, e, val, eType) { | ||
val = val.replace(/[^0-9^\.^\-]/g, ""); | ||
var arrNumber = val.split('.'), | ||
returnValue | ||
; | ||
return returnValue; | ||
}, | ||
"number": function (opts, optIdx, e, val, eType) { | ||
val = val.replace(/[^0-9^\.^\-]/g, ""); | ||
var arrNumber = val.split('.'), | ||
returnValue | ||
; | ||
if (arrNumber.length > 1) { | ||
if (U.isNumber(opts.maxRound)) { | ||
returnValue = arrNumber[0] + U.left(arrNumber[1], opts.maxRound); | ||
if (arrNumber.length > 1) { | ||
if (U.isNumber(opts.maxRound)) { | ||
returnValue = arrNumber[0] + U.left(arrNumber[1], opts.maxRound); | ||
} | ||
else { | ||
returnValue = arrNumber.join(''); | ||
} | ||
} | ||
else { | ||
returnValue = arrNumber.join(''); | ||
returnValue = arrNumber[0].split('.')[0]; | ||
} | ||
} | ||
else { | ||
returnValue = arrNumber[0].split('.')[0]; | ||
} | ||
return returnValue; | ||
}, | ||
"date": function (opts, optIdx, e, val, eType) { | ||
val = val.replace(/\D/g, ""); | ||
if (val == "") return val; | ||
var regExpPattern = /^([0-9]{4})\-?([0-9]{1,2})?\-?([0-9]{1,2})?.*$/; | ||
return returnValue; | ||
}, | ||
"date": function (opts, optIdx, e, val, eType) { | ||
val = val.replace(/\D/g, ""); | ||
if (val == "") return val; | ||
var regExpPattern = /^([0-9]{4})\-?([0-9]{1,2})?\-?([0-9]{1,2})?.*$/; | ||
if (opts.patternArgument == "time") { | ||
regExpPattern = /^([0-9]{4})\-?([0-9]{1,2})?\-?([0-9]{1,2})? ?([0-9]{1,2})?:?([0-9]{1,2})?:?([0-9]{1,2})?.*$/; | ||
} | ||
if (opts.patternArgument == "time") { | ||
regExpPattern = /^([0-9]{4})\-?([0-9]{1,2})?\-?([0-9]{1,2})? ?([0-9]{1,2})?:?([0-9]{1,2})?:?([0-9]{1,2})?.*$/; | ||
} | ||
var matchedPattern = val.match(regExpPattern), | ||
returnValue = "", | ||
inspectValue = function (val, format, inspect, data) { | ||
var _val = { | ||
'Y': function (v) { | ||
if (typeof v == "undefined") v = TODAY.getFullYear(); | ||
if (v == '' || v == '0000') v = TODAY.getFullYear(); | ||
return (v.length < 4) ? U.setDigit(v, 4) : v; | ||
}, | ||
'M': function (v) { | ||
if (typeof v == "undefined") v = TODAY.getMonth() + 1; | ||
return v > 12 ? 12 : v == 0 ? '01' : U.setDigit(v, 2); | ||
}, | ||
'D': function (v) { | ||
if (typeof v == "undefined") v = TODAY.getDate() + 1; | ||
var dLen = U.daysOfMonth(data[1], data[2] - 1); | ||
return v > dLen ? dLen : v == 0 ? '01' : U.setDigit(v, 2); | ||
}, | ||
'h': function (v) { | ||
if (!v) v = 0; | ||
return v > 23 ? 23 : U.setDigit(v, 2); | ||
}, | ||
'm': function (v) { | ||
if (!v) v = 0; | ||
return v > 59 ? 59 : U.setDigit(v, 2); | ||
}, | ||
's': function (v) { | ||
if (!v) v = 0; | ||
return v > 59 ? 59 : U.setDigit(v, 2); | ||
} | ||
var matchedPattern = val.match(regExpPattern), | ||
returnValue = "", | ||
inspectValue = function (val, format, inspect, data) { | ||
var _val = { | ||
'Y': function (v) { | ||
if (typeof v == "undefined") v = TODAY.getFullYear(); | ||
if (v == '' || v == '0000') v = TODAY.getFullYear(); | ||
return (v.length < 4) ? U.setDigit(v, 4) : v; | ||
}, | ||
'M': function (v) { | ||
if (typeof v == "undefined") v = TODAY.getMonth() + 1; | ||
return v > 12 ? 12 : v == 0 ? '01' : U.setDigit(v, 2); | ||
}, | ||
'D': function (v) { | ||
if (typeof v == "undefined") v = TODAY.getDate() + 1; | ||
var dLen = U.daysOfMonth(data[1], data[2] - 1); | ||
return v > dLen ? dLen : v == 0 ? '01' : U.setDigit(v, 2); | ||
}, | ||
'h': function (v) { | ||
if (!v) v = 0; | ||
return v > 23 ? 23 : U.setDigit(v, 2); | ||
}, | ||
'm': function (v) { | ||
if (!v) v = 0; | ||
return v > 59 ? 59 : U.setDigit(v, 2); | ||
}, | ||
's': function (v) { | ||
if (!v) v = 0; | ||
return v > 59 ? 59 : U.setDigit(v, 2); | ||
} | ||
}; | ||
return (inspect) ? _val[format](val) : val; | ||
}; | ||
return (inspect) ? _val[format](val) : val; | ||
}; | ||
returnValue = val.replace(regExpPattern, function (a, b) { | ||
var nval = [inspectValue(arguments[1], "Y", eType)]; | ||
if (arguments[2] || eType) nval.push('-' + inspectValue(arguments[2], "M", eType)); | ||
if (arguments[3] || eType) nval.push('-' + inspectValue(arguments[3], "D", eType, arguments)); | ||
if (opts.patternArgument == "time") { | ||
if (arguments[4] || eType) nval.push(' ' + inspectValue(arguments[4], "h", eType)); | ||
if (arguments[5] || eType) nval.push(':' + inspectValue(arguments[5], "m", eType)); | ||
if (arguments[6] || eType) nval.push(':' + inspectValue(arguments[6], "s", eType)); | ||
} | ||
return nval.join(''); | ||
}); | ||
if (eType == 'blur' && !matchedPattern) { | ||
returnValue = (function () { | ||
var nval = [inspectValue(returnValue, "Y", eType)]; | ||
nval.push('-' + inspectValue(0, "M", eType)); | ||
nval.push('-' + inspectValue(0, "D", eType, arguments)); | ||
returnValue = val.replace(regExpPattern, function (a, b) { | ||
var nval = [inspectValue(arguments[1], "Y", eType)]; | ||
if (arguments[2] || eType) nval.push('-' + inspectValue(arguments[2], "M", eType)); | ||
if (arguments[3] || eType) nval.push('-' + inspectValue(arguments[3], "D", eType, arguments)); | ||
if (opts.patternArgument == "time") { | ||
nval.push(' ' + inspectValue(0, "h", eType)); | ||
nval.push(':' + inspectValue(0, "m", eType)); | ||
nval.push(':' + inspectValue(0, "s", eType)); | ||
if (arguments[4] || eType) nval.push(' ' + inspectValue(arguments[4], "h", eType)); | ||
if (arguments[5] || eType) nval.push(':' + inspectValue(arguments[5], "m", eType)); | ||
if (arguments[6] || eType) nval.push(':' + inspectValue(arguments[6], "s", eType)); | ||
} | ||
return nval.join(''); | ||
})(); | ||
} | ||
else if (!matchedPattern) returnValue = (returnValue.length > 4) ? U.left(returnValue, 4) : returnValue; | ||
}); | ||
return returnValue; | ||
}, | ||
"time": function (opts, optIdx, e, val, eType) { | ||
val = val.replace(/\D/g, ""); | ||
var regExpPattern = /^([0-9]{1,2})?:?([0-9]{1,2})?:?([0-9]{1,2})?.*$/; | ||
if (eType == 'blur' && !matchedPattern) { | ||
returnValue = (function () { | ||
var nval = [inspectValue(returnValue, "Y", eType)]; | ||
nval.push('-' + inspectValue(0, "M", eType)); | ||
nval.push('-' + inspectValue(0, "D", eType, arguments)); | ||
if (opts.patternArgument == "time") { | ||
nval.push(' ' + inspectValue(0, "h", eType)); | ||
nval.push(':' + inspectValue(0, "m", eType)); | ||
nval.push(':' + inspectValue(0, "s", eType)); | ||
} | ||
return nval.join(''); | ||
})(); | ||
} | ||
else if (!matchedPattern) returnValue = (returnValue.length > 4) ? U.left(returnValue, 4) : returnValue; | ||
var matchedPattern = val.match(regExpPattern), | ||
returnValue = val.replace(regExpPattern, function (a, b) { | ||
var nval = [arguments[1]]; | ||
if (arguments[2]) nval.push(':' + arguments[2]); | ||
if (arguments[3]) nval.push(':' + arguments[3]); | ||
return nval.join(''); | ||
}); | ||
return returnValue; | ||
}, | ||
"time": function (opts, optIdx, e, val, eType) { | ||
val = val.replace(/\D/g, ""); | ||
var regExpPattern = /^([0-9]{1,2})?:?([0-9]{1,2})?:?([0-9]{1,2})?.*$/; | ||
if (!matchedPattern) returnValue = (returnValue.length > 2) ? U.left(returnValue, 2) : returnValue; | ||
var matchedPattern = val.match(regExpPattern), | ||
returnValue = val.replace(regExpPattern, function (a, b) { | ||
var nval = [arguments[1]]; | ||
if (arguments[2]) nval.push(':' + arguments[2]); | ||
if (arguments[3]) nval.push(':' + arguments[3]); | ||
return nval.join(''); | ||
}); | ||
return returnValue; | ||
}, | ||
"bizno": function (opts, optIdx, e, val, eType) { | ||
val = val.replace(/\D/g, ""); | ||
var regExpPattern = /^([0-9]{3})\-?([0-9]{1,2})?\-?([0-9]{1,5})?.*$/, | ||
returnValue = val.replace(regExpPattern, function (a, b) { | ||
var nval = [arguments[1]]; | ||
if (arguments[2]) nval.push(arguments[2]); | ||
if (arguments[3]) nval.push(arguments[3]); | ||
return nval.join("-"); | ||
}); | ||
if (!matchedPattern) returnValue = (returnValue.length > 2) ? U.left(returnValue, 2) : returnValue; | ||
return returnValue; | ||
}, | ||
"phone": function (opts, optIdx, e, val, eType) { | ||
val = val.replace(/\D/g, ""); | ||
var regExpPattern3 = /^([0-9]{3})\-?([0-9]{1,4})?\-?([0-9]{1,4})?\-?([0-9]{1,4})?\-?([0-9]{1,4})?/, | ||
returnValue = val.replace(regExpPattern3, function (a, b) { | ||
var nval = [arguments[1]]; | ||
if (arguments[2]) nval.push(arguments[2]); | ||
if (arguments[3]) nval.push(arguments[3]); | ||
if (arguments[4]) nval.push(arguments[4]); | ||
if (arguments[5]) nval.push(arguments[5]); | ||
return nval.join("-"); | ||
}); | ||
return returnValue; | ||
}, | ||
"custom": function (opts, optIdx, e, val, eType) { | ||
if (opts.getPatternValue) { | ||
return opts.getPatternValue.call(opts, {event: e, $input: opts.$input, value: val}); | ||
return returnValue; | ||
}, | ||
"bizno": function (opts, optIdx, e, val, eType) { | ||
val = val.replace(/\D/g, ""); | ||
var regExpPattern = /^([0-9]{3})\-?([0-9]{1,2})?\-?([0-9]{1,5})?.*$/, | ||
returnValue = val.replace(regExpPattern, function (a, b) { | ||
var nval = [arguments[1]]; | ||
if (arguments[2]) nval.push(arguments[2]); | ||
if (arguments[3]) nval.push(arguments[3]); | ||
return nval.join("-"); | ||
}); | ||
return returnValue; | ||
}, | ||
"phone": function (opts, optIdx, e, val, eType) { | ||
val = val.replace(/\D/g, ""); | ||
var regExpPattern3 = /^([0-9]{3})\-?([0-9]{1,4})?\-?([0-9]{1,4})?\-?([0-9]{1,4})?\-?([0-9]{1,4})?/, | ||
returnValue = val.replace(regExpPattern3, function (a, b) { | ||
var nval = [arguments[1]]; | ||
if (arguments[2]) nval.push(arguments[2]); | ||
if (arguments[3]) nval.push(arguments[3]); | ||
if (arguments[4]) nval.push(arguments[4]); | ||
if (arguments[5]) nval.push(arguments[5]); | ||
return nval.join("-"); | ||
}); | ||
return returnValue; | ||
}, | ||
"custom": function (opts, optIdx, e, val, eType) { | ||
if (opts.getPatternValue) { | ||
return opts.getPatternValue.call(opts, {event: e, $input: opts.$input, value: val}); | ||
} | ||
} | ||
} | ||
}, | ||
formatterEvent = { | ||
'focus': function (opts, optIdx, e) { | ||
if (!opts.$input.data("__originValue__")) opts.$input.data("__originValue__", opts.$input.val()); | ||
}, | ||
/* 키 다운 이벤트에서 입력할 수 없는 키 입력을 방어 */ | ||
'keydown': function (opts, optIdx, e) { | ||
var isStop = false; | ||
if (!opts.enterableKeyCodes) { | ||
formatterEvent = { | ||
'focus': function (opts, optIdx, e) { | ||
if (!opts.$input.data("__originValue__")) opts.$input.data("__originValue__", opts.$input.val()); | ||
}, | ||
/* 키 다운 이벤트에서 입력할 수 없는 키 입력을 방어 */ | ||
'keydown': function (opts, optIdx, e) { | ||
var isStop = false; | ||
if (!opts.enterableKeyCodes) { | ||
} | ||
else if (e.which && opts.enterableKeyCodes[e.which]) { | ||
} | ||
else if (e.which && opts.enterableKeyCodes[e.which]) { | ||
} | ||
else if (!e.metaKey && !e.ctrlKey && !e.shiftKey) { | ||
//console.log(e.which, opts.enterableKeyCodes); | ||
isStop = true; | ||
} | ||
if (isStop) ax5.util.stopEvent(e); | ||
}, | ||
/* 키 업 이벤트에서 패턴을 적용 */ | ||
'keyup': function (opts, optIdx, e) { | ||
var elem = opts.$input.get(0), | ||
elemFocusPosition, | ||
beforeValue, | ||
newValue, | ||
selection, selectionLength | ||
; | ||
} | ||
else if (!e.metaKey && !e.ctrlKey && !e.shiftKey) { | ||
//console.log(e.which, opts.enterableKeyCodes); | ||
isStop = true; | ||
} | ||
if (isStop) ax5.util.stopEvent(e); | ||
}, | ||
/* 키 업 이벤트에서 패턴을 적용 */ | ||
'keyup': function (opts, optIdx, e) { | ||
var elem = opts.$input.get(0), | ||
elemFocusPosition, | ||
beforeValue, | ||
newValue, | ||
selection, selectionLength | ||
; | ||
if ('selectionStart' in elem) { | ||
// Standard-compliant browsers | ||
elemFocusPosition = elem.selectionStart; | ||
} | ||
else if (document.selection) { | ||
// IE | ||
//elem.focus(); | ||
selection = document.selection.createRange(); | ||
selectionLength = document.selection.createRange().text.length; | ||
selection.moveStart('character', -elem.value.length); | ||
elemFocusPosition = selection.text.length - selectionLength; | ||
} | ||
if ('selectionStart' in elem) { | ||
// Standard-compliant browsers | ||
elemFocusPosition = elem.selectionStart; | ||
} | ||
else if (document.selection) { | ||
// IE | ||
//elem.focus(); | ||
selection = document.selection.createRange(); | ||
selectionLength = document.selection.createRange().text.length; | ||
selection.moveStart('character', -elem.value.length); | ||
elemFocusPosition = selection.text.length - selectionLength; | ||
} | ||
beforeValue = elem.value; | ||
newValue = (getPatternValue[opts.pattern]) ? getPatternValue[opts.pattern].call(this, opts, optIdx, e, elem.value) : beforeValue; | ||
beforeValue = elem.value; | ||
newValue = (getPatternValue[opts.pattern]) ? getPatternValue[opts.pattern].call(this, opts, optIdx, e, elem.value) : beforeValue; | ||
if (newValue != beforeValue) { | ||
opts.$input.val(newValue).trigger("change"); | ||
setSelectionRange(elem, elemFocusPosition + newValue.length - beforeValue.length); | ||
} | ||
}, | ||
'blur': function (opts, optIdx, e) { | ||
var elem = opts.$input.get(0), | ||
beforeValue, | ||
newValue | ||
; | ||
if (newValue != beforeValue) { | ||
opts.$input.val(newValue).trigger("change"); | ||
setSelectionRange(elem, elemFocusPosition + newValue.length - beforeValue.length); | ||
} | ||
}, | ||
'blur': function (opts, optIdx, e) { | ||
var elem = opts.$input.get(0), | ||
beforeValue, | ||
newValue | ||
; | ||
opts.$input.removeData("__originValue__"); | ||
opts.$input.removeData("__originValue__"); | ||
beforeValue = elem.value; | ||
newValue = (getPatternValue[opts.pattern]) ? getPatternValue[opts.pattern].call(this, opts, optIdx, e, elem.value, 'blur') : beforeValue; | ||
if (newValue != beforeValue) { | ||
opts.$input.val(newValue).trigger("change"); | ||
beforeValue = elem.value; | ||
newValue = (getPatternValue[opts.pattern]) ? getPatternValue[opts.pattern].call(this, opts, optIdx, e, elem.value, 'blur') : beforeValue; | ||
if (newValue != beforeValue) { | ||
opts.$input.val(newValue).trigger("change"); | ||
} | ||
} | ||
} | ||
}, | ||
bindFormatterTarget = function (opts, optIdx) { | ||
}, | ||
bindFormatterTarget = function (opts, optIdx) { | ||
if (!opts.pattern) { | ||
if (opts.$target.get(0).tagName == "INPUT") { | ||
opts.pattern = opts.$target | ||
.attr('data-ax5formatter'); | ||
} | ||
else { | ||
opts.pattern = opts.$target | ||
.find('input[type="text"]') | ||
.attr('data-ax5formatter'); | ||
} | ||
if (!opts.pattern) { | ||
console.log(ax5.info.getError("ax5formatter", "501", "bind")); | ||
console.log(opts.target); | ||
return this; | ||
if (opts.$target.get(0).tagName == "INPUT") { | ||
opts.pattern = opts.$target | ||
.attr('data-ax5formatter'); | ||
} | ||
else { | ||
opts.pattern = opts.$target | ||
.find('input[type="text"]') | ||
.attr('data-ax5formatter'); | ||
} | ||
if (!opts.pattern) { | ||
console.log(ax5.info.getError("ax5formatter", "501", "bind")); | ||
console.log(opts.target); | ||
return this; | ||
} | ||
} | ||
} | ||
var re = /[^\(^\))]+/gi, | ||
matched = opts.pattern.match(re); | ||
var re = /[^\(^\))]+/gi, | ||
matched = opts.pattern.match(re); | ||
opts.pattern = matched[0]; | ||
opts.patternArgument = matched[1] || ""; | ||
opts.pattern = matched[0]; | ||
opts.patternArgument = matched[1] || ""; | ||
// 함수타입 | ||
for (var key in setEnterableKeyCodes) { | ||
if (opts.pattern == key) { | ||
setEnterableKeyCodes[key].call(this, opts, optIdx); | ||
break; | ||
// 함수타입 | ||
for (var key in setEnterableKeyCodes) { | ||
if (opts.pattern == key) { | ||
setEnterableKeyCodes[key].call(this, opts, optIdx); | ||
break; | ||
} | ||
} | ||
} | ||
opts.$input | ||
.unbind('focus.ax5formatter') | ||
.bind('focus.ax5formatter', formatterEvent.focus.bind(this, this.queue[optIdx], optIdx)); | ||
opts.$input | ||
.unbind('focus.ax5formatter') | ||
.bind('focus.ax5formatter', formatterEvent.focus.bind(this, this.queue[optIdx], optIdx)); | ||
opts.$input | ||
.unbind('keydown.ax5formatter') | ||
.bind('keydown.ax5formatter', formatterEvent.keydown.bind(this, this.queue[optIdx], optIdx)); | ||
opts.$input | ||
.unbind('keydown.ax5formatter') | ||
.bind('keydown.ax5formatter', formatterEvent.keydown.bind(this, this.queue[optIdx], optIdx)); | ||
opts.$input | ||
.unbind('keyup.ax5formatter') | ||
.bind('keyup.ax5formatter', formatterEvent.keyup.bind(this, this.queue[optIdx], optIdx)); | ||
opts.$input | ||
.unbind('keyup.ax5formatter') | ||
.bind('keyup.ax5formatter', formatterEvent.keyup.bind(this, this.queue[optIdx], optIdx)); | ||
opts.$input | ||
.unbind('blur.ax5formatter') | ||
.bind('blur.ax5formatter', formatterEvent.blur.bind(this, this.queue[optIdx], optIdx)); | ||
opts.$input | ||
.unbind('blur.ax5formatter') | ||
.bind('blur.ax5formatter', formatterEvent.blur.bind(this, this.queue[optIdx], optIdx)); | ||
formatterEvent.blur.call(this, this.queue[optIdx], optIdx); | ||
formatterEvent.blur.call(this, this.queue[optIdx], optIdx); | ||
return this; | ||
return this; | ||
}; | ||
}; | ||
/** | ||
* Preferences of formatter UI | ||
* @method ax5.ui.formatter.setConfig | ||
* @param {Object} config - 클래스 속성값 | ||
* @returns {ax5.ui.formatter} | ||
* @example | ||
* ``` | ||
* ``` | ||
*/ | ||
this.init = function () { | ||
/** | ||
* Preferences of formatter UI | ||
* @method ax5.ui.formatter.setConfig | ||
* @param {Object} config - 클래스 속성값 | ||
* @returns {ax5.ui.formatter} | ||
* @example | ||
* ``` | ||
* ``` | ||
*/ | ||
this.init = function () { | ||
}; | ||
}; | ||
this.bind = function (opts) { | ||
var | ||
formatterConfig = {}, | ||
optIdx; | ||
this.bind = function (opts) { | ||
var | ||
formatterConfig = {}, | ||
optIdx; | ||
jQuery.extend(true, formatterConfig, cfg); | ||
if (opts) jQuery.extend(true, formatterConfig, opts); | ||
opts = formatterConfig; | ||
jQuery.extend(true, formatterConfig, cfg); | ||
if (opts) jQuery.extend(true, formatterConfig, opts); | ||
opts = formatterConfig; | ||
if (!opts.target) { | ||
console.log(ax5.info.getError("ax5formatter", "401", "bind")); | ||
return this; | ||
} | ||
opts.$target = jQuery(opts.target); | ||
if (opts.$target.get(0).tagName == "INPUT") { | ||
opts.$input = opts.$target; | ||
} | ||
else { | ||
opts.$input = opts.$target.find('input[type="text"]'); | ||
if (opts.$input.length > 1) { | ||
opts.$input.each(function () { | ||
opts.target = this; | ||
self.bind(opts); | ||
}); | ||
if (!opts.target) { | ||
console.log(ax5.info.getError("ax5formatter", "401", "bind")); | ||
return this; | ||
} | ||
} | ||
opts.$target = jQuery(opts.target); | ||
opts.$input = (opts.$target.get(0).tagName == "INPUT") ? opts.$target : opts.$target.find('input[type="text"]'); | ||
if (!opts.id) opts.id = opts.$input.data("ax5-formatter"); | ||
if (opts.$target.get(0).tagName == "INPUT") { | ||
opts.$input = opts.$target; | ||
} | ||
else { | ||
opts.$input = opts.$target.find('input[type="text"]'); | ||
if (opts.$input.length > 1) { | ||
opts.$input.each(function () { | ||
opts.target = this; | ||
self.bind(opts); | ||
}); | ||
return this; | ||
} | ||
} | ||
if (!opts.id) { | ||
opts.id = 'ax5-formatter-' + ax5.getGuid(); | ||
opts.$input.data("ax5-formatter", opts.id); | ||
} | ||
optIdx = U.search(this.queue, function () { | ||
return this.id == opts.id; | ||
}); | ||
opts.$input = (opts.$target.get(0).tagName == "INPUT") ? opts.$target : opts.$target.find('input[type="text"]'); | ||
if (!opts.id) opts.id = opts.$input.data("ax5-formatter"); | ||
if (optIdx === -1) { | ||
this.queue.push(opts); | ||
bindFormatterTarget.call(this, this.queue[this.queue.length - 1], this.queue.length - 1); | ||
} | ||
else { | ||
this.queue[optIdx] = opts; | ||
bindFormatterTarget.call(this, this.queue[optIdx], optIdx); | ||
} | ||
if (!opts.id) { | ||
opts.id = 'ax5-formatter-' + ax5.getGuid(); | ||
opts.$input.data("ax5-formatter", opts.id); | ||
} | ||
optIdx = U.search(this.queue, function () { | ||
return this.id == opts.id; | ||
}); | ||
return this; | ||
}; | ||
if (optIdx === -1) { | ||
this.queue.push(opts); | ||
bindFormatterTarget.call(this, this.queue[this.queue.length - 1], this.queue.length - 1); | ||
} | ||
else { | ||
this.queue[optIdx] = opts; | ||
bindFormatterTarget.call(this, this.queue[optIdx], optIdx); | ||
} | ||
// 클래스 생성자 | ||
this.main = (function () { | ||
if (arguments && U.isObject(arguments[0])) { | ||
this.setConfig(arguments[0]); | ||
} | ||
}).apply(this, arguments); | ||
}; | ||
return this; | ||
}; | ||
ROOT.formatter = (function () { | ||
if (U.isFunction(_SUPER_)) ax5formatter.prototype = new _SUPER_(); // 상속 | ||
// 클래스 생성자 | ||
this.main = (function () { | ||
if (arguments && U.isObject(arguments[0])) { | ||
this.setConfig(arguments[0]); | ||
} | ||
}).apply(this, arguments); | ||
}; | ||
return ax5formatter; | ||
})(); // ax5.ui에 연결 | ||
})()); | ||
@@ -520,0 +510,0 @@ })(); |
@@ -5,3 +5,3 @@ { | ||
"jquery": "^1.11.0", | ||
"ax5core": "", | ||
"ax5core": ">=1.0.9", | ||
"bootstrap": "^3.3.6", | ||
@@ -8,0 +8,0 @@ "font-awesome": "" |
62472
938