Skip to content

Commit

Permalink
added automatic filtration, using ko.program.init_filters(opt)
Browse files Browse the repository at this point in the history
eemeli committed Jul 9, 2014
1 parent b0e039b commit 7a0ed17
Showing 3 changed files with 143 additions and 95 deletions.
126 changes: 34 additions & 92 deletions index.html
Original file line number Diff line number Diff line change
@@ -70,97 +70,7 @@ <h1><a href="#info"><!-- alt="CONVENTION" title="CONVENTION" -->
</style>
<div id="prog_view" class="view">
<div id="prog_filters" class="filters">
<div id="prog_lists">
<ul id="day">
<li id="now">Now
<li id="all_days">All days
<li id="d2014-01-17">Friday
<li id="d2014-01-18">Saturday
<li id="d2014-01-19">Sunday
<li id="d2014-01-20">Monday
</ul>

<ul id="area">
<li id="all_areas">Everywhere
<li id="a3W">Mezzanine (3W)
<li id="a3E">Conference (3E)
<li id="a2">Lobby (2)
<li id="a1W">Concourse (1W)
<li id="a1E">Galleria (1E)
<li id="area2-list"><div class="popup-link" style="display: inline-block; max-width: 110px;">More…</div>
<ul id="area2" class="popup" data-title="Room">
<li id="Adams">Adams
<li id="Alcott">Alcott
<li id="Bulfinch">Bulfinch
<li id="Burroughs">Burroughs
<li id="Carlton">Carlton
<li id="Commonwealth Ballroom ABC">Commonwealth Ballroom
<li id="Douglas">Douglas
<li id="Executive Board Room">Executive Board Room
<li id="Faneuil">Faneuil
<li id="Galleria - Autograph Space">Galleria
<li id="Grand Ballroom A">Grand Ballroom A
<li id="Grand Ballroom AB">Grand Ballroom AB
<li id="Grand Ballroom B">Grand Ballroom B
<li id="Grand Ballroom C">Grand Ballroom C
<li id="Grand Ballroom DE">Grand Ballroom DE
<li id="Griffin">Griffin
<li id="Hale">Hale
<li id="Hancock">Hancock
<li id="Harbor Ballroom I">Harbor Ballroom I
<li id="Harbor Ballroom III">Harbor Ballroom III
<li id="Independence">Independence
<li id="Otis">Otis
<li id="Paine">Paine
<li id="Pool">Pool
<li id="Revere">Revere
<li id="Webster">Webster
<li id="ArisiaTV">ArisiaTV
<!--<li id="Other">Other-->
</ul></ul>

<ul id="tag" style="min-width: 140px;">
<li id="all_tags">All tracks &amp; types
<li id="Featured">Featured items
<li id="track-list"><div class="popup-link">Choose track…</div>
<ul id="tag2" class="popup" data-title="Track">
<li id="track:Anime">Anime
<li id="track:Art">Art
<li id="track:Comics">Comics
<li id="track:Communities">Communities
<li id="track:ConComm">ConComm
<li id="track:Costuming">Costuming
<li id="track:Fan Interest">Fan Interest
<li id="track:Fast Track">Fast Track
<li id="track:GOH">GOH
<li id="track:Gaming">Gaming
<li id="track:Literature">Literature
<li id="track:Maker">Maker
<li id="track:Media">Media
<li id="track:Music">Music
<li id="track:Science">Science
<li id="track:Theater">Theater
<li id="track:Theater & con tech">Theater &amp; con tech
<li id="track:Writing">Writing
<li id="track:Trackless events">Trackless events
</ul>
<li id="type-list"><div class="popup-link">Choose type…</div>
<ul id="tag3" class="popup" data-title="Type">
<li id="type:Concert">Concert
<li id="type:Drama">Drama
<li id="type:Lecture">Lecture
<li id="type:Meeting">Meeting
<li id="type:Open Gaming">Open Gaming
<li id="type:Panel">Panel
<li id="type:Participatory Event">Participatory Event
<li id="type:Projected Media">Projected Media
<li id="type:Reading">Reading
<li id="type:Scheduled Game">Scheduled Game
<li id="type:Signing">Signing
<li id="type:Workshop">Workshop
<!-- id="kf" data-regexp="^Kaffeeklatsch">Kaffeeklatsch -->
</ul></ul>
</div>
<div id="prog_lists"></div>

