From: Svante Bengtson Date: Thu, 17 May 2018 09:14:48 +0000 (+0200) Subject: Add js to remove soft hyphens on text copy X-Git-Url: https://jfr.im/git/irc/freenode/web-7.0.git/commitdiff_plain/96af768f6cdee6ebdf6bbcd5de36164a3bdf737a?ds=inline Add js to remove soft hyphens on text copy --- diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 998abaa4e..034a61c8c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -80,3 +80,4 @@ A *.footerchild* should contain at least 3 items, it just look silly otherwise. ### JS JavaScript should be used sparsely and should not break the usability of the site for browsers without JavaScript - For style, follow [JavaScript Standard Style](https://standardjs.com/) +- Document with [jsdoc](http://usejsdoc.org/) at least to describe what every function does diff --git a/config/build.yml b/config/build.yml index 7142fa376..4a5a957f1 100644 --- a/config/build.yml +++ b/config/build.yml @@ -22,3 +22,7 @@ - command: [postcss, -c, postcss.json] source: static/css output: out/static/css +- command: [standard] +- command: [uglifyjs, -c, -m] + source: static/js + output: out/static/js diff --git a/package.json b/package.json old mode 100644 new mode 100755 index 4f97e6b3e..3a234d04a --- a/package.json +++ b/package.json @@ -15,6 +15,8 @@ "devDependencies": { "postcss-cli": "^2.6.0", "postcss-cssnext": "^2.6.0", - "postcss-csso": "^1.1.2" + "postcss-csso": "^1.1.2", + "standard": "^11.0.1", + "uglify-js": "^3.3.25" } -} +} \ No newline at end of file diff --git a/static/js/utils.js b/static/js/utils.js new file mode 100755 index 000000000..152b0b249 --- /dev/null +++ b/static/js/utils.js @@ -0,0 +1,13 @@ +/** + * 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, '') + + event.clipboardData.setData('text/plain', newText) + event.clipboardData.setData('text/html', newText.replace(/&/g, '&').replace(//g, '>')) + event.preventDefault() +}) diff --git a/templates/base.html b/templates/base.html index 25f7f8672..099e1c06a 100644 --- a/templates/base.html +++ b/templates/base.html @@ -38,5 +38,7 @@ {% include "footer.html" %} + {#- scripts last to avoid blocking rendering #} +