Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 1 | %= javascript begin |
| 2 | |
Nils Diewald | eca3044 | 2014-11-18 20:33:54 +0000 | [diff] [blame] | 3 | // Create new hint |
| 4 | var hint = Object.create(Hint).init(); |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 5 | |
Nils Diewald | e99d904 | 2014-11-20 23:36:54 +0000 | [diff] [blame^] | 6 | // Add toggleClass method similar to jquery |
| 7 | HTMLElement.prototype.toggleClass = function (c1, c2) { |
| 8 | var cl = this.classList; |
| 9 | if (cl.contains(c1)) { |
| 10 | cl.add(c2); |
| 11 | cl.remove(c1); |
| 12 | } |
| 13 | else { |
| 14 | cl.remove(c2); |
| 15 | cl.add(c1); |
| 16 | }; |
| 17 | }; |
| 18 | |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 19 | function openTutorial (o) { |
Nils Diewald | e99d904 | 2014-11-20 23:36:54 +0000 | [diff] [blame^] | 20 | var tut = document.getElementById("tutorial"); |
| 21 | tut.classList.add("active") |
| 22 | var iframe = tut.getElementsByTagName("iframe")[0]; |
| 23 | iframe.setAttribute("src", getTutorialPage()); |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | function closeTutorial (o) { |
Nils Diewald | e99d904 | 2014-11-20 23:36:54 +0000 | [diff] [blame^] | 27 | document.getElementById("tutorial").classList.remove("active"); |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 28 | }; |
| 29 | |
| 30 | function useQuery (o) { |
| 31 | var q = o.getAttribute("data-query"); |
| 32 | var ql = o.getAttribute("data-query-language"); |
Nils Diewald | f49633a | 2014-11-08 22:33:25 +0000 | [diff] [blame] | 33 | var qc = o.getAttribute("data-query-cutoff"); |
Nils Diewald | e99d904 | 2014-11-20 23:36:54 +0000 | [diff] [blame^] | 34 | if (qc !== 0 && qc !== "0" && qc !== "off" && qc !== null) { |
| 35 | document.getElementById("q-cutoff-field").checked = true; |
| 36 | }; |
Nils Diewald | e8e8805 | 2014-11-10 16:32:02 +0000 | [diff] [blame] | 37 | |
Nils Diewald | e99d904 | 2014-11-20 23:36:54 +0000 | [diff] [blame^] | 38 | var qlf = document.getElementById("ql-field").options; |
| 39 | for (i in qlf) |
| 40 | if (qlf[i].value == ql) qlf[i].selected = true; |
Nils Diewald | e8e8805 | 2014-11-10 16:32:02 +0000 | [diff] [blame] | 41 | |
Nils Diewald | e99d904 | 2014-11-20 23:36:54 +0000 | [diff] [blame^] | 42 | document.getElementById("q-field").value = q; |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 43 | closeTutorial(); |
| 44 | }; |
| 45 | |
Nils Diewald | e99d904 | 2014-11-20 23:36:54 +0000 | [diff] [blame^] | 46 | document.getElementById("sidebar").addEventListener("click",function(){ |
| 47 | this.classList.toggle("active"); |
| 48 | },false); |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 49 | |
Nils Diewald | e99d904 | 2014-11-20 23:36:54 +0000 | [diff] [blame^] | 50 | %# document.getElementById("top") |
| 51 | %# .querySelectorAll("span.location") |
| 52 | %# .addEventListener("click",function() { |
| 53 | %# document.getElementById("sidebar").classList.toggle("active"); |
| 54 | %# }, false); |
| 55 | |
| 56 | function toggleAlignment (o) { |
| 57 | var ol = document.querySelector("#search > ol"); |
| 58 | ol.toggleClass("align-left", "align-right"); |
| 59 | o.firstChild.toggleClass("fa-align-right", "fa-align-left"); |
| 60 | }; |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 61 | |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 62 | % end |