]> WPIA git - gigi.git/blob - static/static/js/expert.js
07d1da4976d809d1a6b4474583efd528fdb6a003
[gigi.git] / static / static / js / expert.js
1 (function() {
2         function showExpert(isExpert)
3         {
4           var elements = document.getElementsByClassName("expert");
5           for(var i = 0; elements.length > i; i++)
6           {
7             if(!isExpert) {
8                 elements[i].setAttribute("class","expert experthidden");
9             } else {
10                 elements[i].setAttribute("class","expert");
11             }
12           }
13         }
14         function init(){
15                 showExpert(false);
16                 var expert = document.getElementById("expertbox");
17                 if(expert !== null) {
18                         expert.onchange = (function(expert){return function(){showExpert(expert.checked)}})(expert);
19                 }
20                 $(".panel-activatable").map(function() {
21                         var panel = $(this);
22                         var refresh = function(){
23                                 var radio = this.type == "radio";
24                                 if(radio && this.form.currentRadios === undefined) {
25                                         this.form.currentRadios = {};
26                                 }
27                                 if(this.checked) {
28                                         panel.find(".panel-body").removeClass("hidden");
29                                         if(radio) {
30                                                 var rds = this.form.currentRadios;
31                                                 if(rds[this.name] !== undefined){
32                                                         $(rds[this.name]).trigger("change");
33                                                 }
34                                                 rds[this.name] = this;
35                                         }
36                                 } else {
37                                         panel.find(".panel-body").addClass("hidden");
38                                 }
39                         };
40                         panel.find(".panel-heading [type=\"checkbox\"]").map(refresh);
41                         panel.find(".panel-heading [type=\"checkbox\"]").change(refresh);
42                         panel.find(".panel-heading [type=\"radio\"]").map(refresh);
43                         panel.find(".panel-heading [type=\"radio\"]").change(refresh);
44                         return this.id;
45                 });
46         }
47         (function(oldLoad) {
48                 if (oldLoad == undefined) {
49                         window.onload = init;
50                 } else {
51                         window.onload = function() {
52                                 init();
53                                 oldLoad();
54                         }
55                 }
56         })(window.onload);
57
58 })();