(function ($) { 'use strict'; function create(root, tools) { var config = JSON.parse(root.querySelector('.fi-visitor-audience-config').textContent); var feis = Number(root.dataset.feisId); var storageKey = 'fi-visitor-favorites-' + feis; var favorites = []; var information = null; var informationRequest = null; var scheduleReady = false; var scheduleError = false; var schedule = root.querySelector('[data-schedule-content]'); try { var stored = JSON.parse(localStorage.getItem(storageKey) || '[]'); if (Array.isArray(stored)) { favorites = stored.map(Number).filter(function (id, index, all) { return Number.isSafeInteger(id) && id > 0 && all.indexOf(id) === index; }); } } catch (error) { favorites = []; } function url(path) { return path + '?event=' + feis; } function syncStars() { $(root).find('[data-favorite-user]').each(function () { var selected = favorites.indexOf(Number(this.dataset.favoriteUser)) !== -1; $(this).toggleClass('is-selected', selected).attr('aria-pressed', String(selected)) .attr('aria-label', selected ? config.remove : config.add).text(selected ? '★' : '☆'); }); $(root).find('[data-favorites-count]').text(favorites.length); } function star(id) { return $('