HtmlLib.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. function HtmlLib ()
  2. {
  3. };
  4. /**
  5. * Xml Node style 값을 얻어 온다.
  6. */
  7. HtmlLib.getStyle = function (xnHtmlNode, strStyleName)
  8. {
  9. if (null != xnHtmlNode && null != strStyleName && 0 < strStyleName.length)
  10. {
  11. switch (strStyleName)
  12. {
  13. case "left" : return xnHtmlNode.style.left;
  14. case "right" : return xnHtmlNode.style.right;
  15. case "top" : return xnHtmlNode.style.top;
  16. case "bottom" : return xnHtmlNode.style.bottom;
  17. case "width" : return xnHtmlNode.style.width;
  18. case "height" : return xnHtmlNode.style.height;
  19. case "font-family" : return xnHtmlNode.style.fontFamily;
  20. case "font-size" : return xnHtmlNode.style.fontSize;
  21. case "font-weight" : return xnHtmlNode.style.fontWeight;
  22. case "font-style" : return xnHtmlNode.style.fontStyle;
  23. case "text-decoration" : return xnHtmlNode.style.textDecoration;
  24. case "color" : return xnHtmlNode.style.color;
  25. case "text-align" : return xnHtmlNode.style.textAlign;
  26. case "vertical-align" : return xnHtmlNode.style.verticalAlign;
  27. case "word-wrap" : return xnHtmlNode.style.wordWrap;
  28. case "line-spacing" : return xnHtmlNode.style.lineSpacing;
  29. case "letter-spacing" : return xnHtmlNode.style.letterSpacing;
  30. case "padding" : return xnHtmlNode.style.padding;
  31. case "padding-left" : return xnHtmlNode.style.paddingLeft;
  32. case "padding-top" : return xnHtmlNode.style.paddingTop;
  33. case "padding-right" : return xnHtmlNode.style.paddingRight;
  34. case "padding-bottom" : return xnHtmlNode.style.paddingBottom;
  35. case "background-color" : return xnHtmlNode.style.backgroundColor;
  36. case "background-image" : return xnHtmlNode.style.backgroundImage;
  37. case "background-repeat" : return xnHtmlNode.style.backgroundRepeat;
  38. case "background-position" :
  39. {
  40. var strBackgroundPosition = xnHtmlNode.style.backgroundPosition;
  41. if ("left center" == strBackgroundPosition)
  42. {
  43. strBackgroundPosition = "center left";
  44. }
  45. else if ("right center" == strBackgroundPosition)
  46. {
  47. strBackgroundPosition = "center right";
  48. }
  49. return strBackgroundPosition;
  50. }
  51. case "border-color" : return xnHtmlNode.style.borderColor;
  52. case "border-left-color" : return xnHtmlNode.style.borderLeftColor;
  53. case "border-top-color" : return xnHtmlNode.style.borderTopColor;
  54. case "border-right-color" : return xnHtmlNode.style.borderRightColor;
  55. case "border-bottom-color" : return xnHtmlNode.style.borderBottomColor;
  56. case "border-width" : return xnHtmlNode.style.borderWidth;
  57. case "border-left-width" : return xnHtmlNode.style.borderLeftWidth;
  58. case "border-top-width" : return xnHtmlNode.style.borderTopWidth;
  59. case "border-right-width" : return xnHtmlNode.style.borderRightWidth;
  60. case "border-bottom-width" : return xnHtmlNode.style.borderBottomWidth;
  61. case "border-style" : return xnHtmlNode.style.borderStyle;
  62. case "border-left-style" : return xnHtmlNode.style.borderLeftStyle;
  63. case "border-top-style" : return xnHtmlNode.style.borderTopStyle;
  64. case "border-right-style" : return xnHtmlNode.style.borderRightStyle;
  65. case "border-bottom-style" : return xnHtmlNode.style.borderBottomStyle;
  66. case "margin" : return xnHtmlNode.style.margin;
  67. case "margin-left" : return xnHtmlNode.style.marginLeft;
  68. case "margin-top" : return xnHtmlNode.style.marginTop;
  69. case "margin-right" : return xnHtmlNode.style.marginRight;
  70. case "margin-bottom" : return xnHtmlNode.style.marginBottom;
  71. case "opacity" : return xnHtmlNode.style.opacity * 100; // Designer에서 입력한 값으로 변환후 return
  72. case "overflow" : return xnHtmlNode.style.oveflow;
  73. case "clip" : return;
  74. case "gradient" : return;
  75. case "cursor" : return xnHtmlNode.style.cursor;
  76. case "focus-rect" : return;
  77. case "unloadmark" : return;
  78. }
  79. }
  80. return null;
  81. };
  82. /**
  83. * Xml Node style 를 설정한다
  84. *
  85. * Node.setStyle(Node, "Style이름", "값")
  86. */
  87. HtmlLib.setStyle = function (xnHtmlNode, strStyleName, strStyleValue)
  88. {
  89. try
  90. {
  91. if (null != xnHtmlNode && null != strStyleName && 0 < strStyleName.length && null != strStyleValue)
  92. {
  93. switch (strStyleName)
  94. {
  95. case "left" : xnHtmlNode.style.left = isFinite(strStyleValue) ? strStyleValue + "px" : strStyleValue; break;
  96. case "right" :
  97. {
  98. if (-1 != strStyleValue.indexOf("%"))
  99. {
  100. strStyleValue = (100 - parseFloat(strStyleValue)) + "%";
  101. xnHtmlNode.style.right = strStyleValue;
  102. break;
  103. }
  104. xnHtmlNode.style.right = isFinite(strStyleValue) ? strStyleValue + "px" : strStyleValue; break;
  105. }
  106. case "top" : xnHtmlNode.style.top = isFinite(strStyleValue) ? strStyleValue + "px" : strStyleValue; break;
  107. case "bottom" :
  108. {
  109. if (-1 != strStyleValue.indexOf("%"))
  110. {
  111. strStyleValue = (100 - parseFloat(strStyleValue)) + "%";
  112. xnHtmlNode.style.bottom = strStyleValue;
  113. break;
  114. }
  115. xnHtmlNode.style.bottom = isFinite(strStyleValue) ? strStyleValue + "px" : strStyleValue; break;
  116. }
  117. case "width" :
  118. {
  119. strStyleValue = isFinite(strStyleValue) ? strStyleValue + "px" : strStyleValue;
  120. xnHtmlNode.style.width = strStyleValue;
  121. if (-1 == strStyleValue.indexOf("%") && isFinite(parseInt(strStyleValue)))
  122. {
  123. var nBlockWidth = xnHtmlNode.offsetWidth - parseInt(strStyleValue);
  124. if (0 < nBlockWidth)
  125. {
  126. xnHtmlNode.style.width = (parseInt(strStyleValue) - nBlockWidth) + "px";
  127. }
  128. nBlockWidth = null; //메모리 환원
  129. }
  130. break;
  131. }
  132. case "height" :
  133. {
  134. if (strStyleValue.toString().substring(0,1) == "-")
  135. {
  136. strStyleValue = "0";
  137. }
  138. strStyleValue = isFinite(strStyleValue) ? strStyleValue + "px" : strStyleValue;
  139. xnHtmlNode.style.height = strStyleValue;
  140. if (-1 == strStyleValue.indexOf("%") && isFinite(parseInt(strStyleValue)))
  141. {
  142. var nBlockHeight = xnHtmlNode.offsetHeight - parseInt(strStyleValue);
  143. if (0 < nBlockHeight)
  144. {
  145. xnHtmlNode.style.height = (parseInt(strStyleValue) - nBlockHeight) + "px";
  146. }
  147. nBlockHeight = null; //메모리 환원
  148. }
  149. break;
  150. }
  151. case "font-family" : xnHtmlNode.style.fontFamily = strStyleValue; break;
  152. case "font-size" :
  153. {
  154. strStyleValue = isFinite(strStyleValue) ? strStyleValue + "pt" : strStyleValue;
  155. xnHtmlNode.style.fontSize = strStyleValue;
  156. break;
  157. }
  158. case "font-weight" : xnHtmlNode.style.fontWeight = strStyleValue; break;
  159. case "font-style" : xnHtmlNode.style.fontStyle = strStyleValue; break;
  160. case "text-decoration" : xnHtmlNode.style.textDecoration = strStyleValue; break;
  161. case "color" :
  162. {
  163. strStyleValue = "" == strStyleValue ? "#000000" : strStyleValue;
  164. xnHtmlNode.style.color = strStyleValue; break;
  165. }
  166. case "text-align" : xnHtmlNode.style.textAlign = strStyleValue; break;
  167. case "vertical-align" : xnHtmlNode.style.verticalAlign = strStyleValue; break;
  168. case "word-wrap" : xnHtmlNode.style.wordWrap = strStyleValue; break;
  169. case "line-spacing" : xnHtmlNode.style.lineSpacing = strStyleValue; break;
  170. case "line-height" : xnHtmlNode.style.lineHeight = strStyleValue; break;
  171. case "letter-spacing" : xnHtmlNode.style.letterSpacing = strStyleValue; break;
  172. case "padding" : xnHtmlNode.style.padding = strStyleValue; break;
  173. case "padding-left" : xnHtmlNode.style.paddingLeft = strStyleValue; break;
  174. case "padding-top" : xnHtmlNode.style.paddingTop = strStyleValue; break;
  175. case "padding-right" : xnHtmlNode.style.paddingRight = strStyleValue; break;
  176. case "padding-bottom" : xnHtmlNode.style.paddingBottom = strStyleValue; break;
  177. case "background-color" : xnHtmlNode.style.backgroundColor = strStyleValue; break;
  178. case "background-image" :
  179. {
  180. if (strStyleValue.trim().substring(0,4) != "url(")
  181. {
  182. strStyleValue = "url(" + strStyleValue + ")";
  183. }
  184. xnHtmlNode.style.backgroundImage = strStyleValue; break;
  185. }
  186. case "background-repeat" : xnHtmlNode.style.backgroundRepeat = strStyleValue; break;
  187. case "background-position" :
  188. {
  189. if ("" != strStyleValue)
  190. {
  191. var strBackgroundPositionX = "";
  192. if (-1 != strStyleValue.indexOf("left"))
  193. {
  194. strBackgroundPositionX = "left";
  195. }
  196. else if (-1 != strStyleValue.indexOf("right"))
  197. {
  198. strBackgroundPositionX = "right";
  199. }
  200. var strBackgroundPositionY = "";
  201. if (-1 != strStyleValue.indexOf("top"))
  202. {
  203. strBackgroundPositionY = "top";
  204. }
  205. else if (-1 != strStyleValue.indexOf("bottom"))
  206. {
  207. strBackgroundPositionY = "bottom";
  208. }
  209. if (-1 != strStyleValue.indexOf("center"))
  210. {
  211. if ("center" == strStyleValue)
  212. {
  213. if ("" == strBackgroundPositionX)
  214. {
  215. strBackgroundPositionX = "center";
  216. }
  217. if ("" == strBackgroundPositionY)
  218. {
  219. strBackgroundPositionY = "center";
  220. }
  221. }
  222. }
  223. if ("" != strBackgroundPositionX && "" != strBackgroundPositionY)
  224. {
  225. strStyleValue = strBackgroundPositionX + " " + strBackgroundPositionY;
  226. }
  227. else if ("" != strBackgroundPositionX && "" == strBackgroundPositionY)
  228. {
  229. strStyleValue = strBackgroundPositionX;
  230. }
  231. else if ("" == strBackgroundPositionX && "" != strBackgroundPositionY)
  232. {
  233. strStyleValue = strBackgroundPositionY;
  234. }
  235. else if ("" == strBackgroundPositionX && "" == strBackgroundPositionY)
  236. {
  237. strStyleValue = "left center";
  238. }
  239. }
  240. xnHtmlNode.style.backgroundPosition = strStyleValue; break;
  241. }
  242. case "border-color" : xnHtmlNode.style.borderColor = strStyleValue; break;
  243. case "border-left-color" : xnHtmlNode.style.borderLeftColor = strStyleValue; break;
  244. case "border-top-color" : xnHtmlNode.style.borderTopColor = strStyleValue; break;
  245. case "border-right-color" : xnHtmlNode.style.borderRightColor = strStyleValue; break;
  246. case "border-bottom-color" : xnHtmlNode.style.borderBottomColor = strStyleValue; break;
  247. case "border-width" : xnHtmlNode.style.borderWidth = strStyleValue; break;
  248. case "border-left-width" : xnHtmlNode.style.borderLeftWidth = strStyleValue; break;
  249. case "border-top-width" : xnHtmlNode.style.borderTopWidth = strStyleValue; break;
  250. case "border-right-width" : xnHtmlNode.style.borderRightWidth = strStyleValue; break;
  251. case "border-bottom-width" : xnHtmlNode.style.borderBottomWidth = strStyleValue; break;
  252. case "border-style" : xnHtmlNode.style.borderStyle = strStyleValue; break;
  253. case "border-left-style" : xnHtmlNode.style.borderLeftStyle = strStyleValue; break;
  254. case "border-top-style" : xnHtmlNode.style.borderTopStyle = strStyleValue; break;
  255. case "border-right-style" : xnHtmlNode.style.borderRightStyle = strStyleValue; break;
  256. case "border-bottom-style" : xnHtmlNode.style.borderBottomStyle = strStyleValue; break;
  257. case "margin" : xnHtmlNode.style.margin = strStyleValue; break;
  258. case "margin-left" : xnHtmlNode.style.marginLeft = strStyleValue; break;
  259. case "margin-top" : xnHtmlNode.style.marginTop = strStyleValue; break;
  260. case "margin-right" : xnHtmlNode.style.marginRight = strStyleValue; break;
  261. case "margin-bottom" : xnHtmlNode.style.marginBottom = strStyleValue; break;
  262. case "opacity" :
  263. {
  264. if (is_ie)
  265. {
  266. xnHtmlNode.style.filter = "alpha(opacity=" + strStyleValue + ")";
  267. }
  268. else
  269. {
  270. if (1 < strStyleValue)
  271. {
  272. var fOpacity = parseFloat(strStyleValue)/100;
  273. strStyleValue = fOpacity;
  274. }
  275. xnHtmlNode.style.opacity = strStyleValue;
  276. }
  277. break;
  278. }
  279. case "overflow" : xnHtmlNode.style.overflow = strStyleValue; break;
  280. case "clip" : break;
  281. case "gradient" : break;
  282. case "cursor" :
  283. {
  284. if ("arrow" == strStyleValue)
  285. {
  286. strStyleValue = "default";
  287. }
  288. else if ("drag-move" == strStyleValue)
  289. {
  290. strStyleValue = "pointer";
  291. }
  292. else if ("h-resize" == strStyleValue)
  293. {
  294. strStyleValue = "col-resize";
  295. }
  296. else if ("v-resize" == strStyleValue)
  297. {
  298. strStyleValue = "row-resize";
  299. }
  300. else if ("no" == strStyleValue)
  301. {
  302. strStyleValue = "no-drop";
  303. }
  304. else if ("hand" == strStyleValue)
  305. {
  306. if (is_ie) strStyleValue = "hand";
  307. else strStyleValue = "pointer";
  308. }
  309. else
  310. {
  311. strStyleValue = "default";
  312. }
  313. xnHtmlNode.style.cursor = strStyleValue; break;
  314. }
  315. case "focus-rect" : break;
  316. case "unloadmark" : break;
  317. }
  318. }
  319. }
  320. catch (exception)
  321. {
  322. // alert(exception.message);
  323. }
  324. };
  325. HtmlLib.setStyleFront = function (xnHtmlNode, strStyleName, strStyleValue)
  326. {
  327. if (xnHtmlNode)
  328. {
  329. if ("margin" == strStyleName)
  330. {
  331. var strLeft = xnHtmlNode.style.marginLeft;
  332. var strTop = xnHtmlNode.style.marginTop;
  333. var strRight = xnHtmlNode.style.marginRight;
  334. var strBottom = xnHtmlNode.style.marginBottom;
  335. HtmlLib.setStyle(xnHtmlNode, strStyleName, strStyleValue);
  336. if ("" != strLeft)
  337. {
  338. xnHtmlNode.style.marginLeft = strLeft;
  339. }
  340. if ("" != strTop)
  341. {
  342. xnHtmlNode.style.marginTop = strTop;
  343. }
  344. if ("" != strRight)
  345. {
  346. xnHtmlNode.style.marginRight = strRight;
  347. }
  348. if ("" != strBottom)
  349. {
  350. xnHtmlNode.style.marginBottom = strBottom;
  351. }
  352. }
  353. else if ("border-width" == strStyleName)
  354. {
  355. var strLeftWidth = xnHtmlNode.style.borderLeftWidth;
  356. var strTopWidth = xnHtmlNode.style.borderTopWidth;
  357. var strRightWidth = xnHtmlNode.style.borderRightWidth;
  358. var strBottomWidth = xnHtmlNode.style.borderBottomWidth;
  359. HtmlLib.setStyle(xnHtmlNode, strStyleName, strStyleValue);
  360. if ("" != strLeftWidth)
  361. {
  362. xnHtmlNode.style.borderLeftWidth = strLeftWidth;
  363. }
  364. if ("" != strTopWidth)
  365. {
  366. xnHtmlNode.style.borderTopWidth = strTopWidth;
  367. }
  368. if ("" != strRightWidth)
  369. {
  370. xnHtmlNode.style.borderRightWidth = strRightWidth;
  371. }
  372. if ("" != strBottomWidth)
  373. {
  374. xnHtmlNode.style.borderBottomWidth = strBottomWidth;
  375. }
  376. }
  377. else if ("border-style" == strStyleName)
  378. {
  379. var strLeftStyle = xnHtmlNode.style.borderLeftStyle;
  380. var strTopStyle = xnHtmlNode.style.borderTopStyle;
  381. var strRightStyle = xnHtmlNode.style.borderRightStyle;
  382. var strBottomStyle = xnHtmlNode.style.borderBottomStyle;
  383. HtmlLib.setStyle(xnHtmlNode, strStyleName, strStyleValue);
  384. if ("" != strLeftStyle)
  385. {
  386. xnHtmlNode.style.borderLeftStyle = strLeftStyle;
  387. }
  388. if ("" != strTopStyle)
  389. {
  390. xnHtmlNode.style.borderTopStyle = strTopStyle;
  391. }
  392. if ("" != strRightStyle)
  393. {
  394. xnHtmlNode.style.borderRightStyle = strRightStyle;
  395. }
  396. if ("" != strBottomStyle)
  397. {
  398. xnHtmlNode.style.borderBottomStyle = strBottomStyle;
  399. }
  400. }
  401. else if ("border-color" == strStyleName)
  402. {
  403. var strLeftColor = xnHtmlNode.style.borderLeftColor;
  404. var strTopColor = xnHtmlNode.style.borderTopColor;
  405. var strRightColor = xnHtmlNode.style.borderRightColor;
  406. var strBottomColor = xnHtmlNode.style.borderBottomColor;
  407. HtmlLib.setStyle(xnHtmlNode, strStyleName, strStyleValue);
  408. if ("" != strLeftColor)
  409. {
  410. xnHtmlNode.style.borderLeftColor = strLeftColor;
  411. }
  412. if ("" != strTopColor)
  413. {
  414. xnHtmlNode.style.borderTopColor = strTopColor;
  415. }
  416. if ("" != strRightColor)
  417. {
  418. xnHtmlNode.style.borderRightColor = strRightColor;
  419. }
  420. if ("" != strBottomColor)
  421. {
  422. xnHtmlNode.style.borderBottomColor = strBottomColor;
  423. }
  424. }
  425. else if ("padding" == strStyleName)
  426. {
  427. var strLeft = xnHtmlNode.style.paddingLeft;
  428. var strTop = xnHtmlNode.style.paddingTop;
  429. var strRight = xnHtmlNode.style.paddingRight;
  430. var strBottom = xnHtmlNode.style.paddingBottom;
  431. HtmlLib.setStyle(xnHtmlNode, strStyleName, strStyleValue);
  432. if ("" != strLeft)
  433. {
  434. xnHtmlNode.style.paddingLeft = strLeft;
  435. }
  436. if ("" != strTop)
  437. {
  438. xnHtmlNode.style.paddingTop = strTop;
  439. }
  440. if ("" != strRight)
  441. {
  442. xnHtmlNode.style.paddingRight = strRight;
  443. }
  444. if ("" != strBottom)
  445. {
  446. xnHtmlNode.style.paddingBottom = strBottom;
  447. }
  448. }
  449. }
  450. };