diff options
author | Rasmus Andersson <rasmus@notion.se> | 2020-04-10 01:35:55 +0300 |
---|---|---|
committer | Rasmus Andersson <rasmus@notion.se> | 2020-04-10 01:35:55 +0300 |
commit | 1cae97df77a17c3b59801df444c283e743e8d9ad (patch) | |
tree | 5151b1b1a10347a797b0adeb4a50d2148d1f9ac8 /docs/res/base.js | |
parent | 82a3b7425c2102634cb1a366c9755c5431e4ba30 (diff) | |
download | inter-1cae97df77a17c3b59801df444c283e743e8d9ad.tar.xz |
re-add prev lfs tracked files to docs
Diffstat (limited to 'docs/res/base.js')
-rw-r--r-- | docs/res/base.js | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/docs/res/base.js b/docs/res/base.js new file mode 100644 index 000000000..7d38721b0 --- /dev/null +++ b/docs/res/base.js @@ -0,0 +1,115 @@ + +function $$(query, el) { + return [].slice.call((el || document).querySelectorAll(query)) +} + +function $(query, el) { + return (el || document).querySelector(query) +} + +// fetchjson(url string) :Promise<Object> +// +var fetchjson = ( + typeof window.fetch == 'function' ? ( + function _fetchjson(url, cb) { + return window.fetch(url).then(function(r) { return r.json() }) + } + ) : + function _fetchjson(url, cb) { + return new Promise(function(resolve, reject) { + var r = new XMLHttpRequest() + r.addEventListener("load", function(){ + try { + resolve(JSON.parse(r.responseText)) + } catch (err) { + reject(err) + } + }) + r.addEventListener("error", function(ev) { + reject(ev.error || ev || new Error('network error')) + }) + r.open("GET", url) + r.send() + }) + } +) + + +// timeNow() :float +// +var timeNow = ( + window.performance !== undefined && window.performance.now ? function() { + return window.performance.now() + } : Date.now ? function() { + return Date.now() + } : function() { + return (new Date()).getTime() + } +) + + +var HUDNotification = { + el: $('#hud-notification'), + timer: null, + visible: false, + + show: function(message, duration) { + var n = this + n.el.firstChild.innerText = message + n.el.classList.add('visible') + if (n.visible) { + n.hide() + setTimeout(function(){ n.show(message, duration) }, 120) + return + } + n.visible = true + n.el.style.visibility = null + clearTimeout(n.timer) + n.timer = setTimeout(function(){ n.hide() }, duration || 1200) + }, + + hide: function() { + var n = this + if (n.visible) { + n.el.classList.remove('visible') + n.visible = false + n.el.style.visibility = 'hidden' + } + } +} + + +// InterDynamicTracking takes the font size in points or pixels and returns +// the compensating tracking in EM. +// +function InterDynamicTracking(fontSize) { + var a = -0.0223, b = 0.185, c = -0.1745; + // tracking = a + b * e ^ (c * fontSize) + return a + b * Math.pow(Math.E, c * fontSize) +} + +// InterDynamicLineHeight produces the line height for the given font size +// +function InterDynamicLineHeight(fontSize) { + var l = 1.4 + return Math.round(fontSize * l) +} + + +// Mac or not? Maybe a buggy Safari or a busted Chrome on Windows... +var isMac = false +if (!window.MSStream && + /mac|ipad|iphone|ipod/i.test(navigator.userAgent)) +{ + isMac = true + if (navigator.userAgent.indexOf('Safari') != -1 && + navigator.userAgent.indexOf('Chrome') == -1) + { + document.body.classList.add('safari') + } +} else if ( + navigator.userAgent.indexOf('Windows') != -1 && + navigator.userAgent.indexOf('Chrome') != -1 +) { + document.body.classList.add('chrome-win') +} |