Merge branch 'master' of vcs.fsf.org:enc-static
[enc-static.git] / js / scripts.js
1 /*
2 @licstart The following is the entire license notice for the
3 JavaScript code in this page.
4
5 Copyright © 2014 Free Software Foundation, Inc.
6
7 The JavaScript code in this page is free software: you can
8 redistribute it and/or modify it under the terms of the GNU
9 General Public License (GNU GPL) as published by the Free Software
10 Foundation, either version 3 of the License, or (at your option)
11 any later version. The code is distributed WITHOUT ANY WARRANTY;
12 without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
14
15 As additional permission under GNU GPL version 3 section 7, you
16 may distribute non-source (e.g., minimized or compacted) forms of
17 that code without the copy of the GNU GPL normally required by
18 section 4, provided you include this license notice and a URL
19 through which recipients can access the Corresponding Source.
20
21 @licend The above is the entire license notice
22 for the JavaScript code in this page.
23 */
24
25 $(document).ready(function() {
26 var SLIDE_DURATION = 400;
27
28 // Allow a slide toggle effect to be performed on the given list
29 // element type when clicking a child h4 for the given css class.
30 // This is used for troubleshooting panels and dropdown menus.
31 function slideToggle(cssClass, listElement) {
32 $(cssClass + " > " + listElement).css("display", "none");
33 $(cssClass + " > h4").click(function() {
34 $(this).toggleClass("expanded")
35 .next(listElement).slideToggle(SLIDE_DURATION);
36
37 return false;
38 });
39 }
40
41 // Transform the language list into a dropdown. By doing this trick
42 // here instead of simply writing the HTML this way to begin with,
43 // users that do not have javascript enabled will still see the
44 // links in a non-fancy way that doesn't look horrible.
45 var languageList = $("#languages").removeClass("os").detach();
46 var container = $("<li><h4>Language</h4></li>")
47 .addClass("dropdown")
48 .append(languageList);
49
50 $("#menu").prepend(container);
51
52 // Close dropdowns when user clicks anywhere outside.
53 $("body").click(function() {
54 $(".dropdown > h4.expanded")
55 .removeClass("expanded")
56 .next("ul").toggle();
57 });
58
59 // Enable dropdowns and troubleshooting panels.
60 slideToggle(".troubleshooting", "dl");
61 slideToggle(".dropdown", "ul");
62 });