Skip to content

Commit

Permalink
added new/replacement "Now" view as default
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Oct 5, 2014
1 parent 18f9737 commit 57f8865
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 163 deletions.
3 changes: 2 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
"star_hint": "To \"star\" a programme item, click on the square next to it. Your selections will be remembered, and shown in this view. You currently don't have any programme items selected, so this list is empty.",
"star_no_memory": "{WHY, select, FFcookies{It looks like you're using a Firefox browser with cookies disabled, so } IOSprivate{It looks like you're using an iOS or Safari browser in private mode, so } other{For some reason,}} your <a href=\"http://en.wikipedia.org/wiki/Web_storage\">localStorage</a> is not enabled, and therefore your selection will not be remembered between sessions. {SERVER, select, true{Please <span class=\"js-link\" onclick=\"var e=_el('login-popup-link');if(e)e.click();\">login</span> to enable persistent storage.} other{}}",
"filter_sum_id": "Listing {N, plural, one{one item: {TITLE}} other{# items with id {ID}}}",
"filter_sum": "Listing {N, plural, one{one {TAG} item} other{{ALL} # {TAG} items}} {GOT_NOW, select, true{on today at {NOW} and in the next two hours} other{}} {GOT_DAY, select, true{on {DAY}} other{}} {GOT_AREA, select, true{in {AREA}} other{}} {GOT_Q, select, true{matching the query {Q}} other{}}",
"filter_sum": "Listing {N, plural, one{one} other{{ALL} #}} {LIVE, select, undefined{} other{current and future}} {TAG} {N, plural, one{item} other{items}} {DAY, select, undefined{} other{on {DAY} {TIME, select, undefined{} other{after {TIME}}}}} {AREA, select, undefined{} other{in {AREA}}} {Q, select, undefined{} other{matching the query {Q}}}",
"day_link": "Show {N} matching items from {D, plural, =0{Sunday} =1{Monday} =2{Tuesday} =3{Wednesday} =4{Thursday} =5{Friday} =6{Saturday} other{???}}",
"hidden_link": "Show {N} more matching items with an end time before {T} on {D, plural, =0{Sunday} =1{Monday} =2{Tuesday} =3{Wednesday} =4{Thursday} =5{Friday} =6{Saturday} other{???}}",

"server_cmd_fail": "The command \"{CMD}\" failed.",
"show_comments": "Show {N, plural, one{one comment} other{# comments}}",
Expand Down
4 changes: 3 additions & 1 deletion i18n/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
"star_hint": "\"Tähdittääksesi\" valinnan, tökkää sen vieressä olevaa neliötä. Valintasi tallennetaan ja näytetään tässä. Et ole vielä valinnut yhtään ohjelmaa, joten lista on tyhjä.",
"star_no_memory": "{WHY, select, FFcookies{Näyttää siltä, että Firefox-selaimessasi on evästeiden käyttö estetty, jonka takia myöskään} IOSprivate{Näyttää siltä, että käytät iOS- tai Safari-selainta yksityistilassa, jonka takia} other{Jostain syystä}} <a href=\"http://en.wikipedia.org/wiki/Web_storage\">localStorage</a> -välimuisti ei nyt toimi, joten valintasi eivät säily seuraavaan istuntoon. {SERVER, select, true{Ole hyvä ja <span class=\"js-link\" onclick=\"var e=_el('login-popup-link');if(e)e.click();\">kirjaudu sisään</span> säilyttääksesi valintasi.} other{}}",
"filter_sum_id": "Listataan {N, plural, one{yksi ohjelma: {TITLE}} other{# ohjelmaa tunnisteella {ID}}}",
"filter_sum": "Listataan {N, plural, one{yksi {TAG} ohjelma} other{{ALL} # {TAG} ohjelmaa}} {GOT_NOW, select, true{tänään {NOW} ja seuraavan kahden tunnin aikana} other{}} {GOT_DAY, select, true{päivänä {DAY}} other{}} {GOT_AREA, select, true{paikassa {AREA}} other{}} {GOT_Q, select, true{kyselylle {Q}} other{}}",
"filter_sum": "Listataan {N, plural, one{yksi {LIVE, select, undefined{} other{tuleva}} {TAG} ohjelma} other{{ALL} # {LIVE, select, undefined{} other{tulevaa}} {TAG} ohjelmaa}} {DAY, select, undefined{} other{{DAY} {TIME, select, undefined{} other{klo {TIME} jälkeen}}}} {AREA, select, undefined{} other{paikassa {AREA}}} {Q, select, undefined{} other{kyselylle {Q}}}",
"day_link": "Näytä {N} osumaa {D, plural, =0{sunnuntailta} =1{maanantailta} =2{tiistailta} =3{keskiviikolta} =4{torstailta} =5{perjantailta} =6{lauantailta} other{???}}",
"hidden_link": "Näytä {N} lisää osumaa jotka ovat jo päättyneet {D, plural, =0{sunnuntaina} =1{maanantaina} =2{tiistaina} =3{keskiviikkona} =4{torstaina} =5{perjantaina} =6{lauantaina} other{???}} klo {T}",

