PageRenderTime 50ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Main/SPALM.ApplicationDeployer.Help/OutputCHM/Styles/spsfbranding.js

#
JavaScript | 685 lines | 577 code | 63 blank | 45 comment | 197 complexity | 0455570f5b955142097d50f1ce40997f MD5 | raw file
  1. // The Onload method
  2. // this is an array that holds the devLangs of language specific text control, they might are:
  3. // vb, cs, cpp, nu
  4. var allLanguageTagSets = new Array();
  5. // we stored the ids of code snippets of same pages so that we can do interaction between them when tab are selected
  6. var snippetIdSets = new Array();
  7. var isSearchPage = false;
  8. // Width of TOC: 1 (280px), 2 (480px), 3 (680px)
  9. var tocPosition = 1;
  10. function onLoad()
  11. {
  12. var lang = GetCookie("CodeSnippetContainerLang", "Visual Basic");
  13. var currentLang = getDevLangFromCodeSnippet(lang);
  14. // if LST exists on the page, then set the LST to show the selected or nu value of the LST
  15. if (lanSpecTextIdSet.length >= 1)
  16. {
  17. var i = 0;
  18. while (i < lanSpecTextIdSet.length)
  19. {
  20. var devLangSpan = document.getElementById(lanSpecTextIdSet[i] + "_" + currentLang);
  21. if (devLangSpan != null)
  22. {
  23. devLangSpan.style.display = 'inline';
  24. }
  25. else
  26. document.getElementById(lanSpecTextIdSet[i] + "_nu").style.display = 'inline';
  27. i++;
  28. }
  29. }
  30. // if codesnippet exists
  31. if (snippetIdSets.length > 0)
  32. {
  33. var i = 0;
  34. while (i < snippetIdSets.length)
  35. {
  36. var _tempSnippetCount = 5;
  37. if (document.getElementById(snippetIdSets[i] + "_tab5") == null)
  38. _tempSnippetCount = 1;
  39. if (_tempSnippetCount < 2)
  40. { // Tabs not grouped - skip
  41. // Disable 'Copy to clipboard' link if in Chrome
  42. if (navigator.userAgent.toLowerCase().indexOf('chrome') != -1)
  43. {
  44. document.getElementById(snippetIdSets[i] + "_copycode").style.display = 'none';
  45. }
  46. i++;
  47. continue;
  48. }
  49. if (lang != null && lang.length > 0)
  50. {
  51. var index = 1, j = 1;
  52. while (j < 6)
  53. {
  54. var tabTemp = document.getElementById(snippetIdSets[i] + "_tab" + j);
  55. if (tabTemp == null) { j++; continue; }
  56. if (tabTemp.innerHTML.indexOf(lang) != -1)
  57. {
  58. index = j;
  59. break;
  60. }
  61. j++;
  62. }
  63. if (j == 6) {
  64. if (document.getElementById(snippetIdSets[i] + "_tab1").className.indexOf("OH_CodeSnippetContainerTabDisabled") != -1) {
  65. // Select the first non-disabled tab
  66. var j = 2;
  67. while (j < 6) {
  68. var tab = document.getElementById(snippetIdSets[i] + "_tab" + j);
  69. if (tab.className.indexOf("OH_CodeSnippetContainerTabDisabled") == -1) {
  70. tab.className = "OH_CodeSnippetContainerTabActiveNotFirst";
  71. document.getElementById(snippetIdSets[i] + '_code_Div' + j).style.display = 'block';
  72. break;
  73. }
  74. j++;
  75. }
  76. // disable left most img if first tab disabled
  77. document.getElementById(snippetIdSets[i] + "_tabimgleft").className = "OH_CodeSnippetContainerTabLeftDisabled";
  78. }
  79. }
  80. else {
  81. setCurrentLang(snippetIdSets[i], lang, index, _tempSnippetCount, false);
  82. }
  83. }
  84. if (document.getElementById(snippetIdSets[i] + "_tab5").className.indexOf("OH_CodeSnippetContainerTabDisabled") != -1)
  85. {
  86. // disable right most img if last tab disabled
  87. document.getElementById(snippetIdSets[i] + "_tabimgright").className = "OH_CodeSnippetContainerTabRightDisabled";
  88. }
  89. i++;
  90. }
  91. }
  92. updateSearchUI();
  93. // Check for high contrast mode
  94. if (isHighContrast())
  95. {
  96. onHighContrast(isBlackBackground());
  97. }
  98. // Position TOC
  99. tocPosition = GetCookie("TocPosition", 1);
  100. resizeToc();
  101. }
  102. function updateSearchUI()
  103. {
  104. var searchWatermark = document.getElementById('searchWatermark');
  105. var searchBtn = document.getElementById('btnS');
  106. var searchTextbox = document.getElementById('qu');
  107. if (searchWatermark && searchBtn && searchTextbox)
  108. {
  109. if (searchBtn.innerText == '' || searchBtn.textContent == '') // true if we are not on the search results page
  110. {
  111. // Position watermarks
  112. searchWatermark.style.top = searchTextbox.offsetTop + 'px';
  113. searchWatermark.style.left = searchTextbox.offsetLeft + 'px';
  114. if (searchTextbox.value != '')
  115. {
  116. searchWatermark.style.display = 'none';
  117. searchTextbox.focus();
  118. }
  119. else
  120. {
  121. searchWatermark.style.display = 'inline';
  122. searchTextbox.blur();
  123. }
  124. }
  125. else
  126. {
  127. isSearchPage = true;
  128. searchWatermark.style.display = 'none';
  129. searchTextbox.focus();
  130. }
  131. }
  132. }
  133. // We use a colored span to detect high contrast mode
  134. function isHighContrast()
  135. {
  136. var elem = document.getElementById('HCColorTest');
  137. if (elem)
  138. {
  139. // Set SPAN text color - will not be applied if in contrast mode
  140. elem.style.color = '#ff00ff';
  141. if (window.getComputedStyle)
  142. { // Firefox
  143. var textcolor = window.getComputedStyle(elem, null).color;
  144. if (textcolor != 'rgb(255, 0, 255)'
  145. && textcolor != '#ff00ff')
  146. {
  147. return true;
  148. }
  149. }
  150. else if (elem.currentStyle)
  151. { // IE
  152. if (elem.currentStyle.color != '#ff00ff')
  153. {
  154. return true;
  155. }
  156. }
  157. }
  158. return false;
  159. }
  160. // Called to determine if background is black
  161. // Only accurate when in high constrast mode
  162. function isBlackBackground()
  163. {
  164. var color = '';
  165. if (window.getComputedStyle)
  166. { // Firefox
  167. color = window.getComputedStyle(document.body, null).backgroundColor;
  168. }
  169. else if (document.body.currentStyle)
  170. { // IE
  171. color = document.body.currentStyle.backgroundColor;
  172. }
  173. if (color == 'rgb(0, 0, 0)'
  174. || color == '#000000')
  175. {
  176. return true;
  177. }
  178. return false;
  179. }
  180. // Called when high constrast is detected
  181. function onHighContrast(black)
  182. {
  183. if (black)
  184. { // Black background, so use alternative images
  185. // VS logo
  186. var logo = document.getElementById('VSLogo');
  187. if (logo)
  188. {
  189. var logoHC = document.getElementById('VSLogoHC');
  190. if (logoHC)
  191. {
  192. logo.style.display = 'none';
  193. logoHC.style.display = '';
  194. }
  195. }
  196. // Search
  197. var searchImage = document.getElementById('searchImage');
  198. if (searchImage)
  199. {
  200. var searchImageHC = document.getElementById('searchImageHC');
  201. if (searchImageHC)
  202. {
  203. searchImage.style.display = 'none';
  204. searchImageHC.style.display = '';
  205. }
  206. }
  207. }
  208. }
  209. function getDevLangFromCodeSnippet(lang)
  210. {
  211. var tagSet = "nu";
  212. if (lang != null)
  213. {
  214. var temp = lang.toLowerCase().replace(" ", "");
  215. if (temp.indexOf("visualbasic") != -1)
  216. tagSet = "vb";
  217. if ((temp.indexOf("csharp") != -1) || (temp.indexOf("c#") != -1))
  218. tagSet = "cs";
  219. if ((temp.indexOf("cplusplus") != -1) || (temp.indexOf("visualc++") != -1))
  220. tagSet = "cpp";
  221. }
  222. return tagSet;
  223. }
  224. // Cookie functionality
  225. function GetCookie(sName, defaultValue)
  226. {
  227. var aCookie = document.cookie.split("; ");
  228. for (var i = 0; i < aCookie.length; i++)
  229. {
  230. var aCrumb = aCookie[i].split("=");
  231. if (sName == aCrumb[0])
  232. return unescape(aCrumb[1])
  233. }
  234. return defaultValue;
  235. }
  236. function SetCookie(name, value, expires, path, domain, secure)
  237. {
  238. // set time, it's in milliseconds
  239. var today = new Date();
  240. today.setTime(today.getTime());
  241. if (expires)
  242. {
  243. expires = expires * 1000 * 60 * 60 * 24;
  244. }
  245. var expires_date = new Date(today.getTime() + (expires));
  246. document.cookie = name + "=" + escape(value) +
  247. ((expires) ? ";expires=" + expires_date.toGMTString() : "") +
  248. ((path) ? ";path=" + path : "") +
  249. ((domain) ? ";domain=" + domain : "") +
  250. ((secure) ? ";secure" : "");
  251. }
  252. function SetCodeSnippetContainerLangCookie(lang)
  253. {
  254. SetCookie("CodeSnippetContainerLang", lang, 60, "/", "", "");
  255. return;
  256. }
  257. // we stored the ids of language specific text control of same pages so that we can get access to all of them
  258. // This function called from Codesnippet.xslt and LanguageSpecificText.xslt
  259. var lanSpecTextIdSet = new Array();
  260. function addToLanSpecTextIdSet(id)
  261. {
  262. lanSpecTextIdSet[lanSpecTextIdSet.length] = id;
  263. //document.cookie = "languageSpecifcTextId=" + id;
  264. }
  265. // Functions called from codesnippet.xslt
  266. function ChangeTab(objid, lang, index, snippetCount)
  267. {
  268. setCurrentLang(objid, lang, index, snippetCount, true);
  269. SetCodeSnippetContainerLangCookie(lang);
  270. // switch tab for all of other codesnippets
  271. i = 0;
  272. while (i < snippetIdSets.length)
  273. {
  274. // we just care about other snippes
  275. if (snippetIdSets[i] != objid)
  276. {
  277. var _tempSnippetCount = 5;
  278. if (document.getElementById(snippetIdSets[i] + "_tab5") == null)
  279. _tempSnippetCount = 1;
  280. if (_tempSnippetCount < 2)
  281. { // Tabs are not grouped - skip
  282. i++;
  283. continue;
  284. }
  285. var index = 1, j = 1;
  286. while (j < 6)
  287. {
  288. var tabTemp = document.getElementById(snippetIdSets[i] + "_tab" + j);
  289. if (tabTemp == null) { j++; continue; }
  290. if (tabTemp.innerHTML.indexOf(lang) != -1)
  291. {
  292. index = j;
  293. }
  294. j++;
  295. }
  296. if (index > 5) index = 1;
  297. setCurrentLang(snippetIdSets[i], lang, index, _tempSnippetCount, false);
  298. }
  299. i++;
  300. }
  301. }
  302. var viewPlain = false;
  303. function setCurrentLang(objid, lang, index, snippetCount, setLangSpecText)
  304. {
  305. var _tab = document.getElementById(objid + "_tab" + index);
  306. if (_tab != null)
  307. {
  308. if (document.getElementById(objid + "_tab" + index).innerHTML.match("javascript") == null)
  309. {
  310. //Select left most tab as fallback
  311. var i = 1;
  312. while (i < 6)
  313. {
  314. if (!document.getElementById(objid + "_tab" + i).disabled)
  315. {
  316. setCurrentLang(objid, document.getElementById(objid + "_tab" + i).firstChild.innerHTML, i, snippetCount, false);
  317. return;
  318. }
  319. i++;
  320. }
  321. return;
  322. }
  323. var langText = _tab.innerHTML;
  324. if (langText.indexOf(lang) != -1)
  325. {
  326. i = 1;
  327. while (i < 6)
  328. {
  329. var tabtemp = document.getElementById(objid + "_tab" + i);
  330. if (tabtemp != null)
  331. {
  332. if (tabtemp.className == "OH_CodeSnippetContainerTabActive")
  333. tabtemp.className = "OH_CodeSnippetContainerTabFirst";
  334. if (tabtemp.className == "OH_CodeSnippetContainerTabActiveNotFirst")
  335. tabtemp.className = "OH_CodeSnippetContainerTab";
  336. }
  337. var codetemp = document.getElementById(objid + "_code_Div" + i);
  338. if (codetemp != null)
  339. {
  340. if (codetemp.style.display != 'none')
  341. codetemp.style.display = 'none';
  342. }
  343. i++;
  344. }
  345. document.getElementById(objid + "_tab" + index).className = "OH_CodeSnippetContainerTabActive";
  346. if (index != 1)
  347. document.getElementById(objid + "_tab" + index).className = "OH_CodeSnippetContainerTabActiveNotFirst";
  348. if (viewPlain == false) document.getElementById(objid + '_code_Div' + index).style.display = 'block';
  349. else document.getElementById(objid + '_code_Plain_Div' + index).style.display = 'block';
  350. // change the css of the first/last image div according the current selected tab
  351. // if the first tab is selected
  352. if (index == 1)
  353. document.getElementById(objid + "_tabs").firstChild.className = "OH_CodeSnippetContainerTabLeftActive";
  354. else
  355. {
  356. if (document.getElementById(objid + "_tabs").firstChild.className != "OH_CodeSnippetContainerTabLeftDisabled")
  357. document.getElementById(objid + "_tabs").firstChild.className = "OH_CodeSnippetContainerTabLeft";
  358. }
  359. // if the last tab is selected
  360. if (index == snippetCount)
  361. document.getElementById(objid + "_tabs").lastChild.className = "OH_CodeSnippetContainerTabRightActive";
  362. else
  363. {
  364. if (document.getElementById(objid + "_tabs").lastChild.className != "OH_CodeSnippetContainerTabRightDisabled")
  365. document.getElementById(objid + "_tabs").lastChild.className = "OH_CodeSnippetContainerTabRight";
  366. }
  367. // show copy code button if EnableCopyCode is set to true (and not in Chrome)
  368. if (document.getElementById(objid + "_tab" + index).getAttribute("EnableCopyCode") == "true"
  369. && navigator.userAgent.toLowerCase().indexOf('chrome') == -1)
  370. {
  371. document.getElementById(objid + "_copycode").style.display = 'inline';
  372. }
  373. else
  374. {
  375. document.getElementById(objid + "_copycode").style.display = 'none';
  376. }
  377. // we set the corresponding language period for language specific text control
  378. // according to the current selected language
  379. if (setLangSpecText)
  380. {
  381. var i = 0;
  382. var allSupportLang = new Array('nu', 'vb', 'cs', 'cpp');
  383. while (i < lanSpecTextIdSet.length)
  384. {
  385. var j = 0;
  386. while (j < allSupportLang.length)
  387. {
  388. var elem = document.getElementById(lanSpecTextIdSet[i] + "_" + allSupportLang[j]);
  389. if (elem != null)
  390. {
  391. elem.style.display = 'none';
  392. }
  393. j++;
  394. }
  395. var curDevLang = getDevLangFromCodeSnippet(lang);
  396. var elem = document.getElementById(lanSpecTextIdSet[i] + "_" + curDevLang);
  397. if (elem != null)
  398. {
  399. elem.style.display = 'inline';
  400. }
  401. i++;
  402. }
  403. }
  404. }
  405. }
  406. }
  407. function addSpecificTextLanguageTagSet(codesnippetid)
  408. {
  409. var i = 1;
  410. while (i < 6)
  411. {
  412. var snippetObj = document.getElementById(codesnippetid + "_tab" + i);
  413. if (snippetObj == null) break;
  414. var tagSet = getDevLangFromCodeSnippet(snippetObj.innerHTML);
  415. var insert = true;
  416. var j = 0;
  417. while (j < allLanguageTagSets.length)
  418. {
  419. if (allLanguageTagSets[j] == tagSet)
  420. {
  421. insert = false;
  422. }
  423. j++;
  424. }
  425. if (insert) allLanguageTagSets.push(tagSet);
  426. i++;
  427. }
  428. snippetIdSets.push(codesnippetid);
  429. }
  430. function ExchangeTitleContent(objid, snippetCount)
  431. {
  432. ApplyExchangeTitleContent(objid, snippetCount);
  433. // switch tab for all of other codesnippets
  434. i = 0;
  435. while (i < snippetIdSets.length)
  436. {
  437. // we just care about other snippes
  438. if (snippetIdSets[i] != objid)
  439. {
  440. var _tempSnippetCount = 5;
  441. if (document.getElementById(snippetIdSets[i] + "_tab5") == null)
  442. _tempSnippetCount = 1;
  443. if (_tempSnippetCount < 2) return;
  444. ApplyExchangeTitleContent(snippetIdSets[i], _tempSnippetCount);
  445. }
  446. i++;
  447. }
  448. }
  449. function ApplyExchangeTitleContent(objid, snippetCount)
  450. {
  451. var i = 1;
  452. while (i <= snippetCount)
  453. {
  454. var obj = document.getElementById(objid + '_code_Div' + i);
  455. if ((obj != null) && (obj.style.display != 'none'))
  456. {
  457. obj.style.display = 'none';
  458. document.getElementById(objid + '_code_Plain_Div' + i).style.display = 'block';
  459. viewPlain = true;
  460. document.getElementById(objid + '_ViewPlain').style.display = 'none';
  461. document.getElementById(objid + '_ViewColorized').style.display = 'inline';
  462. break;
  463. }
  464. obj = document.getElementById(objid + '_code_Plain_Div' + i);
  465. if ((obj != null) && (obj.style.display != 'none'))
  466. {
  467. obj.style.display = 'none';
  468. document.getElementById(objid + '_code_Div' + i).style.display = 'block';
  469. viewPlain = false;
  470. document.getElementById(objid + '_ViewPlain').style.display = 'inline';
  471. document.getElementById(objid + '_ViewColorized').style.display = 'none';
  472. break;
  473. }
  474. i++;
  475. }
  476. }
  477. function CopyToClipboard(objid, snippetCount)
  478. {
  479. var contentid;
  480. var i = 1;
  481. while (i <= snippetCount)
  482. {
  483. var obj = document.getElementById(objid + '_code_Div' + i);
  484. if ((obj != null) && (obj.style.display != 'none') && (document.getElementById(objid + '_code_Plain_Div' + i).innerText != ''))
  485. {
  486. contentid = objid + '_code_Plain_Div' + i;
  487. break;
  488. }
  489. obj = document.getElementById(objid + '_code_Plain_Div' + i);
  490. if ((obj != null) && (obj.style.display != 'none') && (document.getElementById(objid + '_code_Plain_Div' + i).innerText != ''))
  491. {
  492. contentid = objid + '_code_Plain_Div' + i;
  493. break;
  494. }
  495. i++;
  496. }
  497. if (contentid == null) return;
  498. if (window.clipboardData)
  499. {
  500. try { window.clipboardData.setData("Text", document.getElementById(contentid).innerText); }
  501. catch (e) {
  502. alert("Permission denied. Enable copying to the clipboard.");
  503. }
  504. }
  505. else if (window.netscape)
  506. {
  507. try
  508. {
  509. netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
  510. var clip = Components.classes['@mozilla.org/widget/clipboard;1']
  511. .createInstance(Components.interfaces.nsIClipboard);
  512. if (!clip) return;
  513. var trans = Components.classes['@mozilla.org/widget/transferable;1']
  514. .createInstance(Components.interfaces.nsITransferable);
  515. if (!trans) return;
  516. trans.addDataFlavor('text/unicode');
  517. var str = new Object();
  518. var len = new Object();
  519. var str = Components.classes["@mozilla.org/supports-string;1"]
  520. .createInstance(Components.interfaces.nsISupportsString);
  521. var copytext = document.getElementById(contentid).textContent;
  522. str.data = copytext;
  523. trans.setTransferData("text/unicode", str, copytext.length * 2);
  524. var clipid = Components.interfaces.nsIClipboard;
  525. clip.setData(trans, null, clipid.kGlobalClipboard);
  526. }
  527. catch (e)
  528. {
  529. alert("Permission denied. Enter \"about:config\" in the address bar and double-click the \"signed.applets.codebase_principal_support\" setting to enable copying to the clipboard.");
  530. }
  531. }
  532. else
  533. {
  534. return;
  535. }
  536. }
  537. function Print(objid, snippetCount)
  538. {
  539. var contentid;
  540. var i = 1;
  541. while (i <= snippetCount)
  542. {
  543. var obj = document.getElementById(objid + '_code_Div' + i);
  544. if ((obj != null) && (obj.style.display != 'none'))
  545. {
  546. contentid = objid + '_code_Plain_Div' + i;
  547. break;
  548. }
  549. obj = document.getElementById(objid + '_code_Plain_Div' + i);
  550. if ((obj != null) && (obj.style.display != 'none'))
  551. {
  552. contentid = objid + '_code_Plain_Div' + i;
  553. break;
  554. }
  555. i++;
  556. }
  557. if (contentid == null) return;
  558. var obj = document.getElementById(contentid);
  559. if (obj)
  560. {
  561. //var tempwin = window.open('', '', '');
  562. var tempwin = window.open('', '', 'top=100000, left=100000, dependent=yes');
  563. tempwin.document.title = "Printer Dialog";
  564. tempwin.document.body.innerText = obj.innerText;
  565. tempwin.print();
  566. tempwin.close();
  567. }
  568. }
  569. function SearchTextboxKeyUp(e)
  570. {
  571. var e = window.event || e;
  572. var key = e.charCode || e.keyCode;
  573. if (key == 27)
  574. { // If user pressed ESCAPE, clear the textbox (IE doesn't pass special keys to onkeypress)
  575. document.getElementById('qu').value = '';
  576. return false;
  577. }
  578. preventEventBubbling(e);
  579. }
  580. // TOC resize script
  581. function onIncreaseToc()
  582. {
  583. tocPosition++;
  584. if (tocPosition > 3) tocPosition = 1;
  585. resizeToc();
  586. SetCookie("TocPosition", tocPosition);
  587. }
  588. function onResetToc()
  589. {
  590. tocPosition = 1;
  591. resizeToc();
  592. SetCookie("TocPosition", tocPosition);
  593. }
  594. function resizeToc()
  595. {
  596. var toc = document.getElementById("LeftNav");
  597. if (toc)
  598. {
  599. // Set TOC width
  600. // Positions: 1 (280px) 2 (380px) 3 (480px)
  601. var tocWidth = 280 + ((tocPosition - 1) * 100);
  602. toc.style.width = tocWidth + "px";
  603. // Position images
  604. if (document.all) tocWidth -= 1;
  605. document.getElementById("TocResize").style.left = tocWidth + "px";
  606. // Hide/show increase TOC width image
  607. document.getElementById("ResizeImageIncrease").style.display = (tocPosition == 3) ? "none" : "";
  608. // Hide/show reset TOC width image
  609. document.getElementById("ResizeImageReset").style.display = (tocPosition != 3) ? "none" : "";
  610. }
  611. }
  612. function preventEventBubbling(e)
  613. {
  614. if (e && e.stopPropagation)
  615. {
  616. e.stopPropagation();
  617. }
  618. else
  619. {
  620. event.cancelBubble = true;
  621. }
  622. }