From 7523a633d93a2506f74dea899e43a8ae4abe1ea3 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Wed, 11 Nov 2026 19:17:17 +0100 Subject: Serve 40C3 --- static/halfnarp.js | 103 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 80 insertions(+), 23 deletions(-) (limited to 'static/halfnarp.js') diff --git a/static/halfnarp.js b/static/halfnarp.js index e40c84e..aac34e4 100644 --- a/static/halfnarp.js +++ b/static/halfnarp.js @@ -102,14 +102,35 @@ function redraw_calendar(myuid, ids) { } }); calendar += 'END:VCALENDAR\r\n'; - $('.export-url-a').attr( 'href', "data:text/calendar;filename=39C3.ics," + encodeURIComponent(calendar) ); + $('.export-url-a').attr( 'href', "data:text/calendar;filename=40C3.ics," + encodeURIComponent(calendar) ); $('.export-url').removeClass( 'hidden' ); } +function update_event_state(elem) { + elem.setAttribute( + 'aria-pressed', + elem.classList.contains('selected') ? 'true' : 'false' + ); +} + +function update_size_aria() { + document.querySelector('.vsmallboxes') + .setAttribute('aria-pressed', + document.body.classList.contains('size-small')); + + document.querySelector('.vmediumboxes') + .setAttribute('aria-pressed', + document.body.classList.contains('size-medium')); + + document.querySelector('.vlargeboxes') + .setAttribute('aria-pressed', + document.body.classList.contains('size-large')); +} + function do_the_halfnarp() { // var halfnarpAPI = 'talks_36C3.json'; var halfnarpAPI = '/-/talkpreferences'; - var halfnarpCorrs = 'corr_array_39c3.json'; + var halfnarpCorrs = 'corr_array_40c3.json'; var halfnarpPubAPI = halfnarpAPI + '/public/'; var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0)); window.top.all_events = new Object(); @@ -117,6 +138,8 @@ function do_the_halfnarp() { var myuid, mypid, newfriend = new Object(); var allhours = ['10', '11','12','13','14','15','16','17','18','19','20','21','22','23','00','01','02','03']; + update_size_aria(); + $('.narpr_done').click( function(ev) { $('.narpr').toggleClass('hidden', true); if (!window.narpr_alerted) { @@ -157,13 +180,17 @@ function do_the_halfnarp() { $('.narpr').on({ 'touchend' : function(ev) { if (!window.touch_valid) return; + var ev = $('#event_'+window.narpr_event); if (window.touch_curX > window.touch_startX + 100) { - $('#event_'+window.narpr_event).toggleClass('selected', true); + ev.toggleClass('selected', true); + update_event_state(ev[0]); set_random_event(); } if (window.touch_curX < window.touch_startX - 100) { - $('#event_'+window.narpr_event).toggleClass('selected', false); - $('#event_'+window.narpr_event).toggleClass('rejected', true); + + ev.toggleClass('selected', false); + ev.toggleClass('rejected', true); + update_event_state(ev[0]); set_random_event(); } @@ -179,8 +206,8 @@ function do_the_halfnarp() { return $(this).attr('event_id'); }).get(); try { - localStorage['39C3-halfnarp'] = ids; - myapi = localStorage.getItem('39C3-halfnarp-api'); + localStorage['40C3-halfnarp'] = ids; + myapi = localStorage.getItem('40C3-halfnarp-api'); if (myapi) { myapi = myapi.replace(/.*?:\//g, ""); myapi = 'https:/' + myapi.replace(/.*?:\//g, ""); @@ -207,9 +234,9 @@ function do_the_halfnarp() { $('.info').text('submitted'); $('.info').removeClass('hidden'); try { - localStorage['39C3-halfnarp-api'] = data['update_url']; - localStorage['39C3-halfnarp-pid'] = mypid = data['hashed_uid']; - localStorage['39C3-halfnarp-uid'] = myuid = data['uid']; + localStorage['40C3-halfnarp-api'] = data['update_url']; + localStorage['40C3-halfnarp-pid'] = mypid = data['hashed_uid']; + localStorage['40C3-halfnarp-uid'] = myuid = data['uid']; window.location.hash = mypid; } catch(err) {} }, 'json' ).fail(function() { @@ -225,9 +252,9 @@ function do_the_halfnarp() { contentType: "application/json", dataType: 'json', }).done(function(data) { - localStorage['39C3-halfnarp-uid'] = myuid = data['uid']; - if( localStorage['39C3-halfnarp-pid'] ) { - window.location.hash = localStorage['39C3-halfnarp-pid']; + localStorage['40C3-halfnarp-uid'] = myuid = data['uid']; + if( localStorage['40C3-halfnarp-pid'] ) { + window.location.hash = localStorage['40C3-halfnarp-pid']; } $('.info').text('updated'); $('.info').removeClass('hidden'); @@ -254,28 +281,42 @@ function do_the_halfnarp() { document.querySelectorAll('.event').forEach(elem => elem.style.display = "initial"); }; + document.querySelectorAll( + '.vtrack, .vlang, .vsmallboxes, .vmediumboxes, .vlargeboxes' + ).forEach(function(elem) { + elem.addEventListener('keydown', function(event) { + if (event.key === 'Enter' || event.key === ' ') { + event.preventDefault(); + elem.click(); + } + }); + }); + /* Add click handlers for event div sizers */ document.querySelector('.vsmallboxes').onclick = function() { document.body.classList.remove('size-medium', 'size-large'); document.body.classList.add('size-small'); + update_size_aria(); }; document.querySelector('.vmediumboxes').onclick = function() { document.body.classList.remove('size-small', 'size-large'); document.body.classList.add('size-medium'); + update_size_aria(); }; document.querySelector('.vlargeboxes').onclick = function() { document.body.classList.remove('size-small', 'size-medium'); document.body.classList.add('size-large'); + update_size_aria(); }; /* Add de-highlighter on touch interface devices */ if( isTouch ) { document.body.onclick = function() { - document.querySelector('.highlighted').forEach(elem => elem.classList.remove('highlighted')); + for (elem of document.querySelectorAll('.highlighted')) {elem.classList.remove('highlighted'); } }; - document.querySelector('.touch-only').forEach(elem => elem.classList.remove('hidden')); + for (elem of document.querySelectorAll('.touch-only')) { elem.classList.remove('hidden'); } } /* Add callbacks for view selector */ @@ -287,8 +328,16 @@ function do_the_halfnarp() { document.querySelector('.vday4').onclick = function() { toggle_grid(4); }; document.querySelector('.vdays').onclick = function() { toggle_grid(5); }; } - document.querySelector('.vlang').onclick = function() { document.body.classList.toggle('languages'); }; - document.querySelector('.vtrack').onclick = function() { document.body.classList.toggle('all-tracks'); }; + + document.querySelector('.vlang').onclick = function() { + document.body.classList.toggle('languages'); + this.setAttribute('aria-pressed', document.body.classList.contains('languages')); + }; + document.querySelector('.vtrack').onclick = function() { + document.body.classList.toggle('all-tracks'); + this.setAttribute('aria-pressed', document.body.classList.contains('all-tracks')); + }; + document.querySelector('.vnarpr').onclick = function() { $('.narpr').toggleClass('hidden'); set_random_event(); }; if (0) { @@ -311,10 +360,10 @@ function do_the_halfnarp() { /* If we've been here before, try to get local preferences. They are authoratative */ var selection = [], friends = { }; try { - selection = localStorage['39C3-halfnarp'] || []; - friends = localStorage['39C3-halfnarp-friends'] || { }; - myuid = localStorage['39C3-halfnarp-uid'] || ''; - mypid = localStorage['39C3-halfnarp-pid'] || ''; + selection = localStorage['40C3-halfnarp'] || []; + friends = localStorage['40C3-halfnarp-friends'] || { }; + myuid = localStorage['40C3-halfnarp-uid'] || ''; + mypid = localStorage['40C3-halfnarp-pid'] || ''; } catch(err) { } @@ -328,12 +377,16 @@ function do_the_halfnarp() { /* Take copy of hidden event template div and select them, if they're in list of previous prereferences */ var t = $( '#template' ).clone(true); + t.attr({ role: 'button', tabindex: '0', 'aria-pressed': 'false' }); + t.on('keydown', function(event) { if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); $(this).trigger('click'); } }); + var event_id = item.event_id.toString(); t.addClass('event ' + ' lang_' + (item.language || 'en')); t.attr('event_id', item.event_id.toString()); t.attr('id', 'event_' + item.event_id.toString()); if( selection && selection.indexOf(item.event_id) != -1 ) { t.addClass( 'selected' ); + update_event_state(t[0]); } /* Sort textual info into event div */ @@ -357,7 +410,7 @@ function do_the_halfnarp() { if( hour > 23) hour -= 24; - /* Fix up room for 39C3 */ + /* Fix up room for 40C3 */ room = (item.room_id || '').toString().replace('1','room1').replace('2','room2').replace('3','room3'); /* Apply attributes to sort events into calendar */ @@ -373,6 +426,7 @@ function do_the_halfnarp() { if( isTouch ) { if ( $( this ).hasClass('highlighted') ) { $( this ).toggleClass('selected'); + update_event_state(this); $('.info').addClass('hidden'); } else { $('.highlighted').removeClass('highlighted'); @@ -380,6 +434,7 @@ function do_the_halfnarp() { } } else { $( this ).toggleClass('selected'); + update_event_state(this); $('.info').addClass('hidden'); } event.stopPropagation(); @@ -442,7 +497,7 @@ function do_the_halfnarp() { $.getJSON( halfnarpPubAPI + friends.pid, { format: 'json' }) .done(function( data ) { friend.prefs = data.talk_ids; - localStorage['39C3-halfnarp-friends'] = friends; + localStorage['40C3-halfnarp-friends'] = friends; update_friends(); }); } @@ -476,6 +531,8 @@ function do_the_halfnarp() { /* toggle_corr_mode(); */ break; } + document.querySelector('.vlang').setAttribute('aria-pressed', document.body.classList.contains('languages')); + document.querySelector('.vtrack').setAttribute('aria-pressed', document.body.classList.contains('all-tracks')); }; } -- cgit v1.3