"Votes": "Äänet",
"Not connected": "Ei yhteyttä palvelimeen",
Expand Down
4 changes: 3 additions & 1 deletion i18n/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
"star_hint": "”Stjärnmarkera” en programpunkt genom att klocka på den grå fyrkanten bredvid den. Dina markeringar lagras och visas i denna vy. Du har inte markerat några programpunkter än, så listan är för närvarande tom.",
"star_no_memory": "{WHY, select, FFcookies{It looks like you're using a Firefox browser with cookies disabled, so } IOSprivate{It looks like you're using an iOS or Safari browser in private mode, so } other{For some reason,}} your <a href=\"http://en.wikipedia.org/wiki/Web_storage\">localStorage</a> is not enabled, and therefore your selection will not be remembered between sessions. {SERVER, select, true{Please <span class=\"js-link\" onclick=\"var e=_el('login-popup-link');if(e)e.click();\">login</span> to enable persistent storage.} other{}}",
"filter_sum_id": "Visar {N, plural, one{en punkt: {TITLE}} other{# punkter med id {ID}}}",
"filter_sum": "Visar {N, plural, one{en {TAG} punkt} other{{ALL} # {TAG} punkter}} {GOT_NOW, select, true{on today at {NOW} and in the next two hours} other{}} {GOT_DAY, select, true{på {DAY}} other{}} {GOT_AREA, select, true{i {AREA}} other{}} {GOT_Q, select, true{stämmer med sökningen {Q}} other{}}",
"filter_sum": "Visar {N, plural, one{en} other{{ALL} #}} {LIVE, select, undefined{} other{[current and future]}} {TAG} {N, plural, one{punkt} other{punkter}} {DAY, select, undefined{} other{på {DAY} {TIME, select, undefined{} other{efter {TIME}}}}} {AREA, select, undefined{} other{i {AREA}}} {Q, select, undefined{} other{stämmer med sökningen {Q}}}",
"day_link": "[Show {N} matching items from {D, plural, =0{Sunday} =1{Monday} =2{Tuesday} =3{Wednesday} =4{Thursday} =5{Friday} =6{Saturday} other{???}}]",
"hidden_link": "[Show {N} more matching items with an end time before {T} on {D, plural, =0{Sunday} =1{Monday} =2{Tuesday} =3{Wednesday} =4{Thursday} =5{Friday} =6{Saturday} other{???}}]",

"Votes": "Röster",
"Not connected": "Inte ansluten",
Expand Down
140 changes: 86 additions & 54 deletions src/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,68 +95,91 @@ KonOpas.Item.new = function(it) {
return KonOpas.Item.new(it);
}

