// Form Control State FCS_NORMAL = 0x00000000; FCS_FOCUS = 0x00000001; // focus FCS_SELECT = 0x00000002; // select FCS_HOVER = 0x00000004; // hover FCS_DOWN = 0x00000008; // down FCS_DISABLE = 0x00000010; // disable FCS_ACTIVE = 0x00000020; // active // Binding Type BT_NONE = 0; BT_SINGLE = 1; BT_NODESET = 2; XFormsControl.prototype = new XFormsElement; function XFormsControl (strParentId, strAlert, strHelp, strHint, strAccesskey, strClass, bDisabled, strId, nNavindex, strStyle, strTag, strVisibility, strUserDefineAttrib) { if (!strId) { return; } XFormsElement.call(this, strParentId, strId, strTag); /** * Attribute */ this.attribute["alert"] = strAlert; this.attribute["help"] = strHelp; this.attribute["hint"] = strHint; this.attribute["accesskey"] = strAccesskey; this.attribute["class"] = strClass; this.attribute["disabled"] = String(bDisabled); this.attribute["id"] = strId; this.attribute["navindex"] = String(nNavindex); this.attribute["tag"] = strTag; this.attribute["visibility"] = strVisibility; /** * Property */ this.disabled = bDisabled; this.hint = strHint; this.navIndex = nNavindex; this.visible = ("visible" == strVisibility) ? true : false; /** * html Element */ this.m_heControl; /** * Style */ this.m_strStyle = strStyle; /** * User Define Attribute */ this.m_strUserDefineAttrib = strUserDefineAttrib; /** * Event State 관련 */ this.m_bDown = false; this.m_bDragStart = false; this.m_bLButtonDown = false; this.m_dwState = 0; /** * 컨트롤이 가져야 할 index 멤버변수 */ this.m_TabIndex; /** * 컨트롤 안에 존재하는 새부적인 컨트롤일 경우 true (ex> combo.input , combo.button) */ this.m_bDependentCtl = false; /** * 도큐먼트에 컨트롤을 추가한다. */ if ("xforms:col" != this.attribute["tag"]) { XFormsDocument.appendControl(strId, this); } /** * 탭인덱스를 추가한다. */ model.addTabIndex(nNavindex, this); }; XFormsControl.prototype.init = function () { this.m_heControl = document.getElementById("HE_" + this.id); var bIsControl = null != this.m_heControl ? true : false; this.setStyleToAttribute(); this.setUserDefineAttribute(); if (!bIsControl) {//물리적인 tag가 존재하지 않을 때 부모의 style을 상속받는다. // this.setNotObjToChildStyle(); } else if (bIsControl && this.m_bDependentCtl) {//물리적인 tag가 존재하지만 컨트롤의 문서상에서 style을 변경할수 없는 자식들의 style을 넣어준다. //ex)combo.input , combo.buttom // this.setChildStyle(); } if (null != g_objStyleSheet) { g_objStyleSheet.applyCSS(this); } if (bIsControl) { if (!this.m_bDependentCtl) {//앞에서 적용하였기 때문에 생략한다. // this.setChildStyle(); } this.applyDefaultStyle(); // this.adjustDIVSize(); this.m_heControl.title = this.hint; if (1 == this.navIndex) { window.setTimeout("window.setFocus('" + this.id + "');", 0); } if(!this.visible) { this.m_heControl.style.visibility = "hidden"; } } this.disabled = false; }; XFormsControl.prototype.setStyleToAttribute = function () { if (null != this.m_strStyle && "" != this.m_strStyle) { this.m_strStyle = this.m_strStyle.trim(); if (";" == this.m_strStyle.charAt(this.m_strStyle.length - 1)) { this.m_strStyle = this.m_strStyle.substring(0, this.m_strStyle.length - 1); } var arStyle = this.m_strStyle.split(";"); for (var i=0; i nIndex) { if (null != this.parent) { nIndex = arTabIndex.find(this.parent); } } if (-1 <= nIndex) { var objNext; if (nIndex + 1 < arTabIndex.length) { objNext = arTabIndex[nIndex + 1]; } else { objNext = arTabIndex[0]; } if (null != objNext && (objNext.id != event.target)) { window.setFocus(objNext.id); } else { window.setFocus("body"); } } // 실제 브라우저 이벤트를 막는다. if (event.m_browserEvent.cancelable === undefined) { event.m_browserEvent.returnValue = false; } else { if (event.m_browserEvent.cancelable) { event.m_browserEvent.preventDefault (); } } this.dispatch("xforms-next"); } }; XFormsControl.prototype.onPrevious = function (event) { if (event.target == this.getId()) { var arTabIndex = model.getTabIndex(); var nIndex = arTabIndex.find(this); if (0 > nIndex) { if (null != this.parent) { nIndex = arTabIndex.find(this.parent); } } var objPrev; if (0 <= nIndex - 1) { objPrev = arTabIndex[nIndex - 1]; } else if (0 <= arTabIndex.length - 1) { objPrev = arTabIndex[arTabIndex.length - 1]; } if (null != objPrev && (objPrev.id != event.target)) { window.setFocus(objPrev.id); } else { window.setFocus("body"); } // 실제 브라우저 이벤트를 막는다. if (event.m_browserEvent.cancelable === undefined) { event.m_browserEvent.returnValue = false; } else { if (event.m_browserEvent.cancelable) { event.m_browserEvent.preventDefault (); } } this.dispatch("xforms-previous"); } }; XFormsControl.prototype.onScroll = function (event) { }; XFormsControl.prototype.onScrollDown = function (event) { }; XFormsControl.prototype.onScrollUp = function (event) { }; XFormsControl.prototype.onMouseWheel = function (event) { }; XFormsControl.prototype.onInvalid = function (event) { }; XFormsControl.prototype.onOptional = function (event) { }; XFormsControl.prototype.onReadonly = function (event) { }; XFormsControl.prototype.onReadWrite = function (event) { }; XFormsControl.prototype.onRequired = function (event) { }; XFormsControl.prototype.onvalid = function (event) { }; XFormsControl.prototype.onDragStart = function (event) { if ("false" != this.getAttribute("dragmode")) { event.drag = this.getId(); if (event.target == event.currentTarget) { } } }; XFormsControl.prototype.onDragEnter = function (event) { }; XFormsControl.prototype.onDragOver = function (event) { }; XFormsControl.prototype.onDragLeave = function (event) { }; XFormsControl.prototype.onDrop = function (event) { }; XFormsControl.prototype.setState = function (nState, bSet, event, bRedraw, bCallChange) { if (bSet) { switch(nState) { case FCS_HOVER : event.hover = this.getId(); this.setAttribute("hover", true); break; case FCS_DOWN : event.down = this.getId(); this.setAttribute("down", true); break; case FCS_FOCUS : event.focus = this.getId(); this.setAttribute("focus", true); break; case FCS_SELECT : this.attribute["select"] = "true"; break; case FCS_DISABLE : this.attribute["disable"] = "true"; break; } this.m_dwState |= nState; } else { switch(nState) { case FCS_HOVER : event.hover = ""; this.setAttribute("hover", false); break; case FCS_DOWN : event.down = ""; this.setAttribute("down", false); break; case FCS_FOCUS : event.focus = ""; this.setAttribute("focus", false); break; case FCS_SELECT : this.attribute["select"] = "false"; break; case FCS_DISABLE : this.attribute["disable"] = "false"; break; } this.m_dwState &= ~nState; } this.resetStyle(nState, bSet); if (bCallChange) { this.onStateChange(nState, bSet); } }; XFormsControl.prototype.resetStyle = function (nState, bSet) { var htStyle = null; if (FCS_NORMAL == nState) { htStyle = this.attribute; } else { if (nState & FCS_DISABLE) { if (nState & FCS_SELECT) { htStyle = this.m_htSelectStyle; } if (nState & FCS_DISABLE) { htStyle = this.m_htDisableStyle; } } else { if (nState & FCS_HOVER) { htStyle = this.m_htHoverStyle; } if (nState & FCS_SELECT) { htStyle = this.m_htSelectStyle; } if (nState & FCS_FOCUS) { htStyle = this.m_htFocusStyle; } if (nState & FCS_DOWN) { htStyle = this.m_htDownStyle; } } } if (null != htStyle) { for (var strKey in htStyle) { var strValue = htStyle[strKey]; if (!bSet) { strValue = this.attribute[strKey]; } if (STYLE_LIST[strKey]) { HtmlLib.setStyle(this.m_heControl, strKey, strValue); } } } else { if (null != this.m_heControl) { if (nState & FCS_DISABLE) { var nConStatus = this.getEditControls(); if (1 == nConStatus) { if (!bSet) { this.m_heControl.style.backgroundColor = null != this.attribute["background-color"] ?this.attribute["background-color"] : "#ffffff"; } else { this.m_heControl.style.backgroundColor = null != this.attribute["disable.background-color"] ? this.attribute["disable.background-color"] : "#EBEBE4"; } } else if (2 == nConStatus) { if (!bSet) { this.m_heControl.style.color = null != this.attribute["color"] ?this.attribute["color"] : "#000000"; } else { this.m_heControl.style.color = null != this.attribute["disable.background-color"] ? this.attribute["disable.background-color"] : "#EBEBE4"; } } } } } }; XFormsControl.prototype.getState = function (nState) { return this.m_dwState & nState; }; XFormsControl.prototype.isFocusValid = function (nState) { var heParent = this.m_heControl; while (null != heParent && "HE_body" != heParent.id) { if ("hidden" == heParent.style.visibility || "none" == heParent.style.display || true == heParent.disabled) { return false; } if (is_firefox) { heParent = heParent.parentNode; } else { heParent = heParent.parentElement; } } return true; }; XFormsControl.prototype.getEditControls = function () { // CON_TPYE_EDIT = 1; //CON_TPYE_VIEW = 2; //CON_TPYE_BUTTON = 3; var strElementName = this.elementName; if ("xforms:input" == strElementName || "xforms:comboinput" == strElementName || "xforms:output" == strElementName || "xforms:secret" == strElementName || "xforms:textarea" == strElementName) { strElementName = null; return CON_TPYE_EDIT; } else if ("xforms:select1" == strElementName || "minimal" == this.attribute["appearance"]) { strElementName = null; return CON_TPYE_EDIT; } else if ("xforms:button" == strElementName) { strElementName = null; return CON_TPYE_BUTTON; } else { strElementName = null; return CON_TPYE_VIEW; } }; XFormsControl.prototype.defaultAction = function (strEventName, event) { if("onaccesskey" == strEventName) { this.dispatch("DOMActivate"); this.dispatch("xforms-activate"); } if (!this.isEnable()) { return; } switch(strEventName) { case "onmouseactivate" : this.onMouseActivate(event); break; case "onmousemove" : this.onMouseMove(event); break; case "onmousedown" : this.onMouseDown(event); break; case "onmouseenter" : this.onMouseEnter(event); break; case "onmouseup" : this.onMouseUp(event); break; case "oncursor" : this.onCursor(event); break; case "onmouseover" : this.onMouseOver(event); break; case "onmouseout" : this.onMouseOut(event); break; case "onclick" : this.onClick(event); break; case "ondelayclick" : this.onDelayClick(event); break; case "ondblclick" : this.onDblClick(event); break; case "onfocus" : this.onFocus(event); break; case "onblur" : this.onBlur(event); break; case "onkeypress" : this.onKeyPress(event); break; case "onkeydown" : this.onKeyDown(event); break; case "onkeyup" : this.onKeyUp(event); break; case "onscrolldown" : this.onScrollDown(event); break; case "onscrollup" : this.onScrollUp(event); break; case "onscrollpagedown" : this.onScrollPageDown(event); break; case "onscrollpageup" : this.onScrollPageUp(event); break; case "onscrollpos" : this.onScrollPos(event); break; case "onscrolltrack" : this.onScrollTrack(event); break; case "onscrolltrackdown": this.onScrollTrackDown(event);break; case "onscrolltrackup" : this.onScrollTrackUp(event); break; case "onscroll" : this.onScroll(event); break; case "onmousewheel" : this.onMouseWheel(event); break; case "ontimer" : this.onTimer(event); break; case "onnext" : this.onNext(event); break; case "onprevious" : this.onPrevious(event); break; case "xforms-invalid" : this.onInvalid(event); break; case "xforms-optional" : this.onOptional(event); break; case "xforms-readonly" : this.onReadonly(event); break; case "xforms-readwrite" : this.onReadWrite(event); break; case "xforms-required" : this.onRequired(event); break; case "xforms-valid" : this.onvalid(event); break; case "xforms-enabled" : this.onEnabled(event); break; case "xforms-disabled" : this.onDisabled(event); break; case "ondragenter" : this.onDragEnter(event); break; case "ondragleave" : this.onDragLeave(event); break; case "ondrop" : this.onDrop(event); break; case "ondragover" : this.onDragOver(event); break; case "ondragstart" : this.onDragStart(event); break; case "onscrollmax" : this.onScrollMax(event); break; case "onscrollmin" : this.onScrollMin(event); break; } }; XFormsControl.prototype.getClientLeft = function (bCalcScroll) { var nClientLeft = 0; var heOffsetParent = this.m_heControl; while (null != heOffsetParent) { nClientLeft += heOffsetParent.offsetLeft; if (heOffsetParent != this.m_heControl ) { nClientLeft += heOffsetParent.clientLeft; } if (bCalcScroll && heOffsetParent != document.body) { nClientLeft -= (is_android ? 0 : heOffsetParent.scrollLeft); } heOffsetParent = heOffsetParent.offsetParent; } return nClientLeft; }; XFormsControl.prototype.getClientTop = function (bCalcScroll) { var nClientTop = 0; var heOffsetParent = this.m_heControl; while (null != heOffsetParent) { nClientTop += heOffsetParent.offsetTop; if (heOffsetParent != this.m_heControl) { nClientTop += heOffsetParent.clientTop; } if (bCalcScroll&& heOffsetParent != document.body) { nClientTop -= (is_android ? 0 : heOffsetParent.scrollTop); } heOffsetParent = heOffsetParent.offsetParent; } return nClientTop; }; XFormsControl.prototype.preTranslateEvent = function (event) { var nScrolledTargetX = event.targetX; var nScrolledTargetY = event.targetY; var heOffsetParent = null; var clAllItem = document.allElement; if (null != clAllItem.item(event.target)) { //컨트롤의 존재 유무를 제어한다. heOffsetParent = clAllItem.item(event.target).m_heControl; } var strParentId = null != heOffsetParent ? heOffsetParent.getAttribute("id") : null; if (strParentId) { strParentId = strParentId.replace("HE_", ""); } while (null != heOffsetParent && strParentId != event.currentTarget) { nScrolledTargetX += heOffsetParent.offsetLeft; nScrolledTargetY += heOffsetParent.offsetTop; if (strParentId != event.target) { nScrolledTargetX = nScrolledTargetX + heOffsetParent.clientLeft - heOffsetParent.scrollLeft; nScrolledTargetY = nScrolledTargetY + heOffsetParent.clientLeft - heOffsetParent.scrollTop; } heOffsetParent = heOffsetParent.offsetParent; if (heOffsetParent) { strParentId = heOffsetParent.getAttribute("id"); if (strParentId) { strParentId = strParentId.replace("HE_", ""); } } } if (null != heOffsetParent && event.target != event.currentTarget) { nScrolledTargetX -= heOffsetParent.scrollLeft; nScrolledTargetY -= heOffsetParent.scrollTop; } event.x = nScrolledTargetX; event.y = nScrolledTargetY; }; /** * jquery Effects hide() */ XFormsControl.prototype.hide = function () { var arArg = arguments; switch (arArg.length) { case 1: { $(this.m_heControl).hide(arArg[0]); break; } case 2: { $(this.m_heControl).hide(arArg[0] ,arArg[1]); break; } case 3: { $(this.m_heControl).hide(arArg[0], arArg[1], arArg[2]); break; } default: { $(this.m_heControl).hide(); break; } } }; /** * jquery Effects show() */ XFormsControl.prototype.show = function () { var arArg = arguments; switch (arArg.length) { case 1: { $(this.m_heControl).show(arArg[0]); break; } case 2: { $(this.m_heControl).show(arArg[0] ,arArg[1]); break; } case 3: { $(this.m_heControl).show(arArg[0], arArg[1], arArg[2]); break; } default: { $(this.m_heControl).show(); break; } } }; /** * jquery Effects animate() */ XFormsControl.prototype.animate = function () { var arArg = arguments; switch (arArg.length) { case 1: { $(this.m_heControl).animate(arArg[0]); break; } case 2: { $(this.m_heControl).animate(arArg[0] ,arArg[1]); break; } case 3: { $(this.m_heControl).animate(arArg[0], arArg[1], arArg[2]); break; } case 4: { $(this.m_heControl).animate(arArg[0], arArg[1], arArg[2], arArg[3]); break; } default: { $(this.m_heControl).animate(); break; } } }; XFormsControl.createAttribute = function (xnHtmlNode, clAttribute) { for (var strKey in clAttribute.m_htCollection) { if (strKey == "id") { xnHtmlNode.setAttribute("id", "HE_" + clAttribute.item("id")); } else if (strKey == "disabled") { continue; } else if (strKey == "clsid") { xnHtmlNode.setAttribute("CLASSID", "clsid:" + clAttribute.item("clsid")); } else { if (STYLE_LIST[strKey]) { HtmlLib.setStyle(xnHtmlNode, strKey, clAttribute.item(strKey)); } else { xnHtmlNode.setAttribute(strKey, clAttribute.item(strKey)); } } } xnHtmlNode.style.position = "absolute"; xnHtmlNode = XFormsElement.createAttribute(xnHtmlNode, clAttribute); return xnHtmlNode; };