]> jfr.im git - irc/freenode/web-7.0.git/blob - static/js/utils.js
honour navbar when scrolling to anchor
[irc/freenode/web-7.0.git] / static / js / utils.js
1 'use strict'
2
3 /**
4 * Removes soft hyphens from copied text
5 * @param {Object} event
6 * @return {Undefined}
7 */
8 document.addEventListener('copy', function (event) {
9 var oldText = window.getSelection().toString()
10 var newText = oldText.replace(/\u00AD/g, '')
11
12 event.clipboardData.setData('text/plain', newText)
13 event.clipboardData.setData('text/html', newText.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;'))
14 event.preventDefault()
15 })
16
17 /**
18 * Scroll the page to honour the fixed navbar when linked to an anchor
19 * @return {Undefined}
20 */
21 function shiftWindow () { if (window.location.hash) window.scrollBy(0, -50) };
22 window.addEventListener('hashchange', shiftWindow)
23 window.onload = shiftWindow