KonOpas.Item.show_list = function(ls, show_id, day, in_prog_view) {
if (!day || !konopas.program.days[day]) {
day = '';
for (day in konopas.program.days) break;
KonOpas.Item.show_list = function(ls, opt) {
var _now = Date.now(),
day_lengths = {}, day_links = {},
frag = document.createDocumentFragment(),
prev_date = '', prev_time = '',
_list_item = function(p) {
if (opt.day && p.date) {
day_lengths[p.date] = (day_lengths[p.date] || 0) + 1;
}
if (opt.show_all || !opt.day || !p.date || (p.date == opt.day)) {
if (this.hide_ended && p.t1 && (p.t1 < opt.now)) { ++opt.n_hidden; return; }
if (p.date != prev_date) {
prev_date = p.date;
prev_time = '';
frag.appendChild(_new_elem('div', 'new_day', KonOpas.pretty_date(p.t0 || p.date, konopas))).id = 'dt_' + p.date;
}
if (p.time != prev_time) {
prev_time = p.time;
frag.appendChild(document.createElement('hr'));
frag.appendChild(_new_elem('div', 'new_time', KonOpas.pretty_time(p.t0 || p.time, konopas)))
.setAttribute('data-day', p.date);
}
frag.appendChild(KonOpas.Item.new(p));
++opt.n_listed;
}
};
if (!opt) opt = {};
opt.show_all = (ls.length <= konopas.max_items_per_page);
opt.n_hidden = 0; opt.n_listed = 0;
opt.now = new Date(_now + 10*60000 - _now % (10*60000));
if (!opt.day || !konopas.program.days[opt.day]) {
var day_now = KonOpas.data_date(opt.now);
if (konopas.program.days[day_now]) opt.day = day_now;
else { opt.day = ''; for (opt.day in konopas.program.days) break; }
}
var prev_date = "", prev_time = "",
show_all = (ls.length <= konopas.max_items_per_page),
ls_by_day = {}, ls_day_lengths = {},
day_links = {},
frag = document.createDocumentFragment();
if (day) {
for (var d in konopas.program.days) {
ls_by_day[d] = ls.filter(function(p) { return p.date == d; });
ls_day_lengths[d] = ls_by_day[d].length;
}
} else ls_by_day = { '': ls };
if (ls.length > (show_id ? 1 : 0)) {
if (ls.length > (opt.id ? 1 : 0)) {
frag.appendChild(_new_elem('div', 'item_expander', '» '))
.appendChild(_new_elem('a', 'js-link', i18n.txt('Expand all')))
.id = 'item_expander_link';
}
for (var d in ls_by_day) {
if (!show_all && d && (d != day)) {
if (d < day) {
if (ls_day_lengths[d]) day_links['prev'] = d;
} else {
if (!day_links['next'] && ls_day_lengths[d]) day_links['next'] = d;
}
continue;
}
for (var i = 0, l = ls_by_day[d].length; i < l; ++i) {
var p = ls_by_day[d][i];
if (p.date != prev_date) {
prev_date = p.date;
prev_time = "";
frag.appendChild(_new_elem('div', 'new_day', KonOpas.pretty_date(p.date, konopas))).id = 'dt_' + p.date;
}
if (p.time != prev_time) {
prev_time = p.time;
frag.appendChild(document.createElement('hr'));
frag.appendChild(_new_elem('div', 'new_time', KonOpas.pretty_time(p.time, konopas)))
.setAttribute('data-day', p.date);
}
frag.appendChild(KonOpas.Item.new(p));
}
ls.forEach(_list_item, {hide_ended:opt.hide_ended});
if (!opt.n_listed && opt.n_hidden) {
day_lengths = {};
opt.n_hidden = 0; opt.n_listed = 0;
prev_date = ''; prev_time = '';
ls.forEach(_list_item, {hide_ended:false});
}

function _day_link(t) {
var d = day_links[t],
txt = i18n.txt('day_link', {
'D': KonOpas.parse_date(d).getDay(),
'N': ls_day_lengths[d]
'N': day_lengths[d],
'D': KonOpas.parse_date(d).getDay()
}),
link = _new_elem('a', 'day-link js-link', txt);
link.id = t + '_day_link';
link.onclick = function() {
if (t == 'next') window.scrollTo(0, 0);
KonOpas.Item.show_list(ls, show_id, d, in_prog_view);
opt.day = d;
KonOpas.Item.show_list(ls, opt);
};
return link;
}
if (day_links['prev']) frag.insertBefore(_day_link('prev'), frag.firstChild);
function _hidden_link() {
var txt = i18n.txt('hidden_link', {
'N': opt.n_hidden,
'T': KonOpas.pretty_time(opt.now, konopas),
'D': opt.now.getDay()
}),
link = _new_elem('a', 'day-link js-link', txt);
link.id = 'hidden_day_link';
link.onclick = function() {
opt.hide_ended = false;
opt.day = KonOpas.data_date(opt.now);
KonOpas.Item.show_list(ls, opt);
};
return link;
}
if (opt.day && !opt.show_all) for (var d in day_lengths) if (d in konopas.program.days) {
if (d < opt.day) day_links['prev'] = d;
else if ((d > opt.day) && !day_links['next']) day_links['next'] = d;
}
if (day_links['prev'] && !opt.n_hidden) frag.insertBefore(_day_link('prev'), frag.firstChild);
if (day_links['next']) frag.appendChild(_day_link('next'));
if (opt.n_hidden) frag.insertBefore(_hidden_link(), frag.firstChild);

var LS = _el('prog_ls');
while (LS.firstChild) LS.removeChild(LS.firstChild);
Expand Down Expand Up @@ -193,26 +216,34 @@ KonOpas.Item.show_list = function(ls, show_id, day, in_prog_view) {
if (el) el.classList.add("has_star");
}

if (show_id) {
var it = document.getElementById('p' + show_id);
if (opt.id) {
var it = document.getElementById('p' + opt.id);
if (it) {
it.parentNode.classList.add("expanded");
KonOpas.Item.show_extra(it, show_id);
KonOpas.Item.show_extra(it, opt.id);
if (ls.length > 1) it.scrollIntoView();
}
}

if (in_prog_view) {
if (opt.prog_view) {
var d_s = _el('day-sidebar'), d_n = _el('day-narrow'),
d_click = function(ev) {
var li = (ev || window.event).target,
d = li.getAttribute('data-day');
if (!d) return;
if (show_all) {
_el('dt_' + d).scrollIntoView();
KonOpas.Prog.focus_day(d);
opt.day = d;
if (opt.show_all) {
var dt = _el('dt_' + d);
if (dt) {
dt.scrollIntoView();
KonOpas.Prog.focus_day(d);
} else if (d < KonOpas.data_date(opt.now)) {
opt.hide_ended = false;
KonOpas.Item.show_list(ls, opt);
}
} else {
KonOpas.Item.show_list(ls, show_id, d, true);
opt.hide_ended = true;
KonOpas.Item.show_list(ls, opt);
}
},
d_set = function(div, len) {
Expand All @@ -221,16 +252,17 @@ KonOpas.Item.show_list = function(ls, show_id, day, in_prog_view) {
ul.onclick = d_click;
for (var d in konopas.program.days) {
var li = document.createElement('li');
li.textContent = konopas.program.days[d][len] + ' (' + (ls_day_lengths[d] || 0) + ')';
li.textContent = konopas.program.days[d][len] + ' (' + (day_lengths[d] || 0) + ')';
li.setAttribute('data-day', d);
if (d == day) li.className = 'selected';
if (d == opt.day) li.className = 'selected';
ul.appendChild(li);
}
div.innerHTML = '';
div.appendChild(ul);
};
if (d_s) d_set(d_s, 'long');
if (d_n) d_set(d_n, 'short');
konopas.program.show_filter_sum(ls, opt);
}

konopas.item.scroll.i = 0;
Expand Down
Loading

0 comments on commit 57f8865

Please sign in to comment.