diff --git a/i18n/en.js b/i18n/en.js index 4ecc7e7..4305da3 100644 --- a/i18n/en.js +++ b/i18n/en.js @@ -4,7 +4,7 @@ n:function(d,k,o){if(isNaN(d[k]))throw new Error("MessageFormat: '"+k+"' isn't a v:function(d,k){i18n.c(d,k);return d[k]}, p:function(d,k,o,l,p){i18n.c(d,k);return d[k] in p?p[d[k]]:(k=i18n.lc[l](d[k]-o),k in p?p[k]:p.other)}, s:function(d,k,p){i18n.c(d,k);return d[k] in p?p[d[k]]:p.other}} -i18n["en"] = { +i18n["en"]={ "weekday_n":function(d){return i18n.p(d,"N",0,"en",{"0":"Sunday","1":"Monday","2":"Tuesday","3":"Wednesday","4":"Thursday","5":"Friday","6":"Saturday","other":"???"})}, "month_n":function(d){return i18n.p(d,"N",0,"en",{"0":"January","1":"February","2":"March","3":"April","4":"May","5":"June","6":"July","7":"August","8":"September","9":"October","10":"November","11":"December","other":"???"})}, "time_diff":function(d){return i18n.v(d,"T")+" "+i18n.p(d,"T_UNIT",0,"en",{"0":"seconds","1":"minutes","2":"hours","3":"days","4":"weeks","5":"months","6":"years","other":"???"})+" "+i18n.s(d,"T_PAST",{"true":"ago","other":"from now"})}, @@ -28,6 +28,7 @@ i18n["en"] = { "star_add":function(d){return "Add the "+i18n.p(d,"N",0,"en",{"one":"new item","other":i18n.n(d,"N")+" new items"})+" to my selection"}, "star_export_link":function(d){return "Export selection ("+i18n.p(d,"N",0,"en",{"one":"one item","other":i18n.n(d,"N")+" items"})+")"}, "star_hint":function(d){return "To \"star\" a program item, click on the square next to it. Your selections will be remembered, and shown in this view. You currently don't have any program items selected, so this list is empty."}, +"star_no_memory":function(d){return "For some reason, your localStorage is not enabled, so your selection will not be remembered between sessions. "+i18n.s(d,"SERVER",{"true":"Please login to enable persistent storage.","other":""})}, "filter_sum_id":function(d){return "Listing "+i18n.p(d,"N",0,"en",{"one":"one item: "+i18n.v(d,"TITLE"),"other":i18n.n(d,"N")+" items with id "+i18n.v(d,"ID")})}, "filter_sum":function(d){return "Listing "+i18n.p(d,"N",0,"en",{"one":"one "+i18n.v(d,"TAG")+" item","other":i18n.v(d,"ALL")+" "+i18n.n(d,"N")+" "+i18n.v(d,"TAG")+" items"})+" "+i18n.s(d,"GOT_DAY",{"true":"on "+i18n.v(d,"DAY"),"other":""})+" "+i18n.s(d,"GOT_AREA",{"true":"in "+i18n.v(d,"AREA"),"other":""})+" "+i18n.s(d,"GOT_Q",{"true":"matching the query "+i18n.v(d,"Q"),"other":""})}, "server_cmd_fail":function(d){return "The command \""+i18n.v(d,"CMD")+"\" failed."}, @@ -38,4 +39,4 @@ i18n["en"] = { "ical_hint":function(d){return "Note that changes you make in this guide may take some time to show in your external calendar software."}, "ical_make":function(d){return "To view your selection in your calendar app, you may also
"+i18n.v(d,"A_TAG")+"make it available in iCal (.ics) calendar format"}, "login_why":function(d){return "Once you've verified your e-mail address, you'll be able to sync your data between different clients (including external calendars), as well as vote & comment on items. After signing in, no information will be transmitted to these external services."}} -})(this); \ No newline at end of file +})(this); diff --git a/i18n/en.json b/i18n/en.json index a916afd..f4ef89b 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -23,6 +23,7 @@ "star_add": "Add the {N, plural, one{new item} other{# new items}} to my selection", "star_export_link": "Export selection ({N, plural, one{one item} other{# items}})", "star_hint": "To \"star\" a program item, click on the square next to it. Your selections will be remembered, and shown in this view. You currently don't have any program items selected, so this list is empty.", +"star_no_memory": "For some reason, your localStorage is not enabled, so your selection will not be remembered between sessions. {SERVER, select, true{Please login 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_DAY, select, true{on {DAY}} other{}} {GOT_AREA, select, true{in {AREA}} other{}} {GOT_Q, select, true{matching the query {Q}} other{}}", diff --git a/i18n/fi.js b/i18n/fi.js index 6d45ad8..9917c59 100644 --- a/i18n/fi.js +++ b/i18n/fi.js @@ -4,7 +4,7 @@ n:function(d,k,o){if(isNaN(d[k]))throw new Error("MessageFormat: '"+k+"' isn't a v:function(d,k){i18n.c(d,k);return d[k]}, p:function(d,k,o,l,p){i18n.c(d,k);return d[k] in p?p[d[k]]:(k=i18n.lc[l](d[k]-o),k in p?p[k]:p.other)}, s:function(d,k,p){i18n.c(d,k);return d[k] in p?p[d[k]]:p.other}} -i18n["fi"] = { +i18n["fi"]={ "Scroll up":function(d){return "Palaa ylös"}, "Next":function(d){return "Seuraavaksi"}, "My con":function(d){return "Minun con"}, @@ -48,6 +48,7 @@ i18n["fi"] = { "star_add":function(d){return "Lisää "+i18n.p(d,"N",0,"fi",{"one":"uusi valinta","other":i18n.n(d,"N")+" uutta valintaa"})+" valintoihini"}, "star_export_link":function(d){return "Vie valinnat ("+i18n.p(d,"N",0,"fi",{"one":"yksi valinta","other":i18n.n(d,"N")+" valintaa"})+")"}, "star_hint":function(d){return "\"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":function(d){return "Jostain syystä localStorage -välimuisti ei nyt toimi, joten valintasi eivät säily seuraavaan istuntoon. "+i18n.s(d,"SERVER",{"true":"Ole hyvä ja kirjaudu sisään säilyttääksesi valintasi.","other":""})}, "filter_sum_id":function(d){return "Listataan "+i18n.p(d,"N",0,"fi",{"one":"yksi ohjelma: "+i18n.v(d,"TITLE"),"other":i18n.n(d,"N")+" ohjelmaa tunnisteella "+i18n.v(d,"ID")})}, "filter_sum":function(d){return "Listataan "+i18n.p(d,"N",0,"fi",{"one":"yksi "+i18n.v(d,"TAG")+" ohjelma","other":i18n.v(d,"ALL")+" "+i18n.n(d,"N")+" "+i18n.v(d,"TAG")+" ohjelmaa"})+" "+i18n.s(d,"GOT_DAY",{"true":"päivänä "+i18n.v(d,"DAY"),"other":""})+" "+i18n.s(d,"GOT_AREA",{"true":"paikassa "+i18n.v(d,"AREA"),"other":""})+" "+i18n.s(d,"GOT_Q",{"true":"kyselylle "+i18n.v(d,"Q"),"other":""})}, "Votes":function(d){return "Äänet"}, @@ -72,4 +73,4 @@ i18n["fi"] = { "ical_hint":function(d){return "Huomaa että oppaassa tekemäsi muutokset saattavat päivittyä muuhun kalenteriohjelmaan vasta jonkin ajan kuluttua."}, "ical_make":function(d){return "Katsellaaksesi valintojasi kalenteriohjelmassasi, voit myös
"+i18n.v(d,"A_TAG")+"tehdä sen saataville iCal (.ics) -muodossa."}, "login_why":function(d){return "Vahvistettuasi sähköpostiosoitteesi voit synkronoida valintasi eri päätelaitteiden (mukaanlukien kalenteriohjelmien) kanssa sekä äänestää ja kommentoida ohjelmia. Ulkoisille palveluille ei kirjautumisen jälkeen lähetetä mitään tietoja."}} -})(this); \ No newline at end of file +})(this); diff --git a/i18n/fi.json b/i18n/fi.json index 2277d06..086d6f2 100644 --- a/i18n/fi.json +++ b/i18n/fi.json @@ -44,6 +44,7 @@ "star_add": "Lisää {N, plural, one{uusi valinta} other{# uutta valintaa}} valintoihini", "star_export_link": "Vie valinnat ({N, plural, one{yksi valinta} other{# valintaa}})", "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": "Jostain syystä localStorage -välimuisti ei nyt toimi, joten valintasi eivät säily seuraavaan istuntoon. {SERVER, select, true{Ole hyvä ja kirjaudu sisään 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_DAY, select, true{päivänä {DAY}} other{}} {GOT_AREA, select, true{paikassa {AREA}} other{}} {GOT_Q, select, true{kyselylle {Q}} other{}}", diff --git a/src/app.js b/src/app.js index d303acc..905d297 100644 --- a/src/app.js +++ b/src/app.js @@ -653,6 +653,7 @@ function show_star_view(opt) { set.sort(); var set_len = set.length; + var html = stars.persistent() ? '' : '

' + i18n_txt('star_no_memory', {'SERVER': !!server}); var star_list = stars.list(); star_list.sort(); var stars_len = star_list.length; @@ -660,7 +661,7 @@ function show_star_view(opt) { var set_link = '#star/set:' + star_list.join(','); if (set_len) { if (arrays_equal(set, star_list)) { - view.innerHTML = '

' + i18n_txt('star_export_this', {'THIS':set_link}) + html += '

' + i18n_txt('star_export_this', {'THIS':set_link}) + '

' + i18n_txt('star_export_share', { 'SHORT':link_to_short_url(location.href), 'QR':link_to_qr_code(location.href) }); @@ -669,7 +670,7 @@ function show_star_view(opt) { var n_same = array_overlap(set, star_list); var n_new = set_len - n_same; var n_bad = set_raw.length - set_len; - var html = '

' + i18n_txt('star_import_this', {'THIS':location.href}) + html += '

' + i18n_txt('star_import_this', {'THIS':location.href}) + '

' + i18n_txt('star_import_diff', { 'PREV':stars_len, 'NEW':n_new, 'SAME':n_same }); if (n_bad) html += ' ' + i18n_txt('star_import_bad', {'BAD':n_bad}); if (!stars_len || (n_same != stars_len)) { @@ -684,13 +685,11 @@ function show_star_view(opt) { } if (n_new) html += '

» ' + i18n_txt('star_add', {'N':n_new}) + ''; } - view.innerHTML = html; - var el_set = EL('star_set_set'); if (el_set) el_set.onclick = function() { stars.set(set); return true; }; var el_add = EL('star_set_add'); if (el_add) el_add.onclick = function() { stars.add(set); return true; }; } } else { - view.innerHTML = '

' + i18n_txt('star_hint'); + html += '

' + i18n_txt('star_hint'); EL("prog_ls").innerHTML = ''; } + view.innerHTML = html; } diff --git a/src/stars.js b/src/stars.js index f68b37b..05cef27 100644 --- a/src/stars.js +++ b/src/stars.js @@ -1,28 +1,34 @@ "use strict"; function Stars(id, opt) { - this.name = 'konopas.' + id + '.stars'; - opt = opt || {}; - this.store = opt.store || localStorage; + this.name = 'konopas.' + id + '.stars'; + this.store = opt.store || localStorage || sessionStorage || (new (function() { + var data = {}; + this.getItem = function(k) { return data[k]; }; + this.setItem = function(k, v) { data[k] = v; }; + })()); this.tag = opt.tag || 'has_star'; - this.server = false; this.data = this.read(); } Stars.prototype.read = function() { - return JSON.parse(this.store.getItem(this.name) || '{}'); + return JSON.parse(this.store && this.store.getItem(this.name) || '{}'); } Stars.prototype.write = function() { try { - this.store.setItem(this.name, JSON.stringify(this.data)); + if (this.store) this.store.setItem(this.name, JSON.stringify(this.data)); } catch (e) { if ((e.code != DOMException.QUOTA_EXCEEDED_ERR) || (this.store.length != 0)) { throw e; } } } +Stars.prototype.persistent = function() { + return this.store && ((this.store == localStorage) || this.server && this.server.connected); +} + Stars.prototype.list = function() { var list = []; if (this.data) for (var id in this.data) {