<form name="search" id="search">
<input type="text" id="q" required data-txt="Search" data-txt-attr="placeholder">
@@ -274,9 +184,41 @@ <h2>Quick Reference</h2>
<script> var konopas_set = {
'id': '',
'default_duration': 60,
'tag_categories': ['track', 'type'],
'time_show_am_pm': true,
'show_all_days_by_default': false,
'use_server': true };
'use_server': true,
'filters': {
'day': {},
'area': {
'loc_level': 0,
'labels': {
'all_areas': 'Everywhere',
'area': 'Other location',
'Galleria': 'Galleria (1E)',
'1W': 'Concourse (1W)',
'2': 'Lobby (2)',
'3E': 'Conference (3E)',
'3W': 'Mezzanine (3W)',
'ArisiaTV': '$ArisiaTV',
'Commonwealth Ballroom ABC': 'Commonwealth Ballroom',
},
'regexp': { 'Galleria': '^Galleria' },
'promote': ['3W', '3E', '2', '1W', 'Galleria'],
'exclude': ['^Galleria -', '^Gaming Table', '^Grand Prefunction$']
},
'tag': {
'categories': ['track', 'type'],
'labels': {
'all_tags': 'All tracks & types',
'Featured': 'Featured items',
'track': 'Track',
'type': 'Type'
},
'promote': ['Featured'],
}
}
};
</script>
<script src="data/program.js"></script>
<script src="data/people.js"></script>
4 changes: 2 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ function KonOpas(set) {
if (_el('refresh')) window.addEventListener('load', this.refresh_cache.bind(this), false);
}

KonOpas.prototype.set_program = function(list) { this.program = new KonOpas.Prog(list); }
KonOpas.prototype.set_program = function(list, opt) { this.program = new KonOpas.Prog(list, opt); }
KonOpas.prototype.set_people = function(list) { this.people = new KonOpas.Part(list, this); }

