help2.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /*
  3. * This file is part of the LibreOffice project.
  4. *
  5. * This Source Code Form is subject to the terms of the Mozilla Public
  6. * License, v. 2.0. If a copy of the MPL was not distributed with this
  7. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  8. */
  9. // Used to set Application in caseinline=APP
  10. function setApplSpan(spanZ) {
  11. var module = getParameterByName("DbPAR");
  12. if (module === null) {
  13. module = "WRITER";
  14. }
  15. var y = spanZ.getElementsByTagName("SPAN");
  16. var n = y.length;
  17. var foundAppl = false;
  18. for (i = 0; i < n; i++) {
  19. if (y[i].getAttribute("id") === null){
  20. continue;
  21. }
  22. else if( y[i].getAttribute("id").startsWith(module)){
  23. y[i].removeAttribute("hidden");
  24. foundAppl=true;
  25. }
  26. }
  27. for (i = 0; i < n; i++) {
  28. if (y[i].getAttribute("id") === null){
  29. continue;
  30. }
  31. else if( y[i].getAttribute("id").startsWith("default")){
  32. if(!foundAppl){
  33. y[i].removeAttribute("hidden");
  34. }
  35. }
  36. }
  37. }
  38. // Used to set system in case, caseinline=SYSTEM
  39. function setSystemSpan(spanZ) {
  40. // if no System in URL, get browser system
  41. var system = getParameterByName("System");
  42. if (system === null) {
  43. system = getSystem();
  44. }
  45. var y = spanZ.getElementsByTagName("SPAN");
  46. var n = y.length;
  47. var foundSystem = false;
  48. for (i = 0; i < n; i++) {
  49. if (y[i].getAttribute("id") === null){
  50. continue;
  51. }
  52. else if( y[i].getAttribute("id").startsWith(system)){
  53. y[i].removeAttribute("hidden");
  54. foundSystem=true;
  55. }
  56. }
  57. for (i = 0; i < n; i++) {
  58. if (y[i].getAttribute("id") === null){
  59. continue;
  60. }
  61. else if( y[i].getAttribute("id").startsWith("default")){
  62. if(!foundSystem){
  63. y[i].removeAttribute("hidden");
  64. }
  65. }
  66. }
  67. }
  68. // paint headers and headings with appl color
  69. function moduleColor (module) {
  70. switch (module){
  71. case "WRITER" : {color="#083fa6"; break;}
  72. case "CALC" : {color="#007c3c"; break;}
  73. case "CHART" : {color="darkcyan"; break;}
  74. case "IMPRESS": {color="#d0120d"; break;}
  75. case "DRAW" : {color="#cb6d30"; break;}
  76. case "BASE" : {color="#7324a9"; break;}
  77. case "BASIC" : {color="black"; break;}
  78. case "MATH" : {color="#c10018"; break;}
  79. case "SHARED" : {color="darkslategray"; break;}
  80. default : {color="#18A303"; break;}
  81. }
  82. document.getElementById("TopLeftHeader").style.background = color;
  83. document.getElementById("SearchFrame").style.background = color;
  84. document.getElementById("DonationFrame").style.background = color;
  85. var cols = document.getElementsByClassName('tableheadcell');
  86. for(i = 0; i < cols.length; i++) {cols[i].style.backgroundColor = color;};
  87. for (j of [1,2,3,4,5,6]) {
  88. var hh = document.getElementsByTagName("H" + j);
  89. for(i = 0; i < hh.length; i++) {
  90. hh[i].style.color = color;
  91. hh[i].style.borderBottomColor = color;
  92. }
  93. }
  94. }
  95. // Find spans that need the switch treatment and give it to them
  96. var spans = document.querySelectorAll("[class^=switch]");
  97. var n = spans.length;
  98. for (z = 0; z < n; z++) {
  99. var id = spans[z].getAttribute("id");
  100. if (id === null) {
  101. continue;
  102. }
  103. else if (id.startsWith("swlnsys")) {
  104. setSystemSpan(spans[z]);
  105. } else {
  106. setApplSpan(spans[z]);
  107. }
  108. }
  109. /* add &DbPAR= and &System= to the links in DisplayArea div */
  110. /* skip for object files */
  111. function fixURL(module, system) {
  112. if ((DisplayArea = document.getElementById("DisplayArea")) === null) return;
  113. var itemlink = DisplayArea.getElementsByTagName("a");
  114. var pSystem = (system === null) ? getSystem() : system;
  115. var pAppl = (module === null) ? "SHARED" : module;
  116. var n = itemlink.length;
  117. for (var i = 0; i < n; i++) {
  118. if (itemlink[i].getAttribute("class") != "objectfiles") {
  119. setURLParam(itemlink[i], pSystem, pAppl);
  120. }
  121. }
  122. }
  123. //Set the params inside URL
  124. function setURLParam(itemlink, pSystem, pAppl) {
  125. var href = itemlink.getAttribute("href");
  126. if (href !== null) {
  127. // skip external links
  128. if (!href.startsWith("http")) {
  129. // handle bookmark.
  130. if (href.lastIndexOf('#') != -1) {
  131. var postf = href.substring(href.lastIndexOf('#'), href.length);
  132. var pref = href.substring(0, href.lastIndexOf('#'));
  133. itemlink.setAttribute("href", pref + "?" + '&DbPAR=' + pAppl + '&System=' + pSystem + postf);
  134. } else {
  135. itemlink.setAttribute("href", href + "?" + '&DbPAR=' + pAppl + '&System=' + pSystem);
  136. }
  137. }
  138. }
  139. }
  140. function getSystem() {
  141. var system = "Unknown OS";
  142. if (navigator.appVersion.indexOf("Win") != -1) system = "WIN";
  143. if (navigator.appVersion.indexOf("Mac") != -1) system = "MAC";
  144. if (navigator.appVersion.indexOf("X11") != -1) system = "UNIX";
  145. if (navigator.appVersion.indexOf("Linux") != -1) system = "UNIX";
  146. return system;
  147. }
  148. function getParameterByName(name, url) {
  149. if (!url) {
  150. url = window.location.href;
  151. }
  152. name = name.replace(/[\[\]]/g, "\\$&");
  153. var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)");
  154. var results = regex.exec(url);
  155. if (!results) {
  156. return null;
  157. }
  158. if (!results[2]) {
  159. return '';
  160. }
  161. return decodeURIComponent(results[2].replace(/\+/g, " "));
  162. }
  163. function existingLang(lang) {
  164. if (lang === undefined) {
  165. return 'en-US';
  166. }
  167. if (languagesSet.has(lang)) {
  168. return lang;
  169. }
  170. lang = lang.replace(/[-_].*/, '');
  171. if (languagesSet.has(lang)) {
  172. return lang;
  173. }
  174. return 'en-US';
  175. }
  176. function setupModules(lang) {
  177. var modulesNav = document.getElementById('modules-nav');
  178. if (!modulesNav.classList.contains('loaded')) {
  179. var html =
  180. '<a href="' + lang + '/text/shared/05/new_help.html?DbPAR=SHARED"><div class="office-icon"></div>LibreOffice</a>' +
  181. '<a href="' + lang + '/text/swriter/main0000.html?DbPAR=WRITER"><div class="writer-icon"></div>Writer</a>' +
  182. '<a href="' + lang + '/text/scalc/main0000.html?DbPAR=CALC"><div class="calc-icon"></div>Calc</a>' +
  183. '<a href="' + lang + '/text/simpress/main0000.html?DbPAR=IMPRESS"><div class="impress-icon"></div>Impress</a>' +
  184. '<a href="' + lang + '/text/sdraw/main0000.html?DbPAR=DRAW"><div class="draw-icon"></div>Draw</a>' +
  185. '<a href="' + lang + '/text/sdatabase/main.html?DbPAR=BASE"><div class="base-icon"></div>Base</a>' +
  186. '<a href="' + lang + '/text/smath/main0000.html?DbPAR=MATH"><div class="math-icon"></div>Math</a>' +
  187. '<a href="' + lang + '/text/schart/main0000.html?DbPAR=CHART"><div class="chart-icon"></div>Chart</a>' +
  188. '<a href="' + lang + '/text/sbasic/shared/main0601.html?DbPAR=BASIC"><div class="basic-icon"></div>Basic</a>';
  189. modulesNav.innerHTML = html;
  190. modulesNav.classList.add('loaded');
  191. }
  192. }
  193. function setupLanguages(page) {
  194. var langNav = document.getElementById('langs-nav');
  195. if (!langNav.classList.contains('loaded')) {
  196. var html = '';
  197. languagesSet.forEach(function(lang) {
  198. html += '<a href="' + lang + page + '">' + ((lang in languageNames)? languageNames[lang]: lang) + '</a>';
  199. });
  200. langNav.innerHTML = html;
  201. langNav.classList.add('loaded');
  202. }
  203. }
  204. // Test, if we are online
  205. if (document.body.getElementsByTagName('meta')) {
  206. var _paq = _paq || [];
  207. /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  208. _paq.push(['disableCookies']);
  209. _paq.push(['trackPageView']);
  210. _paq.push(['enableLinkTracking']);
  211. (function() {
  212. var u="//piwik.documentfoundation.org/";
  213. _paq.push(['setTrackerUrl', u+'piwik.php']);
  214. _paq.push(['setSiteId', '68']);
  215. var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
  216. g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
  217. })();
  218. var system = getParameterByName("System");
  219. } else {
  220. var system = getSystem();
  221. }
  222. var module = getParameterByName("DbPAR");
  223. fixURL(module,system);
  224. moduleColor(module);
  225. var helpID = getParameterByName("HID");
  226. // only used in xhp pages with <help-id-missing/> tags
  227. var missingElement = document.getElementById("bm_HID2");
  228. if(missingElement != null){missingElement.innerHTML = helpID;}
  229. function debugInfo(dbg) {
  230. if (dbg == null) return;
  231. document.getElementById("DEBUG").style.display = "block";
  232. document.getElementById("bm_module").innerHTML = "Module is: "+module;
  233. document.getElementById("bm_system").innerHTML = "System is: "+system;
  234. document.getElementById("bm_HID").innerHTML = "HID is: "+helpID;
  235. }
  236. debugInfo(getParameterByName("Debug"));
  237. // Mobile devices need the modules and langs on page load
  238. if (Math.max(document.documentElement.clientWidth, window.innerWidth || 0) < 960) {
  239. var e = new Event('click');
  240. var modulesBtn = document.getElementById('modules');
  241. var langsBtn = document.getElementById('langs');
  242. var modules = document.getElementById('modules-nav');
  243. var langs = document.getElementById('langs-nav');
  244. modules.setAttribute('data-a11y-toggle-open', '');
  245. modulesBtn.dispatchEvent(e);
  246. if (langs) {
  247. langs.setAttribute('data-a11y-toggle-open', '');
  248. langsBtn.dispatchEvent(e);
  249. }
  250. }
  251. /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */