CSS_NULL = 0; CSS_FIRST = CSS_NULL; CSS_USER = 1; CSS_UNIVERSAL = 2; CSS_TYPE = 3; CSS_DYNAMIC_PSEUDO = 4; CSS_ID = 5; CSS_DESCENDANT = 6; CSS_CHILD = 7; CSS_GROUP = 8; AS_NULL = 0; AS_EXIST = 1; AS_EQUAL = 2; HAS_NS = 0x00000001; HAS_ID = 0x00000010; HAS_CLASS = 0x00000100; var g_childList = new Array(); var g_objStyleSheet = new XFormsStyleSheet(); /** * Stylesheet * * @author 김지환 */ function XFormsStyleSheet () { this.m_arCSSNode = new Array(); }; XFormsStyleSheet.prototype.push = function (objCSSNode) { this.m_arCSSNode.push(objCSSNode); }; XFormsStyleSheet.prototype.getNode = function (nIndex) { return this.m_arCSSNode[nIndex]; }; XFormsStyleSheet.prototype.getLength = function () { return this.m_arCSSNode.length; }; XFormsStyleSheet.prototype.applyCSS = function (objElement) { var htCssData = null; var strID = objElement.getId(); var nLength = this.getLength(); for (var i=0; i=0; i--) { var objCSSNode = g_childList[i]; if (null == objCurrent) { g_objStyleSheet.push(objCSSNode); } else { objCurrent.setNext(objCSSNode); } objCurrent = objCSSNode; } g_childList.removeAll(); } }; /** * CSS 의 구문 */ function CSSNode (strName, nLink, strPseudo, htAttribute, bHasAs, nAsOperator, strAsName, strAsValue) { if (null == strName) { return; } // 구문의 이름 id, type, class, universial의 값이 될 수 있다. this.m_strName = strName; // CSSNode 연결 타입 this.m_nLink = nLink; // 의사코드 이벤트 hover, down, focus, disable, fixed, data 등 this.m_strPseudo = strPseudo; // 스타일 데이터 this.m_htAttribute = htAttribute; // Attribute Selector 구문의 이름으로 매치가 되더라도 추가적으로 해당 엘리먼트의 어트리부트를 지정해서 해당하는 엘리먼트만 적용할때 쓰인다. this.m_bHasAs = bHasAs; this.m_nAsOperator = nAsOperator; this.m_strAsName = strAsName; this.m_strAsValue = strAsValue; // 같은 CSS 구문안에 위치한 다음 노드 (부모 노드에 대한 정보) this.m_objNext = null; }; CSSNode.prototype.getPseudo = function () { return this.m_strPseudo; }; CSSNode.prototype.getLink = function () { return this.m_nLink; }; CSSNode.prototype.getAttribute = function () { return this.m_htAttribute; }; CSSNode.prototype.getNext = function () { return this.m_objNext; }; CSSNode.prototype.setNext = function (objCSSNode) { this.m_objNext = objCSSNode; }; CSSNode.prototype.match = function (objElement) { if (!this.onMatch(objElement)) { return false; } // Attribute Selector if (this.m_bHasAs) { if (AS_EQUAL == this.m_nAsOperator) { var strAttributeValue = objElement.getAttribute(this.m_strAsName); if (this.m_strAsValue != strAttributeValue) { return false; } } else if (AS_EXIST == this.m_nAsOperator) { var strAttributeValue = objElement.getAttribute(this.m_strAsName); if (null == strAttributeValue) { return false; } } } return true; }; /** * CSS의 대상이 class 에 의해 적용되는 CSS 구문 */ CSSNodeUser.prototype = new CSSNode; function CSSNodeUser (strName, nLink, strPseudo, htAttribute, bHasAs, nAsOperator, strAsName, strAsValue) { if (null == strName) { return; } CSSNode.call(this, strName, nLink, strPseudo, htAttribute, bHasAs, nAsOperator, strAsName, strAsValue); }; CSSNodeUser.prototype.onMatch = function (objElement) { return (null != objElement.getClass && objElement.getClass() == this.m_strName); }; /** * CSS의 대상이 id 에 의해 적용되는 CSS 구문 */ CSSNodeID.prototype = new CSSNode; function CSSNodeID (strName, nLink, strPseudo, htAttribute, bHasAs, nAsOperator, strAsName, strAsValue) { if (null == strName) { return; } CSSNode.call(this, strName, nLink, strPseudo, htAttribute, bHasAs, nAsOperator, strAsName, strAsValue); }; CSSNodeID.prototype.onMatch = function (objElement) { var strId = objElement.getId(); if (CSS_CHILD == this.m_nLink || CSS_DESCENDANT == this.m_nLink) { var nIndex = strId.lastIndexOf("."); if (-1 < nIndex) { strId = strId.substr(nIndex + 1); } } return (strId == this.m_strName); }; /** * CSS의 대상이 type 에 의해 적용되는 CSS 구문 */ CSSNodeType.prototype = new CSSNode; function CSSNodeType (strName, nLink, strPseudo, htAttribute, bHasAs, nAsOperator, strAsName, strAsValue) { if (null == strName) { return; } this.m_dwFlag = 0; this.m_strClass = ""; this.m_strType = ""; this.m_strId = ""; // Class 와 함께인 Type var nIndex = strName.indexOf("."); if (-1 != nIndex) { this.m_strClass = strName.substr(nIndex + 1); this.m_dwFlag |= HAS_CLASS; strName = strName.substring(0, nIndex); } // ID 와 함께인 Type nIndex = strName.indexOf("#"); if (-1 != nIndex) { this.m_strId = strName.substr(nIndex + 1); this.m_dwFlag |= HAS_ID; strName = strName.substring(0, nIndex); } // namespace this.m_dwFlag |= (strName.indexOf("|") != -1 ? HAS_NS : 0); strName.replace("|", ":"); this.m_strType = strName; CSSNode.call(this, strName, nLink, strPseudo, htAttribute, bHasAs, nAsOperator, strAsName, strAsValue); }; CSSNodeType.prototype.onMatch = function (objElement) { if (this.m_dwFlag & HAS_ID) { var strId = objElement.getId(); if (CSS_CHILD == this.getLink()) { var nIndex = strId.lastIndexOf("."); if (-1 < nIndex) { strId = strId.substr(nIndex + 1); } } return (strId == this.m_strName); } if (this.m_dwFlag & HAS_CLASS) { if ("html" != objElement.id) { var strClass = objElement.getClass(); if (this.m_strClass != strClass) { return false; } } else { return false; } } return (this.m_dwFlag & HAS_NS) ? objElement.getTag() == this.m_strType : objElement.getLocalTag() == this.m_strType; }; /** * CSS의 대상이 전체인 CSS 구문 (*) */ CSSNodeUniversal.prototype = new CSSNodeType; function CSSNodeUniversal (strName, nLink, strPseudo, htAttribute, bHasAs, nAsOperator, strAsName, strAsValue) { if (null == strName) { return; } CSSNodeType.call(this, strName, nLink, strPseudo, htAttribute, bHasAs, nAsOperator, strAsName, strAsValue); }; CSSNodeUniversal.prototype.onMatch = function (objElement) { if (this.m_dwFlag & HAS_ID) { if (this.m_strId != objElement.getId()) { return false; } } if (this.m_dwFlag & HAS_CLASS) { if (this.m_strClass != objElement.getClass()) { return false; } } return true; };