CSSManager.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. /****************************************************************
  2. ** Licensed Materials - Property of IBM
  3. **
  4. ** BI and PM: qs
  5. **
  6. ** (C) Copyright IBM Corp. 2001, 2015
  7. **
  8. ** US Government Users Restricted Rights - Use, duplication or
  9. ** disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *****************************************************************/
  11. // Copyright (C) 2008 Cognos ULC, an IBM Company. All Rights Reserved.
  12. // Cognos and the Cognos logo are trademarks of Cognos ULC (formerly Cognos Incorporated) in the United States and/or other countries. IBM and the IBM logo are trademarks of International Business Machines Corporation in the United States, or other countries, or both. Other company, product, or service names may be trademarks or service marks of others.
  13. function getStylesFromAllSelectedCols()
  14. {
  15. var currentStyle = new Array();
  16. var selectionController = null;
  17. if (typeof goApplicationManager == "object")
  18. {
  19. selectionController = goApplicationManager.getSelectionController();
  20. }
  21. else if (typeof goDialogManager == "object")
  22. {
  23. selectionController = goDialogManager.getSelectionController();
  24. }
  25. else
  26. {
  27. return currentStyle;
  28. }
  29. var selections = selectionController.getSelections();
  30. var cf = getConfigFrame();
  31. if (selections.length)
  32. {
  33. var queryIds = new Array();
  34. var types = new Array();
  35. var i;
  36. for (i = 0; i < selections.length; i++)
  37. {
  38. queryIds[queryIds.length] = selections[i].getColumnName();
  39. var cellRef = selections[i].getCellRef();
  40. var oColSpecialProperties = cf.getColSpecialPropertiesFromSelectionObject(selections[i]);
  41. var sForcedType = "";
  42. if (oColSpecialProperties.forcedType)
  43. {
  44. sForcedType = oColSpecialProperties.forcedType;
  45. }
  46. if (cellRef !== null)
  47. {
  48. types[types.length] = (sForcedType == "" ? cf.getType(cellRef.getAttribute("qsc")) : sForcedType);
  49. }
  50. else
  51. {
  52. types[types.length] = null;
  53. }
  54. }
  55. if (types.length == queryIds.length)
  56. {
  57. if (typeof cf !== "undefined")
  58. {
  59. var MQ = cf.goApplicationManager.getMiniQueryManager();
  60. var columns = MQ.getElementsByTagName("Column");
  61. for (var j = 0; j < queryIds.length; j++)
  62. {
  63. var column = null;
  64. for (i = 0; i < columns.length; i++)
  65. {
  66. var sId = columns[i].getAttribute("id");
  67. if (sId && sId == queryIds[j])
  68. {
  69. column = columns[i];
  70. break;
  71. }
  72. }
  73. if (column !== null && types[j] !== null)
  74. {
  75. var styleNodes = column.getElementsByTagName(types[j]);
  76. if (styleNodes !== null)
  77. {
  78. for (var k = 0; k < styleNodes.length; k++)
  79. {
  80. currentStyle[currentStyle.length] = styleNodes[k].getAttribute("style").replace(/&apos;/gi, "'");
  81. }
  82. }
  83. }
  84. }
  85. }
  86. }
  87. }
  88. return currentStyle;
  89. };
  90. function getStylesFromAllSelectedReportElements()
  91. {
  92. var cf = getConfigFrame();
  93. var currentStyle = new Array();
  94. var selectionController = null;
  95. try
  96. {
  97. selectionController = getReportFrame().g_reportSelectionController;
  98. }
  99. catch (e)
  100. {
  101. return currentStyle;
  102. }
  103. var selections = selectionController.getSelections();
  104. if (selections.length)
  105. {
  106. var styleTypes = new Array();
  107. var i;
  108. for (i = 0; i < selections.length; i++)
  109. {
  110. styleTypes[styleTypes.length] = selections[i].getType();
  111. }
  112. if (typeof cf != "undefined")
  113. {
  114. var MQ = cf.goApplicationManager.getMiniQueryManager();
  115. var titleArea = MQ.getElementsByTagName("TitleArea");
  116. if (titleArea !== null && titleArea.length)
  117. {
  118. for (i = 0; i < styleTypes.length; i++)
  119. {
  120. var styleList = titleArea[0].getElementsByTagName(styleTypes[i]);
  121. if (styleList !== null && styleList.length)
  122. {
  123. currentStyle[currentStyle.length] = styleList[0].getAttribute("style").replace(/&apos;/gi, "'");
  124. }
  125. }
  126. }
  127. }
  128. }
  129. return currentStyle;
  130. };
  131. function mergeStyles(stylesArray, returnAsArray)
  132. {
  133. var commonStyles = new Array();
  134. if (stylesArray.length === 0)
  135. {
  136. if (typeof returnAsArray != "undefined" && returnAsArray === true)
  137. {
  138. return commonStyles;
  139. }
  140. return "";
  141. }
  142. commonStyles[0] = getCSSValue(stylesArray[0], 'font-weight');
  143. commonStyles[1] = getCSSValue(stylesArray[0], 'font-style');
  144. commonStyles[2] = getCSSValue(stylesArray[0], 'font-family');
  145. commonStyles[3] = getCSSValue(stylesArray[0], 'font-size');
  146. commonStyles[4] = getCSSValue(stylesArray[0], 'color');
  147. commonStyles[5] = getCSSValue(stylesArray[0], 'background-color');
  148. var textDecoration = getCSSValue(stylesArray[0], 'text-decoration');
  149. commonStyles[6] = textDecoration.toLowerCase().indexOf('underline') >= 0 ? true : -1;
  150. commonStyles[7] = textDecoration.toLowerCase().indexOf('overline') >= 0 ? true : -1;
  151. commonStyles[8] = textDecoration.toLowerCase().indexOf('line-through') >= 0 ? true : -1;
  152. commonStyles[9] = getCSSValue(stylesArray[0], 'text-align');
  153. commonStyles[10] = getCSSValue(stylesArray[0], 'vertical-align');
  154. var i;
  155. for (i = 1; i < stylesArray.length; i++)
  156. {
  157. if (commonStyles[0] !== -1 && commonStyles[0] != getCSSValue(stylesArray[i], 'font-weight'))
  158. {
  159. commonStyles[0] = -1;
  160. }
  161. if (commonStyles[1] !== -1 && commonStyles[1] != getCSSValue(stylesArray[i], 'font-style'))
  162. {
  163. commonStyles[1] = -1;
  164. }
  165. if (commonStyles[2] !== -1 && commonStyles[2] != getCSSValue(stylesArray[i], 'font-family'))
  166. {
  167. commonStyles[2] = -1;
  168. }
  169. if (commonStyles[3] !== -1 && commonStyles[3] != getCSSValue(stylesArray[i], 'font-size'))
  170. {
  171. commonStyles[3] = -1;
  172. }
  173. if (commonStyles[4] !== -1 && commonStyles[4] != getCSSValue(stylesArray[i], 'color'))
  174. {
  175. commonStyles[4] = -1;
  176. }
  177. if (commonStyles[5] !== -1 && commonStyles[5] != getCSSValue(stylesArray[i], 'background-color'))
  178. {
  179. commonStyles[5] = -1;
  180. }
  181. textDecoration = getCSSValue(stylesArray[i], 'text-decoration');
  182. if (commonStyles[6] !== -1)
  183. {
  184. commonStyles[6] = textDecoration.toLowerCase().indexOf('underline') >= 0 ? true : -1;
  185. }
  186. if (commonStyles[7] !== -1)
  187. {
  188. commonStyles[7] = textDecoration.toLowerCase().indexOf('overline') >= 0 ? true : -1;
  189. }
  190. if (commonStyles[8] !== -1)
  191. {
  192. commonStyles[8] = textDecoration.toLowerCase().indexOf('line-through') >= 0 ? true : -1;
  193. }
  194. if (commonStyles[9] !== -1 && commonStyles[9] != getCSSValue(stylesArray[i], 'text-align'))
  195. {
  196. commonStyles[9] = -1;
  197. }
  198. if (commonStyles[10] !== -1 && commonStyles[10] != getCSSValue(stylesArray[i], 'vertical-align'))
  199. {
  200. commonStyles[10] = -1;
  201. }
  202. }
  203. if (typeof returnAsArray != "undefined" && returnAsArray === true)
  204. {
  205. return commonStyles;
  206. }
  207. if (commonStyles[0] !== -1 && commonStyles[0] !== "")
  208. {
  209. commonStyles[0] = 'font-weight:' + commonStyles[0];
  210. }
  211. if (commonStyles[1] !== -1 && commonStyles[1] !== "")
  212. {
  213. commonStyles[1] = 'font-style:' + commonStyles[1];
  214. }
  215. if (commonStyles[2] !== -1 && commonStyles[2] !== "")
  216. {
  217. commonStyles[2] = 'font-family:' + commonStyles[2];
  218. }
  219. if (commonStyles[3] !== -1 && commonStyles[3] !== "")
  220. {
  221. commonStyles[3] = 'font-size:' + commonStyles[3];
  222. }
  223. if (commonStyles[4] !== -1 && commonStyles[4] !== "")
  224. {
  225. commonStyles[4] = 'color:' + commonStyles[4];
  226. }
  227. if (commonStyles[5] !== -1 && commonStyles[5] !== "")
  228. {
  229. commonStyles[5] = 'background-color:' + commonStyles[5];
  230. }
  231. textDecoration = "";
  232. if (commonStyles[6] !== -1 && commonStyles[6] !== "")
  233. {
  234. textDecoration = "underline ";
  235. }
  236. if (commonStyles[7] !== -1 && commonStyles[7] !== "")
  237. {
  238. textDecoration += "overline ";
  239. }
  240. if (commonStyles[8] !== -1 && commonStyles[8] !== "")
  241. {
  242. textDecoration += "line-through";
  243. }
  244. commonStyles[6] = -1;
  245. commonStyles[7] = -1;
  246. if (textDecoration !== "")
  247. {
  248. commonStyles[8] = "text-decoration:" + textDecoration;
  249. }
  250. else
  251. {
  252. commonStyles[8] = -1;
  253. }
  254. if (commonStyles[9] !== -1 && commonStyles[9] !== "")
  255. {
  256. commonStyles[9] = 'text-align:' + commonStyles[9];
  257. }
  258. if (commonStyles[10] !== -1 && commonStyles[10] !== "")
  259. {
  260. commonStyles[10] = 'vertical-align:' + commonStyles[10];
  261. }
  262. var currentStyleStr = "";
  263. for (i = 0; i < commonStyles.length; i++)
  264. {
  265. if (commonStyles[i] !== -1)
  266. {
  267. currentStyleStr += addSeparator(commonStyles[i]);
  268. }
  269. }
  270. return currentStyleStr;
  271. };
  272. function addSeparator(cssString, separator)
  273. {
  274. if (cssString !== "")
  275. {
  276. if (typeof separator != "undefined")
  277. {
  278. cssString += separator;
  279. }
  280. else
  281. {
  282. cssString += ";";
  283. }
  284. }
  285. return cssString;
  286. };
  287. function initTextStyles(css, elementsArray, formArray)
  288. {
  289. if (typeof formArray[6] != "undefined")
  290. {
  291. setCombo(formArray[6], getCSSValue(css, 'font-family'));
  292. }
  293. if (typeof formArray[7] != "undefined")
  294. {
  295. setCombo(formArray[7], getCSSValue(css, 'font-size'));
  296. }
  297. if (typeof formArray[8] != "undefined")
  298. {
  299. setCombo(formArray[8], getCSSValue(css, 'font-weight'));
  300. }
  301. if (typeof formArray[9] != "undefined")
  302. {
  303. setCombo(formArray[9], getCSSValue(css, 'font-style'));
  304. }
  305. var forecolor = getCSSValue(css, 'color');
  306. if (typeof formArray[0] != "undefined")
  307. {
  308. formArray[0].value = forecolor;
  309. }
  310. if (typeof elementsArray[0] != "undefined")
  311. {
  312. elementsArray[0].style.backgroundColor = forecolor;
  313. }
  314. if (typeof elementsArray[3] != "undefined")
  315. {
  316. elementsArray[3].setColor(forecolor);
  317. }
  318. var backcolor = getCSSValue(css, 'background-color');
  319. if (typeof formArray[1] != "undefined")
  320. {
  321. formArray[1].value = backcolor;
  322. }
  323. if (typeof elementsArray[1] != "undefined")
  324. {
  325. elementsArray[1].style.backgroundColor = backcolor;
  326. }
  327. if (typeof elementsArray[4] != "undefined")
  328. {
  329. elementsArray[4].setColor(backcolor);
  330. }
  331. var textDecoration = getCSSValue(css, 'text-decoration');
  332. if (typeof formArray[2] != "undefined")
  333. {
  334. formArray[2].checked = (/underline/gi).test(textDecoration);
  335. }
  336. if (typeof formArray[3] != "undefined")
  337. {
  338. formArray[3].checked = (/overline/gi).test(textDecoration);
  339. }
  340. if (typeof formArray[4] != "undefined")
  341. {
  342. formArray[4].checked = (/line-through/gi).test(textDecoration);
  343. }
  344. var vertAlign = getCSSValue(css, 'vertical-align');
  345. var horizAlign = getCSSValue(css, 'text-align');
  346. var align = cssToAlignCode(horizAlign, vertAlign);
  347. if (typeof formArray[5] != "undefined")
  348. {
  349. formArray[5].value = align;
  350. }
  351. if (typeof elementsArray[2] != "undefined")
  352. {
  353. elementsArray[2].setAlignment(align);
  354. }
  355. };
  356. function cssToAlignCode(horizAlign, vertAlign)
  357. {
  358. var align = "";
  359. if (vertAlign !== "" && horizAlign !== "")
  360. {
  361. switch (vertAlign)
  362. {
  363. case "top":
  364. align = "T";
  365. break;
  366. case "middle":
  367. align = "M";
  368. break;
  369. case "bottom":
  370. align = "B";
  371. break;
  372. }
  373. switch (horizAlign)
  374. {
  375. case "left":
  376. align += "L";
  377. break;
  378. case "center":
  379. align += "C";
  380. break;
  381. case "right":
  382. align += "R";
  383. break;
  384. }
  385. }
  386. return align;
  387. };
  388. function setCombo(selectObj, cssValue)
  389. {
  390. if (cssValue !== "")
  391. {
  392. for (var i = 0; i < selectObj.options.length; i++)
  393. {
  394. if (selectObj.options[i].value == cssValue)
  395. {
  396. selectObj.options[i].selected = true;
  397. break;
  398. }
  399. }
  400. }
  401. else
  402. {
  403. selectObj.options[0].selected = true;
  404. }
  405. };
  406. function getCSSValue(css, attribute)
  407. {
  408. var reAttr = new RegExp('^([^:]*)');
  409. var reValue = new RegExp(':\s*(.*)');
  410. var reAttrName = new RegExp('^\s*' + attribute + '\s*$', 'i');
  411. var value = "";
  412. var cssLines = css.split(";");
  413. if (cssLines)
  414. {
  415. for (var i = 0; i < cssLines.length; i++)
  416. {
  417. var cssLine = cssLines[i].replace(/^\s*/,"").replace(/\s*$/, "");
  418. if ( reAttr.test(cssLine) )
  419. {
  420. if ( reAttrName.test(RegExp.$1) && reValue.test(cssLine) )
  421. {
  422. value = RegExp.$1;
  423. break;
  424. }
  425. }
  426. }
  427. }
  428. return value;
  429. };