Skip to content

Commit afd2065

Browse files
committedSep 10, 2013
updating button "active" checking to toggle properly. School's are no liberally defined but there remain schools that don't serve any grades. I am logging those schools to the console so they can be tracked down and fixed in data.
1 parent 3db9932 commit afd2065

File tree

3 files changed

+59
-40
lines changed

3 files changed

+59
-40
lines changed
 

‎neighborhood-postload.js

+31-25
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,30 @@ $(document).ready(function() {
4747

4848
});
4949

50-
// function defs below
51-
50+
// the active attribute doesn't change until after onclick is resolved so it's easier to manually track button state
51+
var button_onoff = {
52+
"charter":1,
53+
"public":1,
54+
"elementary":1,
55+
"middle":1,
56+
"high":1,
57+
};
58+
$('.btn-group').on('click', 'button', function(e){
59+
var selected = $(this).attr('value');
60+
// console.log(selected);
61+
if($(this).hasClass("active")){
62+
button_onoff[selected] = 0;
63+
$(this).removeClass("btn-primary");
64+
//$(this).addClass("btn-inverse");
65+
// console.log("deactivating "+selected);
66+
}else{
67+
$(this).removeClass("btn-inverse");
68+
$(this).addClass("btn-primary");
69+
button_onoff[selected] = 1;
70+
// console.log("activating "+selected);
71+
}
72+
displaySchools('none',$(this));
73+
});
5274

5375
var first_pass = 1;
5476
var layer ;
@@ -64,23 +86,8 @@ function displaySchools(e,toggleswitch) {
6486
toggleswitch = 'none'
6587
layer = e.target;
6688
}
67-
// active switches don't toggle until after onclick has already passed
68-
// there must be a better way to do the toggleswitch piece
69-
var inactive_charter = $('button[name="schoolinfo"].active')
70-
.filter('[id="charter"]').val()=="charter" ? 0 : 1 ;
71-
if(toggleswitch == 'togglecharter'){ inactive_charter=inactive_charter+1%2; }
72-
var inactive_public = $('button[name="schoolinfo"].active')
73-
.filter('[id="public"]').val()=="public" ? 0 : 1 ;
74-
if(toggleswitch == 'togglepublic'){ inactive_public=inactive_public+1%2; }
75-
var inactive_elementary = $('button[name="schoolinfo"].active')
76-
.filter('[id="elementary"]').val()=="elementary" ? 0 : 1 ;
77-
if(toggleswitch == 'toggleelementary'){ inactive_elementary==inactive_elementary+1%2; }
78-
var inactive_middle = $('button[name="schoolinfo"].active')
79-
.filter('[id="middle"]').val()=="middle" ? 0 : 1 ;
80-
if(toggleswitch == 'togglemiddle'){ inactive_middle==inactive_middle+1%2; }
81-
var inactive_high = $('button[name="schoolinfo"].active')
82-
.filter('[id="high"]').val()=="high" ? 0 : 1 ;
83-
if(toggleswitch == 'togglehigh'){ inactive_high==inactive_high+1%2; }
89+
// console.log(" button checks: "+ button_onoff["charter"]+" "+button_onoff["public"]+
90+
// " "+button_onoff["elementary"] +" "+ button_onoff["middle"] +" "+ button_onoff["high"]);
8491

