|
[유용한 xxjavascript] input text에서 format 값 입력 받기 3 (연재)
html input tag에서 다음과 같은 형식의 값을 입력 받는 sample code를 소개하겠습니다.
123-45-67
그리고 아무것도 입력되지 않은 상태에서는
...-..-...
이렇게 표시되고, 3456 입력하면
345-6.-..
이렇게 자동 format이 됩니다.
이러한 기능을 html input tag만으로 구현하려면 3개의 input tag를 사용해야 합니다.
또한 하나의 input tag에서 지정된 수의 문자 입력이 되면 자동으로
다음 input tag로 넘어가야 합니다.
그리고 다음 input tag에서도 backspace를 치면 이전 input tag로 넘어가야 합니다.
아래에 제공하는 source code는 하나의 input tag를 사용하는 방식입니다.
아래의 source code를 이해하기 위해서는
이전에 올린 글중에서 아래의 2가지 글을 읽으시는 것을 권합니다.
[유용한 xxjavascript] input text format edit 기능 연재(1/2) cursor position을 설정하고 얻어오는 방법
[유용한 xxjavascript] input text에서 특정 format(money,날짜) 형식으로 입력 받기(연재)
아래의 글에서 editctrl.js xxjavascript를 포함하고 있습니다.(첨부파일 참조)
아래의 xxjavascript에서 format_init()이 처음 호출됩니다.
그리고 format_init_call ++을 하여 호출된 count를 증가합니다.
이렇게 하는 이유가 있습니다.
일반적으로 하나의 JSP page 혹은 page에서 HTML, xxjavascript 이 있을때
순차적으로 loading이 된다는 가정을 합니다. 하지만 Internet Explorer에서 실행을 하다 보면
HTML이 완전히 loading이 안된 상태에서 xxjavascript가 실행하거나
혹은 xxjavascript가 완전히 loading이 않된 상태에서 xxjavascript를 호출하는 경우
이러한 경우 오류가 잘 발생합니다.
즉 아래의 format_init_call 을 사용하여 현재 call count를 increase하면서 중간에 exception이 나면
다시 호출하게 하는 것은 xxjavascript가 만약 loading이 마무리 되지 않았을 경우 다시 format_init()을
호출하기 위해서 이렇게 합니다. 이와 같은 기법은 xxjavascript의 실행의 안정성을 보장합니다.
WCEditCtrl_setEdit(window,oCtrl,elEdit);
input text tag를 xxjavascript object에 설정합니다. oCtrl.elEdit 가 input text tag가 됩니다.
WCEditCtrl_setUnit(window,oCtrl,"");
money type이 아니기 때문에 unit은 없습니다.
WCEditCtrl_setImeMode(window,oCtrl,"disabled");
한글을 입력받지 않기 위해서 ImeMode를 disabled 했습니다.
WCEditCtrl_setFilter(window,oCtrl,"1");
숫자만 입력받기 위해서 filter를 1로 설정하였습니다.
WCEditCtrl_setAny(window,oCtrl,".");
format에서 "."에 char가 위치할 수 있다는 것을 지정합니다.
WCEditCtrl_setFormat(window,oCtrl,"...-..-..");
format을 지정합니다.
WCEditCtrl_setTextAlign(window,oCtrl,"left");
text align을 left로 지정하였습니다.
WCEditCtrl_formatText(window,oCtrl);
input text tag의 value인 (<INPUT type=text id="elEditCtrl_format" name="format" value="1234567" )
1234567을 123-45-67로 format을 변경합니다.
설명을 효과적으로 하기 위해서
WCEditCtrl_formatText(window,oCtrl)
을 먼저 설명하겠습니다.
oCtrl은 input text tag와 기타 input text의 설정 정보를 저장하고 있는 xxjavascript object입니다.
WCEditCtrl_formatText 이 함수는 1234567을 123-45-67 이와 같은 형식으로 변환하는 기능을 합니다.
WCEditCtrl_formatText
-> WCEditCtrl_formatValue
-> WCEditCtrl_extractChar를 호출하여 123-..-.. 이와 같이 입력된 input text의 값에서 123만을 추출합니다.
-> extract된 123을 ...-..-.. 여기서 any에 해당하는 "."에 위치시킵니다. 즉 123-..-.. 이렇게 format을 맞춥니다.
(any: "." 라고 설정한 것은 아래의 코드에서 WCEditCtrl_setAny(window,oCtrl,"."); 이렇게 호출했습니다.
any는 format에서 valid한 char가 온다는 뜻입니다. 또한 WCEditCtrl_setFilter(window,oCtrl,"1"); 에서
"1" 이라고 호출하여 숫자만 입력 받겠다는 것을 뜻합니다.)
function WCEditCtrl_formatText(wSrcWnd,oCtrl)
{
try
{
var sValue = oCtrl.elEdit.value; // html input text element
var sDest = WCEditCtrl_formatValue(wSrcWnd,oCtrl,sValue);
oCtrl.elEdit.value = sDest; // html input text element에 값을 설정
}
catch (ex)
{
}
}
function WCEditCtrl_formatValue(wSrcWnd,oCtrl,sValue)
{
try
{
...
var cDelimiter = WCEditCtrl_getDelimiter(wSrcWnd,oCtrl); // cDelimiter
var cAny = WCEditCtrl_getAny(wSrcWnd,oCtrl);
var str = WCEditCtrl_extractChar(wSrcWnd,oCtrl,sValue,-1);
var sSrc = new String(str);
var nSrcLen = sSrc.length;
var sDest = "";
var nFormatIdx = 0;
var nSrcIdx = 0;
if (WCEditCtrl_getFormat(wSrcWnd,oCtrl) == null)
return sSrc;
var nFormatLen = WCString_getLength(WCEditCtrl_getFormat(wSrcWnd,oCtrl));
while (nFormatIdx < nFormatLen && nSrcIdx < nSrcLen)
{
var cSrc = sSrc.charAt(nSrcIdx);
if (cSrc == cDelimiter || cSrc == cAny)
{
nSrcIdx ++;
continue;
}
var cFormat = WCEditCtrl_getFormat(wSrcWnd,oCtrl).charAt(nFormatIdx);
if (cFormat == cAny)
{
sDest += cSrc;
nSrcIdx ++;
nFormatIdx ++;
}
else
{
sDest += cFormat;
nFormatIdx ++;
}
}
if (nFormatIdx < nFormatLen)
{
while (nFormatIdx < nFormatLen)
{
var cFormat = WCEditCtrl_getFormat(wSrcWnd,oCtrl).charAt(nFormatIdx);
sDest += cFormat;
nFormatIdx ++;
}
}
if (nFormatLen <= 0)
{
sDest = sSrc;
}
return sDest;
}
catch (ex)
{
}
}
이제는 key board down/up에 대해서 어떻게 처리하는지 설명하겠습니다.
아래의 소스에서
WCEditCtrl_setEdit(window,oCtrl)
이를 호출하여 html input text tag element의 event handler를 설정하였습니다.
oCtrl.elEdit.[안내]태그제한으로등록되지않습니다-xxonkeydown = new Function("eval(\"WCEditCtrl_keyDown(this.document.frames.window,'"+oCtrl.name+"',this);\")");
oCtrl.elEdit.[안내]태그제한으로등록되지않습니다-xxonkeyup = new Function("eval(\"WCEditCtrl_keyUp(this.document.frames.window,'"+oCtrl.name+"',this);\")");
oCtrl.elEdit.[안내]태그제한으로등록되지않습니다-xxonkeypress = new Function("eval(\"WCEditCtrl_keyPress(this.document.frames.window,'"+oCtrl.name+"',this);\")");
oCtrl.elEdit.[안내]태그제한으로등록되지않습니다-xxonfocus = new Function("eval(\"WCEditCtrl_doFocus(this.document.frames.window,'"+oCtrl.name+"',this);\")");
oCtrl.elEdit.[안내]태그제한으로등록되지않습니다-xxonblur = new Function("eval(\"WCEditCtrl_doBlur(this.document.frames.window,'"+oCtrl.name+"',this);\")");
이제 input text tag에서 key down을 하면 WCEditCtrl_keyDown이 호출됩니다.
WCEditCtrl_keyDown에서는 delete,backspace와 같은 특수키와 key 입력에 대한 input 값의 변화를 처리합니다.
(모든 소스에 대해서 일일이 설명하고 싶지만 너무 설명할 것이 많은 관계로 간단히 설명하겠습니다.)
WCEditCtrl_keyUp에서는 지정한 format에 따라 입력된 값을 format 처리하고 cursor의 position을 설정합니다.
format 처리하는 함수는
WCEditCtrl_keyUp event handler
-> WCEditCtrl_formatEdit(wSrcWnd,oCtrl);
-> WCEditCtrl_formatValue(wSrcWnd,oCtrl,sValue); // 123-4.-.. 이와 같이 format으로 text를 변환합니다.
-> WCEditCtrl_setCursorPos(wSrcWnd,oCtrl,textbox,nPos); // cursor position을 설정
function WCEditCtrl_formatEdit(wSrcWnd,oCtrl)
{
try
{
...
else
{
var sDest = WCEditCtrl_formatValue(wSrcWnd,oCtrl,sValue);
var nAfterCursorPos = WCEditCtrl_getFirstAnyPos(wSrcWnd,oCtrl,sDest);
var sSrc = textbox.value;
var sBefore = WCEditCtrl_extractCharToPosition(wSrcWnd,oCtrl,sSrc,nPos);
var sInvalidBefore = WCEditCtrl_extractInvalidCharToPosition(wSrcWnd,oCtrl,sSrc,nPos);
var sInvalidAfter = WCEditCtrl_extractInvalidCharToPosition(wSrcWnd,oCtrl,sDest,nPos);
if (sBefore.length > 0 && sBefore.length < nPos)
nPos = sBefore.length + sInvalidBefore.length;
if (sInvalidAfter.length - sInvalidBefore.length > 0)
nPos += sInvalidAfter.length - sInvalidBefore.length;
if (nPos > nAfterCursorPos)
nPos = nAfterCursorPos;
textbox.value = sDest;
WCEditCtrl_setCursorPos(wSrcWnd,oCtrl,textbox,nPos);
}
}
...
}
아래의 프로그램과 xxjavascript는 www.webdevlib.net(web development library)에 있는 WCEditCtrl의 기능중에서 일부를 발췌하여
새롭게 구성한 sample입니다. 따라서 www.webdevlib.net에서 java source를 다운로드 받지 않아도
실제 사용할 수 있는 샘플 소스입니다.
보다 더 복잡한 기능의 application을 개발하고자 하는 경우는 www.webdevlib.net에서 소스코드를 다운로드
받아 사용하세요.
간단한 application 혹은 일반적인 web application 개발에서 아래의 sample code는 많은 도움을 드릴 것입니다.
-- 소스 시작
<%@ page language="java" import="java.util.*,java.sql.*,java.lang.*,java.io.*,java.io.File " contentType="text/html; charset=EUC-KR"%>
<style>
td { line-height: 13px; font-size: 11px; font-family: tahoma, Arial, Helvetica, sans-serif, 굴림; }
input { line-height: 13px; font-size: 11px; font-family: tahoma, Arial, Helvetica, sans-serif, 굴림; }
</style>
<table border="0" cellspacing="0" cellpadding="0" >
<tr>
<td valign=top>
format :
<INPUT type=text id="elEditCtrl_format" name="format" value="1234567"
style="background-color:#ffffff; border: 1 solid #000000;color:#000000;
font-size: 11px; font-family: tahoma, Arial, Helvetica, sans-serif, 굴림; height:17px;
text-align:left;
" class="inputstyle01" type="text" style="width:200px;" />
</td>
</tr>
</table>
<script>
var format_init_call = 0;
function format_init()
{
try
{
format_init_call ++;
if (format_init_call > 10)
return;
var sElmtid = "elEditCtrl_format";
var oCtrl = WCEditCtrl_new(window,null,"format");
oCtrl.idx = 3;
var elEdit = window.document.getElementById(sElmtid);
WCEditCtrl_setEdit(window,oCtrl,elEdit);
WCEditCtrl_setUnit(window,oCtrl,"");
WCEditCtrl_setImeMode(window,oCtrl,"disabled");
WCEditCtrl_setFilter(window,oCtrl,"1");
WCEditCtrl_setAny(window,oCtrl,".");
WCEditCtrl_setFormat(window,oCtrl,"...-..-..");
WCEditCtrl_setTextAlign(window,oCtrl,"left");
WCEditCtrl_formatText(window,oCtrl);
}
catch (ex)
{
setTimeout("format_init()",50);
}
}
format_init();
</script>
<script src="editctrl.js"></script>
-- 소스 끝
-- editctrl.js 시작
function WCEditCtrl_setUnit(wSrcWnd,oCtrl,sUnit)
{
oCtrl.unit = sUnit;
}
function WCEditCtrl_new(wSrcWnd,oParentCtrl,sName)
{
try
{
var oCtrl = null;
if (wSrcWnd != null)
oCtrl = WCCtrl_new(wSrcWnd);
else
oCtrl = new Object();
if (sName == null && oParentCtrl != null)
sName = oParentCtrl.name+"_edit";
if (sName != null)
oCtrl.name = sName;
if (oParentCtrl != null)
oCtrl.parent = oParentCtrl;
return oCtrl;
}
catch (ex)
{
}
}
function WCEditCtrl_resetCtrl(wSrcWnd,oCtrl)
{
var oNew = new Object();
oNew.name = oCtrl.name;
oNew.pageObj = oCtrl.pageObj;
oNew.objIndex = oCtrl.objIndex;
oNew.parentName = oCtrl.parentName;
oNew.idx = oCtrl.idx;
oNew.pageObj.aCtrl[oNew.objIndex] = oNew;
WCEditCtrl_setEdit(wSrcWnd,oNew,oCtrl.elEdit);
oNew.elEdit.style.textAlign = "left";
oCtrl = oNew;
return oNew;
}
function WCEditCtrl_setMaxLength(wSrcWnd,oCtrl,nMaxLen)
{
oCtrl.maxLength = nMaxLen;
}
function WCEditCtrl_getMaxLength(wSrcWnd,oCtrl)
{
var nVal = WCString_parseInt(oCtrl.maxLength);
return nVal;
}
function WCEditCtrl_setTextAlign(wSrcWnd,oCtrl,sAlign)
{
try
{
oCtrl.textAlign = sAlign;
if (oCtrl.elEdit != null)
{
oCtrl.elEdit.style.textAlign = sAlign;
}
}
catch (ex)
{
}
}
function WCEditCtrl_setDecimalPoint(wSrcWnd,oCtrl,nPoint)
{
oCtrl.decimalPoint = nPoint;
}
function WCEditCtrl_setImeMode(wSrcWnd,oCtrl,sMode)
{
try
{
oCtrl.imeMode = sMode;
if (oCtrl.elEdit != null)
{
oCtrl.elEdit.style.imeMode = sMode;
}
}
catch (ex)
{
}
}
function WCEditCtrl_setFormatType(wSrcWnd,oCtrl,sFormatType)
{
try
{
oCtrl.formatType = sFormatType;
if (oCtrl.formatType == "integer"
|| oCtrl.formatType == "number"
|| oCtrl.formatType == "float")
{
WCEditCtrl_setFilter(wSrcWnd,oCtrl,"1");
var cDlm = '.';
WCEditCtrl_setDelimiter(wSrcWnd,oCtrl,cDlm);
WCEditCtrl_setImeMode("disabled");
}
else if (oCtrl.formatType == "money")
{
WCEditCtrl_setFilter(wSrcWnd,oCtrl,"1");
var cDlm = ',';
WCEditCtrl_setDelimiter(wSrcWnd,oCtrl,cDlm);
WCEditCtrl_setImeMode("disabled");
}
}
catch (ex)
{
}
}
function WCEditCtrl_getFormatType(wSrcWnd,oCtrl)
{
return oCtrl.formatType;
}
function WCEditCtrl_setFormatUnit(wSrcWnd,oCtrl,sUnit)
{
oCtrl.sUnit = sUnit;
}
function WCEditCtrl_setFormatUnitAlign(wSrcWnd,oCtrl,sAlign)
{
oCtrl.unitAlign = sAlign;
}
function WCEditCtrl_setFormatPrecision(wSrcWnd,oCtrl,nPrecision)
{
oCtrl.nPrecision = nPrecision;
}
function WCEditCtrl_setFormat(wSrcWnd,oCtrl,sFormat)
{
oCtrl.format = sFormat;
}
function WCEditCtrl_getFormat(wSrcWnd,oCtrl)
{
var sRet = oCtrl.format;
return sRet;
}
function WCEditCtrl_setFilter(wSrcWnd,oCtrl,sFilter)
{
oCtrl.filter = sFilter;
}
function WCEditCtrl_getFilter(wSrcWnd,oCtrl)
{
var sRet = oCtrl.filter;
return sRet;
}
function WCEditCtrl_setAny(wSrcWnd,oCtrl,cAny)
{
oCtrl.any = cAny;
}
function WCEditCtrl_getAny(wSrcWnd,oCtrl)
{
return oCtrl.any;
}
function WCEditCtrl_setDelimiter(wSrcWnd,oCtrl,cDlm)
{
oCtrl.delimiter = cDlm;
}
function WCEditCtrl_getDelimiter(wSrcWnd,oCtrl)
{
return oCtrl.delimiter;
}
function WCEditCtrl_isValidCharCode(wSrcWnd,oCtrl,evEvent)
{
var nKeyCode = evEvent.keyCode;
if (nKeyCode == 9)
return true;
if (evEvent.keyCode >= 96 && evEvent.keyCode <= 105)
{
nKeyCode -= 48;
}
var cChar = String.fromCharCode(nKeyCode);
return WCEditCtrl_isValidChar(wSrcWnd,oCtrl,cChar);
}
function WCEditCtrl_keyPress(wSrcWnd,sName,elEdit)
{
if (wSrcWnd.event.keyCode == 13)
return false;
}
function WCEditCtrl_doFocus(wSrcWnd,sName)
{
try
{
var oCtrl = WCObj_getObj(wSrcWnd,sName);
var sVal = oCtrl.elEdit.value;
var nPos = sVal.length;
if (!WCString_isEmpty(WCEditCtrl_getFormat(wSrcWnd,oCtrl)))
{
var nFirstPos = WCEditCtrl_getFirstAnyPos(wSrcWnd,oCtrl,sVal);
if (nPos > nFirstPos)
nPos = nFirstPos;
}
WCEditCtrl_setCursorPos(wSrcWnd,oCtrl,oCtrl.elEdit,nPos);
if (!WCString_isEmpty(oCtrl.parentName))
{
var oParentCtrl = WCObj_getObj(wSrcWnd,oCtrl.parentName);
WCListCtrl_doFocusEdit(wSrcWnd,oParentCtrl.name,oCtrl.elEdit,oCtrl);
}
}
catch (ex)
{
}
}
function WCEditCtrl_doBlur(wSrcWnd,sName,elInput)
{
try
{
var oCtrl = WCObj_getObj(wSrcWnd,sName);
if (!WCString_isEmpty(oCtrl.parentName))
{
var oParentCtrl = WCObj_getObj(wSrcWnd,oCtrl.parentName);
if (oParentCtrl != null && oParentCtrl.editRow == oCtrl.row && oParentCtrl.editCol == oCtrl.col && oParentCtrl.editCtrlArrayIdx == oCtrl.editCtrlArrayIdx)
{
WCListCtrl_blurEditEx(wSrcWnd,oParentCtrl,oCtrl.row,oCtrl.col,oCtrl);
}
}
}
catch (ex)
{
}
}
function WCEditCtrl_keyDown(wSrcWnd,sName,elEdit)
{
try
{
WCEditCtrl_keyDownEx(wSrcWnd,sName,elEdit);
if (wSrcWnd.event.keyCode == 13)
return false;
}
catch (ex)
{
}
}
function WCEditCtrl_keyDownEx(wSrcWnd,sName,elEdit)
{
try
{
var oCtrl = WCObj_getObj(wSrcWnd,sName);
if (WCEditCtrl_isRange(wSrcWnd,oCtrl) == true)
{
return;
}
if (oCtrl != null)
{
if (elEdit != null)
oCtrl.elEdit = elEdit;
elEdit = oCtrl.elEdit;
}
var str = elEdit.value;
var textbox = elEdit;
if (wSrcWnd.event.keyCode == 46)
{
}
if (wSrcWnd.WCEditCtrl_[안내]태그제한으로등록되지않습니다-xxonKeyDown != null)
{
var bRet = wSrcWnd.WCEditCtrl_[안내]태그제한으로등록되지않습니다-xxonKeyDown(wSrcWnd,oCtrl,elEdit);
if (bRet != false)
return;
}
if ((wSrcWnd.event.keyCode == 37
|| wSrcWnd.event.keyCode == 38
|| wSrcWnd.event.keyCode == 39
|| wSrcWnd.event.keyCode == 40)
&& wSrcWnd.event.shiftKey == false)
{
return;
}
if ((wSrcWnd.event.keyCode == 37
|| wSrcWnd.event.keyCode == 39)
&& wSrcWnd.event.shiftKey == true)
{
return;
}
if (wSrcWnd.event.keyCode == 9)
{
return;
}
if (wSrcWnd.event.keyCode == 13)
{
return;
}
if (wSrcWnd.event.keyCode == 8)
{
var cDelimiter = WCEditCtrl_getDelimiter(wSrcWnd,oCtrl);
var nPos = WCEditCtrl_getCursorPos(wSrcWnd,oCtrl,textbox);
while (nPos > 0 && textbox.value.charAt(nPos-1) == cDelimiter)
{
nPos --;
WCEditCtrl_setCursorPos(wSrcWnd,oCtrl,textbox,nPos);
}
}
if (wSrcWnd.event.keyCode == 46)
{
{
var nPos = WCEditCtrl_getCursorPos(wSrcWnd,oCtrl,textbox);
var sSrc = textbox.value;
while (true)
{
var cChar = sSrc.charAt(nPos);
if (WCEditCtrl_isValidChar(wSrcWnd,oCtrl,cChar) == true)
break;
sSrc = WCString_removeCharAt(sSrc,nPos);
}
oCtrl.elEdit.value = sSrc;
var nNewCursorPos = nPos;
WCEditCtrl_setCursorPos(wSrcWnd,oCtrl,textbox,nNewCursorPos);
}
}
if (wSrcWnd.event.keyCode == 8
|| wSrcWnd.event.keyCode == 45
|| wSrcWnd.event.keyCode == 46)
{
return;
}
if (wSrcWnd.event.keyCode < 48 && wSrcWnd.event.keyCode != 9)
return;
if (WCEditCtrl_isValidCharCode(wSrcWnd,oCtrl,wSrcWnd.event) != true
&& wSrcWnd.event.ctrlKey == false
&& wSrcWnd.event.altKey == false)
{
wSrcWnd.event.returnValue=false;
return;
}
if (WCEditCtrl_getFormat(wSrcWnd,oCtrl) != null)
{
if (WCEditCtrl_getFormat(wSrcWnd,oCtrl).length > 0)
{
var sExtract = WCEditCtrl_extractChar(wSrcWnd,oCtrl,str,-1);
var sExtractFormat = WCEditCtrl_extractFormatChar(wSrcWnd,oCtrl,-1);
if (sExtract.length >= sExtractFormat.length)
{
wSrcWnd.event.returnValue=false;
return false;
}
}
}
var cChar = String.fromCharCode(wSrcWnd.event.keyCode);
if (WCEditCtrl_isValidChar(wSrcWnd,oCtrl,cChar) != true)
{
wSrcWnd.event.returnValue=false;
return false;
}
{
var sFilter = WCEditCtrl_getFilter(wSrcWnd,oCtrl);
if (oCtrl.formatType == "float" || oCtrl.formatType == "integer"
|| oCtrl.formatType == "money" || oCtrl.formatType == "number"
|| sFilter == "1")
{
var sText = WCString_extractNumber(oCtrl.elEdit.value);
var nMaxLen = WCEditCtrl_getMaxLength(wSrcWnd,oCtrl);
if (nMaxLen > 0 && nMaxLen <= sText.length)
{
wSrcWnd.event.returnValue=false;
return false;
}
}
}
}
catch (ex)
{
}
}
function WCEditCtrl_isRange(wSrcWnd,oCtrl)
{
try
{
var objRange = wSrcWnd.document.selection.createRange();
if (objRange != null)
{
if (!WCString_isEmpty(objRange.text))
{
if (wSrcWnd.event.keyCode == 37
|| wSrcWnd.event.keyCode == 38
|| wSrcWnd.event.keyCode == 39
|| wSrcWnd.event.keyCode == 40
|| wSrcWnd.event.keyCode == 8
|| wSrcWnd.event.keyCode == 46
)
{
return true;
}
if (WCEditCtrl_isValidCharCode(wSrcWnd,oCtrl,wSrcWnd.event) != true
&& wSrcWnd.event.ctrlKey == false
&& wSrcWnd.event.altKey == false)
{
wSrcWnd.event.returnValue=false;
return true;
}
return true;
}
}
return false;
}
catch (ex)
{
}
}
function WCEditCtrl_keyUp(wSrcWnd,sName,elEdit)
{
try
{
var oCtrl = WCObj_getObj(wSrcWnd,sName);
if (WCEditCtrl_isRange(wSrcWnd,oCtrl) == true)
{
return;
}
if (wSrcWnd.event.keyCode == 9)
return;
if (elEdit != null)
oCtrl.elEdit = elEdit;
elEdit = oCtrl.elEdit;
var str = elEdit.value;
var textbox = elEdit;
if (wSrcWnd.event.keyCode == 8)
{
WCEditCtrl_formatEdit(wSrcWnd,oCtrl);
return;
}
else if (wSrcWnd.event.keyCode == 45)
{
WCEditCtrl_formatEdit(wSrcWnd,oCtrl);
return;
}
else if (wSrcWnd.event.keyCode == 46)
{
WCEditCtrl_formatEdit(wSrcWnd,oCtrl);
return;
}
if ((wSrcWnd.event.keyCode == 37
|| wSrcWnd.event.keyCode == 38
|| wSrcWnd.event.keyCode == 39
|| wSrcWnd.event.keyCode == 40)
&& wSrcWnd.event.shiftKey == false)
{
return;
}
if ((wSrcWnd.event.keyCode == 37
|| wSrcWnd.event.keyCode == 39)
&& wSrcWnd.event.shiftKey == true)
{
return;
}
if ((wSrcWnd.event.keyCode == 255
)
&& wSrcWnd.event.shiftKey == true)
{
return;
}
if (wSrcWnd.event.keyCode < 48 && wSrcWnd.event.keyCode != 9)
{
return;
}
if ((wSrcWnd.event.keyCode >= 48 && wSrcWnd.event.keyCode <= 57
&& wSrcWnd.event.ctrlKey == false
&& wSrcWnd.event.altKey == false
&& wSrcWnd.event.shiftKey == false)
|| (wSrcWnd.event.keyCode >= 96 && wSrcWnd.event.keyCode <= 105
&& wSrcWnd.event.ctrlKey == false
&& wSrcWnd.event.altKey == false
&& wSrcWnd.event.shiftKey == false)
)
{
}
if (wSrcWnd.WCEditCtrl_[안내]태그제한으로등록되지않습니다-xxonKeyUp != null)
{
var bRet = wSrcWnd.WCEditCtrl_[안내]태그제한으로등록되지않습니다-xxonKeyUp(wSrcWnd,oCtrl,elEdit);
if (bRet != false)
return;
}
WCEditCtrl_formatEdit(wSrcWnd,oCtrl);
if (WCEditCtrl_getMaxLength(wSrcWnd,oCtrl) >= 0)
{
if (oCtrl.formatType == "float" || oCtrl.formatType == "integer" || oCtrl.formatType == "money" || oCtrl.formatType == "number")
{
var sText = WCString_extractNumber(oCtrl.elEdit.value);
if (WCEditCtrl_getMaxLength(wSrcWnd,oCtrl) <= sText.length)
{
wSrcWnd.event.returnValue=false;
var sNext = oCtrl.nextElementId;
if (!WCString_isEmpty(sNext))
{
var oNextElmt = wSrcWnd.document.getElementById(sNext);
if (oNextElmt != null)
oNextElmt.focus();
}
return false;
}
}
}
}
catch (ex)
{
}
}
function WCEditCtrl_getCharCount(wSrcWnd,oCtrl,sSrc,cChar,nEnd)
{
try
{
var sDest = "";
var nLen = sSrc.length;
for (var i=0;i<nLen;i++)
{
if (nEnd >= 0 && nEnd <= i)
{
break;
}
var cSrc = sSrc.charAt(i);
if (cChar.indexOf(cSrc) < 0)
{
continue;
}
sDest += cSrc;
}
return sDest.length;
}
catch (ex)
{
}
return 0;
}
function WCEditCtrl_getValue(wSrcWnd,oCtrl)
{
try
{
var cAny = WCEditCtrl_getAny(wSrcWnd,oCtrl);
var sDest = "";
var sSrc = oCtrl.elEdit.value;
var nLen = sSrc.length;
for (var i=0;i<nLen;i++)
{
var cSrc = sSrc.charAt(i);
if (cSrc == cAny)
continue;
sDest += cSrc;
}
return sDest;
}
catch (ex)
{
}
}
function WCEditCtrl_getToken(wSrcWnd,oCtrl,sSrc,nTokenIdx)
{
try
{
var oLex = new Object();
oLex.objIndex = 0;
oLex.srcUrl = sSrc;
var sTok = "";
for (var i=0;i<=nTokenIdx;i++)
{
sTok = WCEditCtrl_getTokenByObj(wSrcWnd,oCtrl,oLex);
}
return sTok;
}
catch (ex)
{
}
}
function WCEditCtrl_getTokenByObj(wSrcWnd,oCtrl,oLex)
{
try
{
var sTok = "";
var sSrc = oLex.srcUrl;
var nLen = sSrc.length;
while (oLex.objIndex < nLen)
{
var cSrc = sSrc.charAt(oLex.objIndex);
oLex.objIndex ++;
if (WCEditCtrl_isValidChar(wSrcWnd,oCtrl,cSrc) == true)
sTok += cSrc;
else
break;
}
return sTok;
}
catch (ex)
{
}
}
function WCEditCtrl_extractChar(wSrcWnd,oCtrl,sSrc,nEnd)
{
try
{
var cDelimiter = WCEditCtrl_getDelimiter(wSrcWnd,oCtrl);
var cAny = WCEditCtrl_getAny(wSrcWnd,oCtrl);
var sDest = "";
var nLen = sSrc.length;
for (var i=0;i<nLen;i++)
{
if (nEnd >= 0 && nEnd <= i)
{
break;
}
var cSrc = sSrc.charAt(i);
if (cSrc == cAny || cSrc == cDelimiter || cSrc == oCtrl.unit || WCEditCtrl_isValidChar(wSrcWnd,oCtrl,cSrc) != true)
{
continue;
}
sDest += cSrc;
}
return sDest;
}
catch (ex)
{
}
}
function WCEditCtrl_getFirstAnyPos(wSrcWnd,oCtrl,sSrc)
{
try
{
var cAny = WCEditCtrl_getAny(wSrcWnd,oCtrl);
var nLen = sSrc.length;
for (var i=0;i<nLen;i++)
{
var cSrc = sSrc.charAt(i);
if (cSrc == cAny)
{
return i;
}
}
return nLen;
}
catch (ex)
{
}
}
function WCEditCtrl_extractCharToPosition(wSrcWnd,oCtrl,sSrc,nEnd)
{
var sDest = "";
var nLen = sSrc.length;
for (var i=0;i<nLen;i++)
{
if (nEnd >= 0 && nEnd <= i)
break;
var cSrc = sSrc.charAt(i);
if (WCEditCtrl_isValidChar(wSrcWnd,oCtrl,cSrc) != true)
continue;
sDest += cSrc;
}
return sDest;
}
function WCEditCtrl_getFirstInvalidCharPosition(wSrcWnd,oCtrl)
{
var cAny = WCEditCtrl_getAny(wSrcWnd,oCtrl);
var sSrc = oCtrl.elEdit.value;
var nLen = sSrc.length;
for (var i=0;i<nLen;i++)
{
var cSrc = sSrc.charAt(i);
if (cAny == cSrc)
{
return i;
}
}
return nLen;
}
function WCEditCtrl_extractInvalidCharToPosition(wSrcWnd,oCtrl,sSrc,nEnd)
{
var sDest = "";
var nLen = sSrc.length;
for (var i=0;i<nLen;i++)
{
if (nEnd >= 0 && nEnd <= i)
break;
var cSrc = sSrc.charAt(i);
if (WCEditCtrl_isValidChar(wSrcWnd,oCtrl,cSrc) == true)
continue;
sDest += cSrc;
}
return sDest;
}
function WCEditCtrl_extractFormatChar(wSrcWnd,oCtrl,nEnd)
{
try
{
var cDelimiter = WCEditCtrl_getDelimiter(wSrcWnd,oCtrl);
var cAny = WCEditCtrl_getAny(wSrcWnd,oCtrl);
var sDest = "";
var sSrc = WCEditCtrl_getFormat(wSrcWnd,oCtrl);
var nLen = sSrc.length;
for (var i=0;i<nLen;i++)
{
if (nEnd >= 0 && nEnd <= i)
{
break;
}
var cSrc = sSrc.charAt(i);
if (cSrc == cAny)
{
sDest += cSrc;
continue;
}
if (cSrc == cDelimiter || WCEditCtrl_isValidChar(wSrcWnd,oCtrl,cSrc) != true)
{
continue;
}
sDest += cSrc;
}
return sDest;
}
catch (ex)
{
}
return "";
}
function WCEditCtrl_isDigit(wSrcWnd,oCtrl,sValue)
{
inputStr = sValue;
for( var i = 0 ; i < inputStr.length ; i++ )
{
var oneChar = inputStr.charAt(i)
if (oneChar < '0' || oneChar > '9')
{
return false;
}
}
return true;
}
function WCEditCtrl_isValid(wSrcWnd,oCtrl,sValue)
{
try
{
var cDelimiter = WCEditCtrl_getDelimiter(wSrcWnd,oCtrl);
var cAny = WCEditCtrl_getAny(wSrcWnd,oCtrl);
var sSrc = new String(sValue);
var nSrcLen = sSrc.length;
var sDest = "";
var nFormatIdx = 0;
var nSrcIdx = 0;
if (WCEditCtrl_getFormat(wSrcWnd,oCtrl) == null)
return true;
var nFormatLen = WCEditCtrl_getFormat(wSrcWnd,oCtrl).length;
while (nFormatIdx < nFormatLen && nSrcIdx < nSrcLen)
{
var cSrc = sSrc.charAt(nSrcIdx);
var cFormat = WCEditCtrl_getFormat(wSrcWnd,oCtrl).charAt(nFormatIdx);
if (cFormat == cAny)
{
if (!WCEditCtrl_isDigit(wSrcWnd,oCtrl,cSrc))
return false;
}
else if (cFormat == cDelimiter)
{
if (cSrc != cDelimiter)
return false;
}
}
return true;
}
catch (ex)
{
}
}
function WCEditCtrl_formatValue(wSrcWnd,oCtrl,sValue)
{
try
{
if (oCtrl.formatType != null)
{
if (oCtrl.formatType == "float")
{
var sSrc = WCString_extractNumber(sValue);
var nLeft = 0;
var nLen = sSrc.length;
var nRight = nLen;
if (nLen > oCtrl.decimalPoint)
{
nLeft = nLen - oCtrl.decimalPoint;
nRight = nLen - nLeft;
}
var sLeft = sSrc.substring(0,nLeft);
var sRight = sSrc.substring(nLeft,nLeft+nRight);
var sDest = sLeft+"."+sRight;
return sDest;
}
else if (oCtrl.formatType == "integer"
|| oCtrl.formatType == "number")
{
var sDest = WCString_extractNumber(sValue);
return sDest;
}
else if (oCtrl.formatType == "money")
{
var sSrc = WCString_extractNumber(sValue);
var sDest = WCString_insertDelimiterReverseOrder(wSrcWnd,oCtrl,sSrc,",",3);
if (oCtrl.unit != null)
{
var unit = oCtrl.unit;
var unitAlign = oCtrl.unitAlign;
if (unitAlign == "right")
{
sDest = sDest+unit;
}
else
{
sDest = unit + sDest;
}
}
return sDest;
}
else
{
}
}
var cDelimiter = WCEditCtrl_getDelimiter(wSrcWnd,oCtrl);
var cAny = WCEditCtrl_getAny(wSrcWnd,oCtrl);
var str = WCEditCtrl_extractChar(wSrcWnd,oCtrl,sValue,-1);
var sSrc = new String(str);
var nSrcLen = sSrc.length;
var sDest = "";
var nFormatIdx = 0;
var nSrcIdx = 0;
if (WCEditCtrl_getFormat(wSrcWnd,oCtrl) == null)
return sSrc;
var nFormatLen = WCString_getLength(WCEditCtrl_getFormat(wSrcWnd,oCtrl));
while (nFormatIdx < nFormatLen && nSrcIdx < nSrcLen)
{
var cSrc = sSrc.charAt(nSrcIdx);
if (cSrc == cDelimiter || cSrc == cAny)
{
nSrcIdx ++;
continue;
}
var cFormat = WCEditCtrl_getFormat(wSrcWnd,oCtrl).charAt(nFormatIdx);
if (cFormat == cAny)
{
sDest += cSrc;
nSrcIdx ++;
nFormatIdx ++;
}
else
{
sDest += cFormat;
nFormatIdx ++;
}
}
if (nFormatIdx < nFormatLen)
{
while (nFormatIdx < nFormatLen)
{
var cFormat = WCEditCtrl_getFormat(wSrcWnd,oCtrl).charAt(nFormatIdx);
sDest += cFormat;
nFormatIdx ++;
}
}
if (nFormatLen <= 0)
{
sDest = sSrc;
}
return sDest;
}
catch (ex)
{
}
}
function WCEditCtrl_formatText(wSrcWnd,oCtrl)
{
try
{
var sValue = oCtrl.elEdit.value;
var sDest = WCEditCtrl_formatValue(wSrcWnd,oCtrl,sValue);
oCtrl.elEdit.value = sDest;
}
catch (ex)
{
}
}
function WCEditCtrl_formatEdit(wSrcWnd,oCtrl)
{
try
{
var sFilter = WCEditCtrl_getFilter(wSrcWnd,oCtrl);
if (WCString_isEmpty(oCtrl.formatType) && WCString_isEmpty(sFilter))
{
return;
}
var textbox = oCtrl.elEdit;
var nPos = WCEditCtrl_getCursorPos(wSrcWnd,oCtrl,textbox);
if (nPos == null)
nPos = 0;
var sValue = textbox.value;
if (oCtrl.formatType == "float")
{
var sBefore = WCEditCtrl_extractCharToPosition(wSrcWnd,oCtrl,textbox.value,nPos);
var sDest = WCEditCtrl_formatValue(wSrcWnd,oCtrl,sValue);
var cChar = ".";
var nBefore = WCEditCtrl_getCharCount(wSrcWnd,oCtrl,sValue,cChar,nPos);
var nAfter = WCEditCtrl_getCharCount(wSrcWnd,oCtrl,sDest,cChar,nPos);
if (nAfter > nBefore)
nPos += (nAfter - nBefore);
else if (nAfter < nBefore)
nPos -= (nBefore - nAfter);
textbox.value = sDest;
WCEditCtrl_setCursorPos(wSrcWnd,oCtrl,textbox,nPos);
}
else if (oCtrl.formatType == "integer"
|| oCtrl.formatType == "number")
{
return;
}
else if (oCtrl.formatType == "money")
{
var sSrc = WCEditCtrl_extractChar(wSrcWnd,oCtrl,sValue,-1);
var sDest = WCEditCtrl_formatValue(wSrcWnd,oCtrl,sSrc);
var cChar = ","+oCtrl.unit;
var nBefore = WCEditCtrl_getCharCount(wSrcWnd,oCtrl,sValue,cChar,nPos);
var nAfter = WCEditCtrl_getCharCount(wSrcWnd,oCtrl,sDest,cChar,nPos);
if (nAfter > nBefore)
nPos += (nAfter - nBefore);
else if (nAfter < nBefore)
nPos -= (nBefore - nAfter);
textbox.value = sDest;
WCEditCtrl_setCursorPos(wSrcWnd,oCtrl,textbox,nPos);
return;
}
else
{
var sDest = WCEditCtrl_formatValue(wSrcWnd,oCtrl,sValue);
var nAfterCursorPos = WCEditCtrl_getFirstAnyPos(wSrcWnd,oCtrl,sDest);
var sSrc = textbox.value;
var sBefore = WCEditCtrl_extractCharToPosition(wSrcWnd,oCtrl,sSrc,nPos);
var sInvalidBefore = WCEditCtrl_extractInvalidCharToPosition(wSrcWnd,oCtrl,sSrc,nPos);
var sInvalidAfter = WCEditCtrl_extractInvalidCharToPosition(wSrcWnd,oCtrl,sDest,nPos);
if (sBefore.length > 0 && sBefore.length < nPos)
nPos = sBefore.length + sInvalidBefore.length;
if (sInvalidAfter.length - sInvalidBefore.length > 0)
nPos += sInvalidAfter.length - sInvalidBefore.length;
if (nPos > nAfterCursorPos)
nPos = nAfterCursorPos;
textbox.value = sDest;
WCEditCtrl_setCursorPos(wSrcWnd,oCtrl,textbox,nPos);
}
}
catch (ex)
{
}
}
function WCEditCtrl_getCursorPos(wSrcWnd,oCtrl,elElmt)
{
try
{
if (elElmt == null)
elElmt = oCtrl.elEdit;
var sOldText = elElmt.value;
var objRange = wSrcWnd.document.selection.createRange();
var sOldRange = objRange.text;
var sWeirdString = '#%~';
objRange.text = sOldRange + sWeirdString;
objRange.moveStart('character', (0 - sOldRange.length - sWeirdString.length));
var sNewText = elElmt.value;
objRange.text = sOldRange;
for (var i=0; i <= sNewText.length; i++)
{
var sTemp = sNewText.substring(i, i + sWeirdString.length);
if (sTemp == sWeirdString)
{
var cursorPos = (i - sOldRange.length);
return cursorPos;
}
}
return null;
}
catch (ex)
{
}
return null;
}
function WCEditCtrl_insertAtCursor(wSrcWnd,oCtrl,myField, myValue)
{
if (wSrcWnd.document.selection)
{
myField.focus();
sel = wSrcWnd.document.selection.createRange();
sel.text = myValue;
sel.moveStart("character", -myValue.length);
sel.select();
}
else if (myField.selecti[안내]태그제한으로등록되지않습니다-xxonStart || myField.selecti[안내]태그제한으로등록되지않습니다-xxonStart == '0')
{
var startPos = myField.selecti[안내]태그제한으로등록되지않습니다-xxonStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
myField.selecti[안내]태그제한으로등록되지않습니다-xxonStart = startPos;
myField.selectionEnd = startPos + myValue.length;
}
else
{
myField.value += myValue;
}
}
function WCEditCtrl_backAtCursor(wSrcWnd,oCtrl,myField)
{
if (wSrcWnd.document.selection)
{
myField.focus();
sel = wSrcWnd.document.selection.createRange();
if(sel.text.length > 0)
{
sel.text="";
}
else
{
sel.moveStart("character",-1);
sel.text="";
}
sel.select();
}
else if (myField.selecti[안내]태그제한으로등록되지않습니다-xxonStart || myField.selecti[안내]태그제한으로등록되지않습니다-xxonStart == '0')
{
var startPos = myField.selecti[안내]태그제한으로등록되지않습니다-xxonStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos-1) + myField.value.substring(endPos, myField.value.length);
myField.selecti[안내]태그제한으로등록되지않습니다-xxonStart = startPos-1;
myField.selectionEnd = startPos-1;
myField.focus();
}
else
{
myField.value=myField.value.substr(0,(myField.value.length-1));
myField.focus();
}
}
function WCEditCtrl_edInsertContent(wSrcWnd,oCtrl,myField, myValue)
{
if (wSrcWnd.document.selection)
{
myField.focus();
var sel = wSrcWnd.document.selection.createRange();
sel.text = myValue;
myField.focus();
}
else if (myField.selecti[안내]태그제한으로등록되지않습니다-xxonStart || myField.selecti[안내]태그제한으로등록되지않습니다-xxonStart == '0')
{
var startPos = myField.selecti[안내]태그제한으로등록되지않습니다-xxonStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
myField.focus();
myField.selecti[안내]태그제한으로등록되지않습니다-xxonStart = startPos + myValue.length;
myField.selectionEnd = startPos + myValue.length;
}
else
{
myField.value += myValue;
myField.focus();
}
}
function WCEditCtrl_setCursorPos(wSrcWnd,oCtrl,elEdit,nPos)
{
try
{
var txtRange = elEdit.createTextRange();
txtRange.moveStart( "character", nPos);
txtRange.moveEnd( "character", -1*(elEdit.value.length-nPos));
txtRange.select();
}
catch (ex)
{
}
}
function WCEditCtrl_setEdit(wSrcWnd,oCtrl,elEdit)
{
try
{
var sName = "";
if (oCtrl != null)
{
oCtrl.elEdit = elEdit;
sName = oCtrl.name;
}
{
}
oCtrl.elEdit.[안내]태그제한으로등록되지않습니다-xxonkeydown = new Function("eval(\"WCEditCtrl_keyDown(this.document.frames.window,'"+oCtrl.name+"',this);\")");
oCtrl.elEdit.[안내]태그제한으로등록되지않습니다-xxonkeyup = new Function("eval(\"WCEditCtrl_keyUp(this.document.frames.window,'"+oCtrl.name+"',this);\")");
oCtrl.elEdit.[안내]태그제한으로등록되지않습니다-xxonkeypress = new Function("eval(\"WCEditCtrl_keyPress(this.document.frames.window,'"+oCtrl.name+"',this);\")");
oCtrl.elEdit.[안내]태그제한으로등록되지않습니다-xxonfocus = new Function("eval(\"WCEditCtrl_doFocus(this.document.frames.window,'"+oCtrl.name+"',this);\")");
oCtrl.elEdit.[안내]태그제한으로등록되지않습니다-xxonblur = new Function("eval(\"WCEditCtrl_doBlur(this.document.frames.window,'"+oCtrl.name+"',this);\")");
}
catch (ex)
{
}
}
function WCEditCtrl_isAny(wSrcWnd,oCtrl,cChar)
{
}
function WCEditCtrl_isValidChar(wSrcWnd,oCtrl,cChar)
{
var sFilter = WCEditCtrl_getFilter(wSrcWnd,oCtrl);
if (sFilter == null)
return true;
var nLen = sFilter.length;
for (var i=0;i<nLen;i++)
{
var cTest = sFilter.charAt(i);
if (cTest == '1')
{
if ('0' <= cChar && cChar <= '9')
return true;
}
if (cTest == 'a')
{
if ('a' <= cChar && cChar <= 'z')
return true;
}
if (cTest == 'A')
{
if ('A' <= cChar && cChar <= 'Z')
return true;
}
}
return false;
}
function WCEditCtrl_setElementFormat(wSrcWnd,sElmtid,sFormat,nMaxLen,sAlign)
{
try
{
if (sFormat == "number")
{
if (sAlign == null)
sAlign = "left";
if (nMaxLen == null)
nMaxLen = -1;
var oParentCtrl = null;
var sName = sElmtid;
var oCtrl = WCEditCtrl_new(wSrcWnd,oParentCtrl,sName);
var elEdit = wSrcWnd.document.getElementById(sElmtid);
if (nMaxLen > 0)
{
elEdit.size = nMaxLen+3;
}
WCEditCtrl_setEdit(wSrcWnd,oCtrl,elEdit);
WCEditCtrl_setImeMode(wSrcWnd,oCtrl,"disabled");
WCEditCtrl_setFormatType(wSrcWnd,oCtrl,"integer");
WCEditCtrl_setTextAlign(wSrcWnd,oCtrl,sAlign);
WCEditCtrl_setMaxLength(wSrcWnd,oCtrl,nMaxLen);
WCEditCtrl_formatText(wSrcWnd,oCtrl);
return oCtrl;
}
else if (sFormat == "datetime")
{
var oParentCtrl = null;
var sName = sElmtid;
var oCtrl = WCEditCtrl_new(wSrcWnd,oParentCtrl,sName);
var elEdit = wSrcWnd.document.getElementById(sElmtid);
WCEditCtrl_setEdit(wSrcWnd,oCtrl,elEdit);
WCEditCtrl_setImeMode(wSrcWnd,oCtrl,"disabled");
WCEditCtrl_setTextAlign(wSrcWnd,oCtrl,"left");
WCEditCtrl_setAny(wSrcWnd,oCtrl,".");
WCEditCtrl_setFilter(wSrcWnd,oCtrl,"1");
WCEditCtrl_setFormat(wSrcWnd,oCtrl,"....-..-.. ..:..:..");
WCEditCtrl_formatText(wSrcWnd,oCtrl);
return oCtrl;
}
else if (sFormat == "date")
{
var oParentCtrl = null;
var sName = sElmtid;
var oCtrl = WCEditCtrl_new(wSrcWnd,oParentCtrl,sName);
var elEdit = wSrcWnd.document.getElementById(sElmtid);
WCEditCtrl_setEdit(wSrcWnd,oCtrl,elEdit);
WCEditCtrl_setImeMode(wSrcWnd,oCtrl,"disabled");
WCEditCtrl_setTextAlign(wSrcWnd,oCtrl,"left");
WCEditCtrl_setAny(wSrcWnd,oCtrl,".");
WCEditCtrl_setFilter(wSrcWnd,oCtrl,"1");
WCEditCtrl_setFormat(wSrcWnd,oCtrl,"....-..-..");
WCEditCtrl_formatText(wSrcWnd,oCtrl);
return oCtrl;
}
}
catch (ex)
{
}
}
var g_oPage = new Object();
g_oPage.aCtrl = new Array();
function WCObj_getObj(wSrcWnd,sName)
{
try
{
if (sName == null)
return;
var oWnd = wSrcWnd;
while (true)
{
if (oWnd == null)
break;
var nSize = oWnd.g_oPage.aCtrl.length;
if (nSize >= 30)
{
WCPage_debugTrace(wSrcWnd,"warning,WCObj.js,oWnd.g_oPage.aCtrl.length="+nSize);
}
for (var i=0;i<nSize;i++)
{
if (oWnd.g_oPage.aCtrl[i] == null)
continue;
if (oWnd.g_oPage.aCtrl[i].name == sName)
{
return oWnd.g_oPage.aCtrl[i];
}
}
if (oWnd == oWnd.parent)
break;
oWnd = oWnd.parent;
}
}
catch (e)
{
}
return null;
}
function WCObj_init(wSrcWnd,oCtrl)
{
oCtrl.name = null;
oCtrl.pageObj = wSrcWnd.g_oPage;
}
function WCCtrl_getEmptySlot(wSrcWnd)
{
try
{
for (var i=0;true;i++)
{
if (wSrcWnd.g_oPage.aCtrl[i] == null)
return i;
}
}
catch (ex)
{
}
}
function WCCtrl_newIdx(wSrcWnd)
{
try
{
var oCtrl = new Object();
var nIdx = WCCtrl_getEmptySlot(wSrcWnd);
wSrcWnd.g_oPage.aCtrl[nIdx] = oCtrl;
oCtrl.objIndex = nIdx;
oCtrl.containerWindow = wSrcWnd;
WCObj_init(wSrcWnd,oCtrl);
return oCtrl;
}
catch (e)
{
}
return null;
}
function WCCtrl_new(wSrcWnd)
{
try
{
var nIdx = wSrcWnd.g_oPage.aCtrl.length;
var nSize = wSrcWnd.g_oPage.aCtrl.length;
for (var i=0;i<nSize;i++)
{
if (wSrcWnd.g_oPage.aCtrl[i] == null)
{
nIdx = i;
break;
}
}
return WCCtrl_newIdx(wSrcWnd,nIdx);
}
catch (e)
{
}
return null;
}
function WCString_extractNumber(sSrc)
{
try
{
var sDest = "";
var nLen = sSrc.length;
for (var i=0;i<nLen;i++)
{
var cSrc = sSrc.charAt(i);
if (cSrc >= '0'
&& cSrc <= '9')
{
sDest += cSrc;
}
}
return sDest;
}
catch (ex)
{
}
}
function WCString_isEmpty(sSrc)
{
try
{
if (sSrc == null)
return true;
var sTmp = WCString_trim(sSrc);
if (sTmp.length == 0)
{
return true;
}
if (sSrc.length == 0)
return true;
return false;
}
catch (ex)
{
}
return true;
}
function WCString_trim(sSrc)
{
try
{
if (sSrc == null)
return null;
var sTemp = "";
sTemp = WCString_trimRight(sSrc);
sDest = WCString_trimLeft(sTemp);
return sDest;
}
catch (ex)
{
}
}
function WCString_trimRight(sSrc)
{
try
{
if (sSrc == null)
return null;
var nLen = sSrc.length;
var nIdx = -1;
var sDest = "";
var i = 0;
for (i=nLen-1;i>=0;i--)
{
var cChar = sSrc.charAt(i);
if (cChar != ' '
&& cChar != '\r'
&& cChar != '\n'
&& cChar != '\t')
{
nIdx = i;
break;
}
nIdx = i;
}
if (i < 0)
{
return "";
}
sDest = sSrc.substring(0,nIdx+1);
return sDest;
}
catch (ex)
{
}
}
function WCString_trimLeft(sSrc)
{
try
{
if (sSrc == null)
return null;
var nLen = sSrc.length;
var nIdx = -1;
var sDest = "";
var i = 0;
for (i=0;i<nLen;i++)
{
var cChar = sSrc.charAt(i);
if (cChar != ' '
&& cChar != '\r'
&& cChar != '\n'
&& cChar != '\t')
{
nIdx = i;
break;
}
nIdx = i;
}
if (i == nLen)
{
return "";
}
sDest = sSrc.substring(nIdx,nLen);
return sDest;
}
catch (ex)
{
}
}
function WCString_parseInt(sVal)
{
var nVal = Number(sVal);
if (nVal == NaN)
nVal = 0;
var sStrVal = ""+sVal;
var nDecimal = sStrVal.indexOf(".");
if (nDecimal > 0)
{
var sLeft = WCString_left(sStrVal,nDecimal);
nVal = Number(sLeft);
}
return nVal;
}
function WCString_left(sSrc,nIdx)
{
if (sSrc == null)
return sSrc;
var sRet = sSrc.substring(0,nIdx);
return sRet;
}
function WCString_removeCharAt(sSrc,nPos)
{
var sDest = "";
var nIdx = 0;
var nLen = sSrc.length;
if (nPos >= nLen)
return;
for (var i=0;i<nPos;i++)
{
var cChar = sSrc.charAt(i);
sDest += cChar;
}
for (var i=nPos+1;i<nLen;i++)
{
var cChar = sSrc.charAt(i);
sDest += cChar;
}
return sDest;
}
function WCString_insertDelimiterReverseOrder(wSrcWnd,oCtrl,sSrc,sDlm,nInterval)
{
var sDest = "";
var nIdx = 0;
var nLen = sSrc.length;
for (var i=1;i<=nLen;i++)
{
var cChar = sSrc.charAt(nLen-i);
sDest = cChar+sDest;
nIdx ++;
if (nIdx >= nInterval && i+1<=nLen)
{
sDest = sDlm+sDest;
nIdx = 0;
}
}
return sDest;
}
function WCString_getLength(sSrc)
{
var nLen = sSrc.length;
return nLen;
}
-- editctrl.js 끝
출처 : 고급 웹 UI 개발 라이브러리 Web Development Library 소스공개 : http://www.webdevlib.net