]> jfr.im git - irc/freenode/web-7.0.git/commitdiff
Add js to remove soft hyphens on text copy
authorSvante Bengtson <redacted>
Thu, 17 May 2018 09:14:48 +0000 (11:14 +0200)
committerChristel Dahlskjaer <redacted>
Thu, 24 May 2018 23:49:12 +0000 (00:49 +0100)
CONTRIBUTING.md
config/build.yml
package.json [changed mode: 0644->0755]
static/js/utils.js [new file with mode: 0755]
templates/base.html

index 998abaa4eaa1078db11e51c3b7fbdf556f9d1fec..034a61c8cb4906d162af039ac46120e30e9fb115 100644 (file)
@@ -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/)
 ### 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
index 7142fa37698b8fdaefb445ece251c3b5059ea1ee..4a5a957f1c4c4a3a8219991470084f466eb7cb12 100644 (file)
@@ -22,3 +22,7 @@
 - command: [postcss, -c, postcss.json]
   source: static/css
   output: out/static/css
 - 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
old mode 100644 (file)
new mode 100755 (executable)
index 4f97e6b..3a234d0
@@ -15,6 +15,8 @@
   "devDependencies": {
     "postcss-cli": "^2.6.0",
     "postcss-cssnext": "^2.6.0",
   "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 (executable)
index 0000000..152b0b2
--- /dev/null
@@ -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, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;'))
+  event.preventDefault()
+})
index 25f7f8672587124e1fd028f2c256914210c0fb6e..099e1c06ae04b075747b643cbe57b60f59e2a020 100644 (file)
@@ -38,5 +38,7 @@
         <a id="navigation"></a>
         {% include "footer.html" %}
     </div>
         <a id="navigation"></a>
         {% include "footer.html" %}
     </div>
+    {#- scripts last to avoid blocking rendering #}
+    <script src="{{ url_for("static/js/utils.js") }}?{{ git_hash }}" type="text/javascript"></script>
 </body>
 </html>
 </body>
 </html>