KonOpas.prototype.storage_get = function(name) {
@@ -97,7 +97,7 @@ KonOpas.prototype.refresh_cache = function() {
}

var ko = new KonOpas(konopas_set);
if (typeof program != 'undefined') ko.set_program(program);
if (typeof program != 'undefined') ko.set_program(program, ko.filters);
if (typeof people != 'undefined') ko.set_people(people);
var server = ko.server;
ko.set_view();
108 changes: 107 additions & 1 deletion src/prog.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KonOpas.Prog = function(list) {
KonOpas.Prog = function(list, opt) {
function _sort(a, b) {
if (a.date < b.date) return -1;
if (a.date > b.date) return 1;
@@ -25,6 +25,7 @@ KonOpas.Prog = function(list) {
sf.onsubmit = _el('q').onblur = KonOpas.Prog.filter_change;
sf.onreset = function() { KonOpas.Prog.set_filters({}); };
}
this.init_filters(opt);
}


@@ -173,6 +174,111 @@ KonOpas.Prog.prototype.now_list = function() {
return now;
}

KonOpas.Prog.prototype.init_filters = function(opt) {
var filter_el = _el('prog_lists'), labels = {}, regexp = {};
function _txt(s) {
return i18n.txt(s.charAt(0).toUpperCase() + s.slice(1).replace('_',' '));
}
function _ul(id) {
var e = document.createElement('ul');
e.id = id;
return e;
}
function _li(par, id, txt) {
var e = document.createElement('li');
e.id = /^[^a-zA-Z]/.test(id) ? par.id[0] + id : id
if (!txt) txt = labels[id] || _txt(id);
e.textContent = /^[\\^$]/.test(txt) ? txt.substr(1) : txt;
if (regexp[id]) e.setAttribute('data-regexp', regexp[id]);
par.appendChild(e);
}
function _compare(a, b) {
var _a = (labels[a] || a).toLowerCase(),
_b = (labels[b] || b).toLowerCase();
if ((_a[0] == '$') != (_b[0] == '$')) return (_a < _b) ? 1 : -1; // $ == 0x24
if (_a < _b) return -1;
if (_a > _b) return 1;
return 0;
}
function _ul2(par, id, name, prefix, list) {
var title = labels[name] || _txt(name),
root = document.createElement('li'),
link = _new_elem('div', 'popup-link', title + '…'),
ul = _new_elem('ul', 'popup');
link.setAttribute('data-title', link.textContent);
link.addEventListener('click', KonOpas.popup_open);
ul.id = id;
ul.setAttribute('data-title', title);
ul.addEventListener('click', KonOpas.Prog.filter_change);
for (var i = 0; i < list.length; ++i) {
var txt = labels[list[i]] || list[i].replace(prefix, '');
_li(ul, list[i], txt);
}
root.appendChild(link);
root.appendChild(ul);
par.appendChild(root);
}
function _fill(id, items) {
var i = 0, o = opt[id], ul = _ul(id);
labels = o.labels || {};
regexp = o.regexp || {};
for (var r in regexp) items[r] = 1;
_li(ul, 'all_' + id + 's');
if (o.promote) for (i = 0; i < o.promote.length; ++i) {
_li(ul, o.promote[i]);
delete items[o.promote[i]];
}
if (o.exclude) {
var re = new RegExp(o.exclude.join('|'));
for (var t in items) if (re.test(t)) delete items[t];
}
var list = Object.keys(items).sort(_compare);
if (o.categories) for (i = 0; i < o.categories.length; ++i) {
var prefix = o.categories[i] + ':',
list_in = [], list_out = [];
for (var j = 0; j < list.length; ++j) {
if (list[j].substr(0, prefix.length) == prefix) {
list_in.push(list[j]);
} else {
list_out.push(list[j]);
}
}
switch (list_in.length) {
case 0: break;
case 1: _li(ul, prefix + list_in[0]); break;
default: _ul2(ul, id + i, o.categories[i], prefix, list_in);
}
list = list_out;
}
if (list.length < 4) for (i = 0; i < list.length; ++i) _li(ul, list[i]);
else _ul2(ul, id + i, id, '', list);
filter_el.appendChild(ul);
}
if (!opt || !filter_el) return;
while (filter_el.firstChild) filter_el.removeChild(filter_el.firstChild);
var days = {}, areas = {}, tags = {},
lvl = (opt.area && opt.area.loc_level) || 0;
for (var i = 0, l = this.list.length; i < l; ++i) {
var p = this.list[i];
if (opt.day && p.date) days[p.date] = 1;
if (opt.area && (typeof p.loc == 'object') && p.loc[lvl]) areas[p.loc[lvl]] = 1;
if (opt.tag && (typeof p.tags == 'object')) for (var j = 0; j < p.tags.length; ++j) tags[p.tags[j]] = 1;
}
if (opt.day) {
var d_ul = _ul('day'),
d_re = opt.day.exclude ? new RegExp(opt.day.exclude.join('|')) : false;
_li(d_ul, 'now');
_li(d_ul, 'all_days');
for (var d in days) {
if (d_re && d_re.test(d)) continue;
var d_d = KonOpas.parse_date(d);
_li(d_ul, 'd' + d, i18n.txt('weekday_n', {'N': d_d ? d_d.getDay() : -1 }));
}
filter_el.appendChild(d_ul);
}
if (opt.area) _fill('area', areas);
if (opt.tag) _fill('tag', tags);
}

KonOpas.Prog.prototype.default_day = function() {
var day_start = '', day_end = '',

0 comments on commit 7a0ed17

Please sign in to comment.