1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-13 14:00:25 +00:00
mycorrhiza/static/common.js
Umar Getagazov 738948f752 Refactor shortcuts
A selection of great commit messages:

- "Safari is a great browser!" -- No one

  If in doubt, just stick overflow: hidden onto it. No, seriously, I
  just added it in Safari devtools and it worked. You'd think Apple has
  a competent team, right?

- Bully Safari into not triggering the Show status bar menu item

  If in doubt, just bully Safari. What is Safari gonna do? Tell Steve
  Jobs?
2022-08-21 18:01:57 +03:00

27 lines
1013 B
JavaScript

const $ = document.querySelector.bind(document)
const $$ = (...args) => Array.prototype.slice.call(document.querySelectorAll(...args))
const isMac = /Macintosh/.test(window.navigator.userAgent)
const arrToStr = a => Array.isArray(a) ? a.join('') : a
const strToArr = a => Array.isArray(a) ? a : [a]
const rrh = {
html(s, ...parts) {
s = s.reduce((acc, cur, i) => (`${acc}${cur}${parts[i] ? arrToStr(parts[i]) : ''}`), '')
const wrapper = document.createElement('div')
wrapper.innerHTML = s
return wrapper.children[0]
},
l10nMap: {},
l10n(text, translations) {
// Choose the translation on load to be consistent with the
// server-rendered interface.
if (translations) {
translations.en = text
this.l10nMap[text] = translations[navigator.languages
.map(lang => lang.split('-')[0])
.find(lang => translations[lang])] || text
}
return this.l10nMap[text] || text
},
}