XFormsIViewer.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. XFormsIViewer.prototype = new XFormsControl;
  2. function XFormsIViewer (strParentId, strAlert, strHelp, strHint, strAccesskey, strBind,
  3. strClass, bDisabled, strId, nNavindex, strRef, strSrc, strStyle, strTag, strVisibility, strUserDefineAttrib)
  4. {
  5. if (!strId)
  6. {
  7. return;
  8. }
  9. XFormsBindableControl.call(this, strParentId, strAlert, strHelp, strHint, strAccesskey, strBind,
  10. strClass, bDisabled, strId, nNavindex, strRef, strStyle, strTag, strVisibility, strUserDefineAttrib);
  11. /**
  12. * Attribute
  13. */
  14. this.attribute["src"] = strSrc;
  15. /**
  16. * Property
  17. */
  18. this.selected;
  19. this.src = strSrc;
  20. // 자식화면 제어를 위해 필요한 Property
  21. this.body;
  22. this.document;
  23. this.window;
  24. };
  25. XFormsIViewer.prototype.init = function ()
  26. {
  27. XFormsControl.prototype.init.call(this);
  28. this.status = true;
  29. this.setSrc(this.src);
  30. this.resizeControl();
  31. var strId = this.id;
  32. if (this.m_heControl.attachEvent)
  33. {
  34. this.m_heControl.attachEvent("onload", function() {XFormsIViewer.setIviewerDoc(strId);});
  35. }
  36. else
  37. {
  38. this.m_heControl.addEventListener("load", function() {XFormsIViewer.setIviewerDoc(strId);}, false);
  39. }
  40. };
  41. XFormsIViewer.prototype.applyDefaultStyle = function ()
  42. {
  43. XFormsControl.prototype.applyDefaultStyle.call(this);
  44. if (!this.attribute["border-style"] && !this.attribute["border-width"])
  45. {
  46. this.m_heControl.style.borderWidth = "";
  47. }
  48. };
  49. XFormsIViewer.prototype.setAttribute = function (strAttribute, strValue)
  50. {
  51. switch (strAttribute) // 우겸 스타일 객체 수정한 뒤 작업해야 함..
  52. {
  53. case "src":
  54. {
  55. this.setSrc(strValue);
  56. break;
  57. }
  58. case "visibility" :
  59. {
  60. if ("visible" == strValue)
  61. {
  62. this.visible = true;
  63. this.attribute["visibility"] = strValue;
  64. this.m_heControl.style.visibility = "visible";
  65. this.m_heControl.style.display = "block";
  66. }
  67. else if ("hidden" == strValue)
  68. {
  69. this.visible = false;
  70. this.attribute["visibility"] = strValue;
  71. this.m_heControl.style.visibility = "hidden";
  72. this.m_heControl.style.display = "none";
  73. }
  74. break;
  75. }
  76. default:
  77. {
  78. XFormsControl.prototype.setAttribute.call(this, strAttribute, strValue);
  79. break;
  80. }
  81. }
  82. };
  83. XFormsIViewer.prototype.setSrc = function (strSrc)
  84. {
  85. this.src = strSrc;
  86. this.attribute["src"] = strSrc;
  87. // 확장자를 .xrw에서 .html로 변환
  88. this.m_heControl.src = strSrc.changeExtension("xrw", "html");
  89. };
  90. XFormsIViewer.prototype.setVisible = function (bVisible)
  91. {
  92. // Property 적용
  93. this.visible = bVisible;
  94. if (bVisible)
  95. {
  96. // Attribute 적용
  97. this.attribute["visibility"] = "visible";
  98. // HTML 적용
  99. this.m_heControl.style.visibility = "visible";
  100. this.m_heControl.style.display = "block";
  101. }
  102. else
  103. {
  104. // Attribute 적용
  105. this.attribute["visibility"] = "hidden";
  106. // HTML 적용
  107. this.m_heControl.style.visibility = "hidden";
  108. this.m_heControl.style.display = "none";
  109. }
  110. };
  111. XFormsIViewer.create = function (strParentId, clAttribute, strStyle)
  112. {
  113. // 메인노드 생성
  114. var xnIViewer = XFormsIViewer.createMainNode(clAttribute);
  115. var xnParent = document.getElementById("HE_"+strParentId);
  116. xnParent.appendChild(xnIViewer);
  117. // 하위노드 생성
  118. xnIViewer = XFormsIViewer.createSubNodes(xnIViewer, clAttribute);
  119. // object 생성
  120. return XFormsIViewer.createObject(strParentId, xnIViewer, clAttribute, strStyle);
  121. };
  122. XFormsIViewer.createMainNode = function (clAttribute)
  123. {
  124. var xnIViewer = document.createElement("iframe");
  125. xnIViewer = XFormsIViewer.createAttribute(xnIViewer, clAttribute);
  126. xnIViewer.frameBorder = "0";
  127. return xnIViewer;
  128. };
  129. XFormsIViewer.createSubNodes = function (xnIViewer, clAttribute)
  130. {
  131. return xnIViewer;
  132. };
  133. XFormsIViewer.createObject = function (strParentId, xnIViewer, clAttribute, strStyle)
  134. {
  135. // src 확장자 html로 바뀐거 다시 xrw로 바꿔치기
  136. if (clAttribute.exists("src"))
  137. {
  138. var strFileName = clAttribute.item("src");
  139. var nPosition = strFileName.lastIndexOf('.');
  140. if (nPosition > 0 && nPosition < strFileName.length && strFileName.substring(nPosition + 1) == "html")
  141. {
  142. strFileName = strFileName.substring(0, nPosition);
  143. strFileName += ".xrw";
  144. }
  145. clAttribute.add("src", strFileName);
  146. }
  147. var bDisabled = false;
  148. var strId = "";
  149. var strSrc = "";
  150. var strVisibility = "visible";
  151. var strUserDefineAttrib = "";
  152. for (var i=0; i<clAttribute.count(); i++)
  153. {
  154. var strAttributeName = clAttribute.keys()[i];
  155. switch (strAttributeName)
  156. {
  157. case "disabled" :
  158. {
  159. if ("true" == clAttribute.item(strAttributeName))
  160. {
  161. bDisabled = true;
  162. }
  163. break;
  164. }
  165. case "id" :
  166. {
  167. strId = clAttribute.item(strAttributeName);
  168. break;
  169. }
  170. case "src" :
  171. {
  172. strSrc = clAttribute.item(strAttributeName);
  173. break;
  174. }
  175. case "visibility" :
  176. {
  177. strVisibility = clAttribute.item(strAttributeName);
  178. break;
  179. }
  180. default :
  181. {
  182. if (!STYLE_LIST[strAttributeName])
  183. {
  184. strUserDefineAttrib += strAttributeName + ":" + clAttribute.item(strAttributeName) + "; ";
  185. }
  186. break;
  187. }
  188. }
  189. }
  190. var objIViewer = new XFormsIViewer (strParentId, "", "", "", "", "", "", bDisabled, strId, -1, "", strSrc, strStyle, "xforms:iviewer", strVisibility, strUserDefineAttrib);
  191. return objIViewer;
  192. };
  193. XFormsIViewer.createAttribute = function (xnHtmlNode, clAttribute)
  194. {
  195. // src 확장자 xrw에서 html로 바꿔치기
  196. if (clAttribute.exists("src"))
  197. {
  198. var strFileName = clAttribute.item("src");
  199. var nPosition = strFileName.lastIndexOf('.');
  200. if (nPosition > 0 && nPosition < strFileName.length && strFileName.substring(nPosition + 1) == "xrw")
  201. {
  202. strFileName = strFileName.substring(0, nPosition);
  203. strFileName += ".html";
  204. }
  205. clAttribute.add("src", strFileName);
  206. }
  207. xnHtmlNode = XFormsControl.createAttribute(xnHtmlNode, clAttribute);
  208. return xnHtmlNode;
  209. };
  210. XFormsIViewer.setIviewerDoc = function (strId)
  211. {
  212. var objIviewer = document.controls.item(strId);
  213. objIviewer.body = objIviewer.m_heControl.contentWindow.body;
  214. objIviewer.document = objIviewer.m_heControl.contentWindow.document;
  215. objIviewer.model = objIviewer.m_heControl.contentWindow.model;
  216. objIviewer.window = objIviewer.m_heControl.contentWindow;
  217. objIviewer.window.type = "iviewer";
  218. };