-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.html
More file actions
409 lines (375 loc) · 21.1 KB
/
example.html
File metadata and controls
409 lines (375 loc) · 21.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" type="text/javascript"></script>
<script>$j = jQuery.noConflict();</script>
<script src="http://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js" type="text/javascript"></script>
<script>
// Converts "JavaScript" to "java_script"
String.prototype.underscore = function() {
return this.replace(/([A-Z]+)([A-Z][a-z])/g,'$1_$2').
replace(/([a-z\d])([A-Z])/g,'$1_$2').
replace("-", "_").
toLowerCase();
};
// Description:
// String variable interpolation, i.e. $s("hello_#{foo}_stuff") substitutes in value of the "foo" variable
//
// Simple Usage:
// years = 3; // Global context (scoped to window object)
// $s("I'm just #{years} and a half years old!");
// -> "I'm just 3 and a half years old!"
//
// Advanced Usage:
// $s('I am speaking to you in a #{fn("loud")} voice!', { fn: function(arg) { return arg.toUpperCase(); } });
// -> "I am speaking to you in a LOUD voice!"
//
// $s("I'm feeling particularly #{x} right now!", { x: 'Randy' });
// -> "I'm feeling particularly Randy right now!"
$s = function(string, context) {
if (string === null) {
throw "string argument cannot be null";
}
if (string === undefined) {
throw "string argument cannot be undefined";
}
var match = null;
try {
match = string.match(/.*(#\{(.+)\}).*/);
} catch (err) {
throw err;
}
while (match) {
var f = function(code) { return eval(code) };
var evalee = match[2].match(/^this\./) ? match[2] : "this.".concat(match[2]);
result = f.apply(context || this, [evalee]);
string = string.replace(match[1], result);
match = string.match(/.*(#\{(.+)\}).*/);
}
return string;
};
</script>
<script src="http://documentcloud.github.com/underscore/underscore-min.js" type="text/javascript"></script>
<style type="text/css">
.facebook_broad_category_chooser .left {
float: left;
}
.facebook_broad_category_chooser .super_clear {
clear: both !important;
float: none !important;
height: 0 !important;
padding: 0 !important;
margin: 0 !important;
}
.facebook_broad_category_chooser div.parents {
margin-left: 20px;
}
.facebook_broad_category_chooser div.left.parents,
.facebook_broad_category_chooser div.left.children {
margin-right: 5px;
width: 200px;
height: 180px;
overflow-y: scroll;
overflow-x: hidden;
border: 1px solid #AAA;
}
.facebook_broad_category_chooser ul {
padding: 0;
border: 0;
margin: 0;
zoom: 1;
}
.facebook_broad_category_chooser ul li {
width: 178px;
height: 23px;
margin-top: 1px;
padding: 0px 2px;
}
.facebook_broad_category_chooser div.parents ul li {
background-image: url(/images/bullets/small-right-grey-arrow.gif);
background-position: 98% 46%;
background-repeat: no-repeat;
}
.facebook_broad_category_chooser div.parents ul li.selected {
background-image: url(/images/bullets/small-right-black-arrow.gif);
background-position: 98% 46%;
background-repeat: no-repeat;
}
.facebook_broad_category_chooser ul li span {
vertical-align: middle;
overflow: hidden;
white-space: nowrap;
}
.facebook_broad_category_chooser ul li span.broad_category_parent {
display: inline-block;
width: 145px;
height: 20px;
}
.facebook_broad_category_chooser ul li span.broad_category_parent_count {
display: inline-block;
width: 20px;
height: 20px;
text-align: center;
margin: 0 auto;
background-color: #D9DEEA;
border-radius: 4px;
}
.facebook_broad_category_chooser ul li.selected,
.facebook_broad_category_chooser ul li.selected:hover {
background-color: #D9DEEA;
}
.facebook_broad_category_chooser ul li:hover {
background-color: #EFF2F7;
}
.facebook_broad_category_chooser ul li span.broad_category_parent_count > p {
font-size: 11px;
font-weight: bold;
margin-top: 4px;
color: #405499;
}
.facebook_broad_category_chooser ul li span.broad_category_parent_count.empty {
display: none;
}
.facebook_broad_category_chooser ul li span.broad_category_child > label {
font-weight: normal;
display: inline-block;
width: 155px;
height: 20px;
}
.facebook_broad_category_chooser div.selection_count {
margin: 10px 20px 0 20px;
}
.facebook_broad_category_chooser div.clear_selections,
.facebook_broad_category_chooser div.show_hide_selected {
margin-top: 13px;
margin-right: 10px;
cursor: pointer !important;
}
.facebook_broad_category_chooser div.selection_count > span.count {
display: inline-block;
width: 25px;
height: 25px;
text-align: center;
margin: 0 auto;
background-color: #D9DEEA;
border-radius: 4px;
}
.facebook_broad_category_chooser div.selection_count > span.count > p {
display: inline-block;
font-size: 14px;
font-weight: bold;
text-align: center;
color: #405499;
margin: 4px auto 0 auto;
}
.facebook_broad_category_chooser div.parents.disabled {
background-color: #ddd;
opacity: 0.4;
}
.facebook_broad_category_chooser a {
color: white;
background-color: #90F;
border-radius: 4px;
font-size: 13px;
padding: 2px 4px;
text-transform: uppercase;
}
</style>
</head>
<body>
<div class="facebook_broad_category_chooser">
<div class="left parents"></div>
<div class="left children"></div>
<div class="super_clear"></div>
<div class="left selection_count">
<span class="count"><p class="bold">0</p></span>
<span class="bold">categories selected</span>
</div>
<div class="left clear_selections"></div>
<div class="left show_hide_selected">
<a class="show">Show selected</a>
<a class="hide" style="display: none;">Hide selected</a>
</div>
</div>
<script>
var data = [{"id": 6002714885172, "name": "Cooking", "parent_category": "Activities"}, {"id": 6002714885972, "name":
"Dancing", "parent_category": "Activities"}, {"id": 6002714885772, "name": "DIY/Crafts", "parent_category": "Activities"},
{"id": 6003050229172, "name": "Event Planning", "parent_category": "Activities"}, {"id": 6002714886772, "name": "Food & Dining",
"parent_category": "Activities"}, {"id": 6002714884772, "name": "Gaming (Console)", "parent_category": "Activities"},
{"id": 6002714884572, "name": "Gaming (Social/Online)", "parent_category": "Activities"}, {"id": 6002714887172, "name":
"Gardening", "parent_category": "Activities"}, {"id": 6002714888172, "name": "Literature/Reading", "parent_category":
"Activities"}, {"id": 6002714889172, "name": "Outdoor Fitness Activities", "parent_category": "Activities"}, {"id":
6003050295572, "name": "Photo Uploading", "parent_category": "Activities"}, {"id": 6002714898772, "name": "Photography",
"parent_category": "Activities"}, {"id": 6002714895372, "name": "Traveling", "parent_category": "Activities"}, {"id":
6002714890972, "name": "Computer Programming", "parent_category": "Business/Technology"}, {"id": 6002714889372, "name":
"Personal Finance", "parent_category": "Business/Technology"}, {"id": 6002714890172, "name": "Real Estate", "parent_category":
"Business/Technology"}, {"id": 6002714890772, "name": "Science/Technology", "parent_category": "Business/Technology"}, {"id":
6002714898572, "name": "Small Business Owners", "parent_category": "Business/Technology"}, {"id": 6002737124172, "name": "Has birthday in <1 week",
"parent_category": "Events"}, {"id": 6003054185372, "name": "Recently Moved", "parent_category":
"Events"}, {"id": 6003053857372, "name": "Away from Family", "parent_category": "Family Status"}, {"id": 6003053860372,
"name": "Away from Hometown", "parent_category": "Family Status"}, {"id": 6002714401172, "name": "Baby Boomers",
"parent_category": "Family Status"}, {"id": 6003050210972, "name": "Engaged (<1 year)", "parent_category": "Family Status"},
{"id": 6002714398772, "name": "Engaged (<6 months)", "parent_category": "Family Status"}, {"id": 6002714398172, "name":
"Newlywed (<1 year)", "parent_category": "Family Status"}, {"id": 6003050226972, "name": "Newlywed (<6 months)",
"parent_category": "Family Status"}, {"id": 6002714398372, "name": "Parents (All)", "parent_category": "Family Status"},
{"id": 6002714905372, "name": "Parents (child: 0-3yrs)", "parent_category": "Family Status"}, {"id": 6002714905572, "name":
"Parents (child: 4-12yrs)", "parent_category": "Family Status"}, {"id": 6002714905772, "name": "Parents (child: 13-15yrs)",
"parent_category": "Family Status"}, {"id": 6002714906172, "name": "Parents (child: 16-19yrs)", "parent_category": "Family Status"},
{"id": 6002714884172, "name": "Autos", "parent_category": "Interests"}, {"id": 6002714891172, "name":
"Beer/Wine/Spirits", "parent_category": "Interests"}, {"id": 6002714885572, "name": "Charity/Causes", "parent_category":
"Interests"}, {"id": 6002714886172, "name": "Education/Teaching", "parent_category": "Interests"}, {"id": 6002714894572,
"name": "Entertainment (TV)", "parent_category": "Interests"}, {"id": 6002714887372, "name": "Environment", "parent_category":
"Interests"}, {"id": 6002714887972, "name": "Health & Wellbeing", "parent_category": "Interests"}, {"id": 6002714887572,
"name": "Home & Garden", "parent_category": "Interests"}, {"id": 6002714888572, "name": "News", "parent_category":
"Interests"}, {"id": 6002714889572, "name": "Pets (All)", "parent_category": "Interests"}, {"id": 6002714889972, "name": "Pets (Cats)",
"parent_category": "Interests"}, {"id": 6002714889772, "name": "Pets (Dogs)", "parent_category": "Interests"}, {"id":
6002714894772, "name": "Politics (US Active)", "parent_category": "Interests"}, {"id": 6002714894972, "name": "Politics (US Conservative)",
"parent_category": "Interests"}, {"id": 6002714895172, "name": "Politics (US Liberal)", "parent_category":
"Interests"}, {"id": 6002714886372, "name": "Pop Culture", "parent_category": "Interests"}, {"id": 6002809853972, "name":
"Mobile (All)", "parent_category": "Mobile"}, {"id": 6002809854572, "name": "Android", "parent_category": "Mobile"}, {"id":
6002809854172, "name": "iPhone", "parent_category": "Mobile"}, {"id": 6003030879772, "name": "Others", "parent_category":
"Mobile"}, {"id": 6002809854372, "name": "RIM/Blackberry", "parent_category": "Mobile"}, {"id": 6002809854772, "name":
"Windows Phone", "parent_category": "Mobile"}, {"id": 6002714888372, "name": "Movie/Film (All)", "parent_category":
"Movie/Film"}, {"id": 6002714902772, "name": "Action/Adventure", "parent_category": "Movie/Film"}, {"id": 6002714902972,
"name": "Animated", "parent_category": "Movie/Film"}, {"id": 6002900645572, "name": "Bollywood", "parent_category":
"Movie/Film"}, {"id": 6002714903172, "name": "Classic", "parent_category": "Movie/Film"}, {"id": 6002714903372, "name":
"Comedy", "parent_category": "Movie/Film"}, {"id": 6002714903572, "name": "Drama", "parent_category": "Movie/Film"}, {"id":
6002714903772, "name": "Family", "parent_category": "Movie/Film"}, {"id": 6002714903972, "name": "Horror", "parent_category":
"Movie/Film"}, {"id": 6002714904172, "name": "Independent", "parent_category": "Movie/Film"}, {"id": 6002714904372, "name":
"Musical", "parent_category": "Movie/Film"}, {"id": 6002714904572, "name": "Romance", "parent_category": "Movie/Film"}, {"id":
6002714904772, "name": "Science Fiction/Fantasy", "parent_category": "Movie/Film"}, {"id": 6002714904972, "name": "Sports",
"parent_category": "Movie/Film"}, {"id": 6002714905172, "name": "Suspense/Thriller", "parent_category": "Movie/Film"}, {"id":
6002714888972, "name": "Music (All)", "parent_category": "Music"}, {"id": 6002714899372, "name": "Alternative",
"parent_category": "Music"}, {"id": 6002714899972, "name": "Children's Music", "parent_category": "Music"}, {"id":
6002714900172, "name": "Christian & Gospel", "parent_category": "Music"}, {"id": 6002714901372, "name": "Classic Rock",
"parent_category": "Music"}, {"id": 6002714900372, "name": "Classical", "parent_category": "Music"}, {"id": 6002714900572,
"name": "Comedy", "parent_category": "Music"}, {"id": 6002714900772, "name": "Country", "parent_category": "Music"}, {"id":
6002714900972, "name": "Dance/Electronic", "parent_category": "Music"}, {"id": 6002714899572, "name": "Hip Hop/Rap",
"parent_category": "Music"}, {"id": 6002714899772, "name": "Jazz/Blues", "parent_category": "Music"}, {"id": 6002714901172,
"name": "Metal", "parent_category": "Music"}, {"id": 6002714901572, "name": "Pop", "parent_category": "Music"}, {"id":
6002714901772, "name": "R&B/Soul", "parent_category": "Music"}, {"id": 6002714901972, "name": "Reggae", "parent_category":
"Music"}, {"id": 6002714902572, "name": "Rock", "parent_category": "Music"}, {"id": 6002714884372, "name": "Beauty Products",
"parent_category": "Retail/Shopping"}, {"id": 6002714885372, "name": "Consumer Electronics", "parent_category":
"Retail/Shopping"}, {"id": 6002714886572, "name": "Fashion", "parent_category": "Retail/Shopping"}, {"id": 6002714890372,
"name": "Luxury Goods", "parent_category": "Retail/Shopping"}, {"id": 6002714891572, "name": "Sports (All)",
"parent_category": "Sports"}, {"id": 6002714891972, "name": "Baseball", "parent_category": "Sports"}, {"id": 6002714892172,
"name": "Basketball", "parent_category": "Sports"}, {"id": 6002900645772, "name": "Cricket", "parent_category": "Sports"},
{"id": 6002714892572, "name": "Extreme Sports", "parent_category": "Sports"}, {"id": 6002714892972, "name": "Fantasy Sports",
"parent_category": "Sports"}, {"id": 6002714891772, "name": "Football (American)", "parent_category": "Sports"}, {"id":
6002714893372, "name": "Golf", "parent_category": "Sports"}, {"id": 6002714892372, "name": "Ice Hockey", "parent_category":
"Sports"}, {"id": 6002714893572, "name": "Motor Sports/NASCAR", "parent_category": "Sports"}, {"id": 6002714894172, "name":
"Soccer/European Football", "parent_category": "Sports"}, {"id": 6002714893772, "name": "Tennis", "parent_category":
"Sports"}];
var selections = [6002714885172, 6002714885972, 6002714885772, 6002714905772, 6002714906172];
var groups = _.groupBy(data, function(item) {
return item['parent_category'];
});
var sanitize_name = function(name) {
return name.gsub('/', '').gsub(' ', '_').underscore();
}
var parents_ul = $j('<ul>');
$j('.facebook_broad_category_chooser div.parents').append(parents_ul);
_.keys(groups).each(function(item) {
var children = groups[item];
var selectedChildren = $j.grep(children, function(item) {
if (_.include(selections, item.id)) {
return true;
}
});
var parent_id = sanitize_name(item);
var parent_li = $j('<li>').attr('parent_id', parent_id);
parent_li.append($j('<span class="broad_category_parent"></span>').text(item));
parent_li.append($j('<span class="broad_category_parent_count"></span>').html($j('<p></p>').
text(selectedChildren.length)).addClass(selectedChildren.length == 0 ? 'empty' : ''));
parents_ul.append(parent_li);
var child_ul = $j($s('<ul parent_id="#{id}" style="display: none;">', {id: parent_id}));
children.each(function(item) {
var checked = _.include(selections, item.id);
item['sanitized_name'] = sanitize_name(item.name);
var child_li = $j('<li>').addClass(checked ? 'selected' : '').append($j('<span class="broad_category_child_checkbox"></span>').
append($j($s('<input type="checkbox" value="#{id}" id="bcc_#{id}" />', item)).attr('checked', checked)));
child_li.append($j('<span class="broad_category_child"></span>').
append($j($s('<label for="bcc_#{id}">#{name}</label>', item))));
child_ul.append(child_li);
});
$j('.facebook_broad_category_chooser div.children').append(child_ul);
});
$j('.facebook_broad_category_chooser div.clear_selections').append($j('<a>').text('Clear Selections')).bind('click', function() {
$j('.facebook_broad_category_chooser div.children ul li.selected input[type=checkbox]:checked').each(function(index, item) {
$j(item).removeAttr('checked');
$j(item).trigger('click', item); // Re-checks the item, so we uncheck it again
$j(item).removeAttr('checked');
});
});
var toggleSelected= function(state) {
if (state) {
$j('.facebook_broad_category_chooser .show_hide_selected a.show').hide();
$j('.facebook_broad_category_chooser .show_hide_selected a.hide').show();
$j('.facebook_broad_category_chooser .children li').hide();
$j('.facebook_broad_category_chooser .children li.selected').show();
$j('.facebook_broad_category_chooser .children ul').show();
$j('.facebook_broad_category_chooser .parents').addClass('disabled');
} else {
$j('.facebook_broad_category_chooser .show_hide_selected a.show').show();
$j('.facebook_broad_category_chooser .show_hide_selected a.hide').hide();
$j('.facebook_broad_category_chooser .children ul').hide();
$j('.facebook_broad_category_chooser .children ul.selected').show();
$j('.facebook_broad_category_chooser .children li').show();
$j('.facebook_broad_category_chooser .parents').removeClass('disabled');
}
};
// Select the first parent
$j(document).ready(function() {
$j('.facebook_broad_category_chooser div.parents ul li').first().trigger('click');
$j.event.trigger('facebook_broad_category_chooser_changed');
$j('.facebook_broad_category_chooser .show_hide_selected a').bind('click', function(event) {
toggleSelected($j(event.target).hasClass('show'));
});
});
</script>
<script>
// Dispatch event indicating selection of a parent element
$j('.facebook_broad_category_chooser div.parents ul li').bind('click', function(event) {
var target = $j(event.target)[0].nodeName == 'SPAN' ? $j(event.target).parent() : $j(event.target);
if (target.closest('div.parents').hasClass('disabled')) {
return;
}
var parent_id = target.attr('parent_id');
$j('.facebook_broad_category_chooser div.children ul').hide();
$j('.facebook_broad_category_chooser div.parents ul li').removeClass('selected');
target.addClass('selected');
$j('.facebook_broad_category_chooser div.children ul').removeClass('selected');
$j($s('.facebook_broad_category_chooser div.children ul[parent_id=#{id}]', {id: parent_id})).show().addClass('selected');
});
// Dispatch event describing changes made to a child collection
$j('.facebook_broad_category_chooser ul li span.broad_category_child_checkbox').bind('click', function(event, target) {
var target = target ? $j(target) : $j(event.target);
if (target.attr('checked')) {
target.closest('li').first().addClass('selected');
} else {
target.closest('li').first().removeClass('selected');
}
var parent_id = $j(event.target).closest('ul').attr('parent_id');
var selectedChildren = $j(event.target).closest('ul').find('li.selected input:checked');
$j.event.trigger('facebook_broad_category_chooser_changed', {parent_id: parent_id, children: selectedChildren});
});
// Listen for events describing changes to child collections
$j('body').bind('facebook_broad_category_chooser_changed', function(event, data) {
if (data && data.children) {
var childCount = data.children.length;
$j($s('.parents ul li[parent_id=#{parent_id}] span.broad_category_parent_count > p', data)).text(childCount);
if (childCount == 0) {
$j($s('.parents ul li[parent_id=#{parent_id}] span.broad_category_parent_count', data)).addClass('empty');
} else {
$j($s('.parents ul li[parent_id=#{parent_id}] span.broad_category_parent_count', data)).removeClass('empty');
}
}
// Update total number of selected children
var totalSelected = $j('div.children ul li.selected').length;
$j('.facebook_broad_category_chooser .selection_count p').text(totalSelected);
// All currently selected values
var allSelectedValues = _.pluck($j('div.children ul li.selected input[type=checkbox]:checked'), 'value');
});
</script>
</body>
</html>