~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to wlhelp/static/js/encyclopedia.js

  • Committer: kaputtnik
  • Date: 2019-05-30 18:20:02 UTC
  • mto: This revision was merged to the branch mainline in revision 540.
  • Revision ID: kaputtnik-20190530182002-g7l91m1xo28clghv
adjusted README; first commit on the new server

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
$(document).ready(function() {
 
2
 
 
3
    // Smooth scrolling, taken from:
 
4
    // http://stackoverflow.com/a/18795112
 
5
    $("a[href*='#']").click(function(event){
 
6
        $('html, body').animate({
 
7
            scrollTop: $( $.attr(this, 'href') ).offset().top
 
8
        }, 500);
 
9
        event.preventDefault();
 
10
    });
 
11
 
 
12
    // Toggle display of scripting values
 
13
    // Usage of sessionStore makes it possible to keep the status
 
14
    // when switching to different pages. When switching the page the
 
15
    // state of checkbox and the visibility of items has to be set.
 
16
    if ( $("input#toggle_scripting").length > 0 &&
 
17
        sessionStorage.getItem('scripting_status') === "true"){
 
18
        $("input#toggle_scripting")[0].checked = true;
 
19
        $(".scripting").show();
 
20
    }
 
21
    $("input#toggle_scripting").click(function(){
 
22
        $(".scripting").toggle();
 
23
        sessionStorage.setItem('scripting_status', this.checked);
 
24
    });
 
25
 
 
26
    // Toggle the display of whole tables
 
27
    $("input#small").click(function(){
 
28
        $(".size-S").toggle();
 
29
    });
 
30
 
 
31
    $("input#medium").click(function(){
 
32
        $(".size-M").toggle();
 
33
    });
 
34
 
 
35
    $("input#big").click(function(){
 
36
        $(".size-B").toggle();
 
37
    });
 
38
 
 
39
    $("input#mines").click(function(){
 
40
        $(".size-I").toggle();
 
41
    });
 
42
 
 
43
    // Toggle rows of tables
 
44
    $("input#warehouse").click(function(){
 
45
        $(".type-W").toggle( function(){
 
46
            hide_empty_tables();
 
47
        });
 
48
    });
 
49
 
 
50
    $("input#production").click(function(){
 
51
        $(".type-P").toggle( function(){
 
52
            hide_empty_tables();
 
53
        });
 
54
    });
 
55
 
 
56
    $("input#military").click(function(){
 
57
        $(".type-M").toggle( function(){
 
58
            hide_empty_tables();
 
59
        });
 
60
    });
 
61
 
 
62
    $("input#training").click(function(){
 
63
        $(".type-T").toggle( function(){
 
64
            hide_empty_tables();
 
65
        });
 
66
    });
 
67
 
 
68
});
 
69
 
 
70
function hide_empty_tables(){
 
71
    // Hide a whole table if no row is displayed in it
 
72
    var tables = $("table");
 
73
    for (var i=0; i<tables.length; i++){
 
74
        var table = tables[i];
 
75
        var hidden_rows = 0;
 
76
        for (var x=0, row; row = table.rows[x]; x++){
 
77
            if (row.style.display == 'none'){
 
78
                hidden_rows++;
 
79
            }
 
80
        }
 
81
        // +1 here because we need to count also <th>
 
82
        if (table.rows.length == hidden_rows+1){
 
83
            table.style.display = 'none';
 
84
        }else{
 
85
            table.style.display = '';
 
86
        }
 
87
    }
 
88
}
 
 
b'\\ No newline at end of file'