]> jfr.im git - irc/freenode/web-7.0.git/blobdiff - static/js/utils.js
honour navbar when scrolling to anchor
[irc/freenode/web-7.0.git] / static / js / utils.js
index 152b0b2498cd40e5e363f842e5f2d6dd5d610f96..06a5b872eed558d21adce117f46035553e811db2 100755 (executable)
@@ -1,13 +1,23 @@
+'use strict'
+
 /**
  * Removes soft hyphens from copied text
  * @param  {Object} event
  * @return {Undefined}
  */
 document.addEventListener('copy', function (event) {
-  let oldText = window.getSelection().toString()
-  let newText = oldText.replace(/\u00AD/g, '')
+  var oldText = window.getSelection().toString()
+  var newText = oldText.replace(/\u00AD/g, '')
 
   event.clipboardData.setData('text/plain', newText)
   event.clipboardData.setData('text/html', newText.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;'))
   event.preventDefault()
 })
+
+/**
+ * Scroll the page to honour the fixed navbar when linked to an anchor
+ * @return {Undefined}
+ */
+function shiftWindow () { if (window.location.hash) window.scrollBy(0, -50) };
+window.addEventListener('hashchange', shiftWindow)
+window.onload = shiftWindow