8592
// sometimes there will be no lines but a legend because of the filters so first pass is used.
8693
if (first_pass != 1) {
@@ -101,11 +108,11 @@ function displaySchools(e,toggleswitch) {
101108
// if the button is off then make sure the school of that class is excluded
102109
// elementary/middle/high schools are all tagged by a specific grade ranges!
103110
if (typeof schools[i].lat === 'number'
104-
&& !(inactive_public==1 && schools[i].school_type == 'Regular school')
105-
&& !(inactive_charter==1 && schools[i].charter == true )
106-
&& !(inactive_elementary==1 && schools[i].elementary_tag == true )
107-
&& !(inactive_middle==1 && schools[i].middle_tag == true )
108-
&& !(inactive_high==1 && schools[i].high_tag == true )
111+
&& !(button_onoff["public"]==0 && schools[i].school_type == 'Regular school')
112+
&& !(button_onoff["charter"]==0 && schools[i].charter == true )
113+
&& !(button_onoff["elementary"]==0 && schools[i].elementary_tag == true )
114+
&& !(button_onoff["middle"]==0 && schools[i].middle_tag == true )
115+
&& !(button_onoff["high"]==0 && schools[i].high_tag == true )
109116
) {
110117
//var marker = L.circleMarker([schools[i].lat, schools[i].lon], {radius: 5+((schools[i].count<10)?0:Math.sqrt(schools[i].count))});
111118
//marker.addTo(neighmap);
@@ -139,4 +146,3 @@ function onEachFeature(feature, layer) {
139146
});
140147
}
141148

142-

‎neighborhood.html

+9-12
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,18 @@
99
<div>Use the buttons to hide various school types.
1010
</div></b>
1111
<p>
12-
<!--- I want the active buttons, but onclick beats the button change to active
13-
so I pass a toggle switch ...this is awful --->
1412
<div class="btn-group" data-toggle="buttons-checkbox">
15-
<button name="schoolinfo" value="charter" id="charter" type="button" class="btn btn-primary active"
16-
onclick="displaySchools('none','togglecharter')">Charter</button>
17-
<button name="schoolinfo" value="public" id="public" type="button" class="btn btn-primary active"
18-
onclick="displaySchools('none','togglepublic')">Public</button>
13+
<button name="schoolinfo" value="charter" id="charter" type="button" class="btn btn-primary active">Charter</button>
14+
<button name="schoolinfo" value="public" id="public" type="button" class="btn btn-primary active">
15+
Public</button>
16+
1917
</div>
2018
<div class="btn-group" data-toggle="buttons-checkbox">
21-
<button name="schoolinfo" value="elementary" id="elementary" type="button" class="btn btn-primary active"
22-
onclick="displaySchools('none','toggleelementary')">Elementary</button>
23-
<button name="schoolinfo" value="middle" id="middle" type="button" class="btn btn-primary active"
24-
onclick="displaySchools('none','togglemiddle')">Middle</button>
25-
<button name="schoolinfo" value="high" id="high" type="button" class="btn btn-primary active"
26-
onclick="displaySchools('none','togglehigh')">High</button>
19+
<button name="schoolinfo" value="elementary" id="elementary" type="button" class="btn btn-primary active">Elementary</button>
20+
<button name="schoolinfo" value="middle" id="middle" type="button" class="btn btn-primary active" >Middle</button>
21+
<button name="schoolinfo" value="high" id="high" type="button" class="btn btn-primary active" >High</button>
22+
23+
2724
</div>
2825
</p>
2926
</div>

‎transparent.js

+19-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,25 @@ function getSchools(clusterId) {
5757
school.lon = data.longitude[key];
5858
school.charter = data.charter_status[key];
5959
school.school_type = data.school_type[key];
60-
school.elementary_tag = (data.grade_1[key]&&data.grade_2[key]&&data.grade_3[key]&&data.grade_4[key]&&data.grade_5[key]);
61-
school.middle_tag = (data.grade_6[key]&&data.grade_7[key]&&data.grade_8[key]);
62-
school.high_tag = (data.grade_9[key]&&data.grade_10[key]&&data.grade_11[key]&&data.grade_12[key]);
60+
61+
school.elementary_tag = (data.prek_3[key]||data.prek_4[key]||data.preschool[key]||data.kindergarten[key]
62+
||data.grade_1[key]||data.grade_2[key]
63+
||data.grade_3[key]||data.grade_4[key]||data.grade_5[key]);
64+
school.middle_tag = (data.grade_6[key]||data.grade_7[key]||data.grade_8[key]);
65+
school.high_tag = (data.grade_9[key]||data.grade_10[key]||data.grade_11[key]||data.grade_12[key]);
66+
67+
if(!(school.elementary_tag||school.middle_tag||school.high_tag)){
68+
console.log( school.school_name+ " " +
69+
data.kindergarten[key] + " " + data.grade_1[key] + " " + data.grade_2[key] + " "+
70+
data.grade_3[key] + " " + data.grade_4[key] + " " + data.grade_5[key] + " "+
71+
data.grade_6[key] + " " + data.grade_7[key] + " " + data.grade_8[key] + " "+
72+
data.grade_9[key] + " " + data.grade_10[key] + " " + data.grade_11[key] + " "+data.grade_12[key]
73+
);
74+
// }else{
75+
// console.log( school.school_name+ " " +
76+
// school.elementary_tag+ " " +school.middle_tag+ " " +school.high_tag);
77+
}
78+
6379
schools.push(school);
6480
}
6581
});

0 commit comments

Comments
 (0)
Please sign in to comment.