Skip to content

Commit

Permalink
Secret copy link to clipboard helper
Browse files Browse the repository at this point in the history
  • Loading branch information
polytypic committed Jun 11, 2018
1 parent df823cc commit 0744ac5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion docs/fw/init-playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
clearTimeout(to)
to = setTimeout(function() {
var cm = document.querySelector('.CodeMirror.cm-s-default').CodeMirror
cm.lineNumbers = true
if (cm) {
var text = cm.getValue()
history.replaceState(
Expand All @@ -48,5 +47,26 @@
}
}, 250)
}

var copyToClipboard = document.querySelector('#copy-to-clipboard')
if (copyToClipboard) {
function copyTextToClipboard(text) {
var textArea = document.createElement('textarea')
textArea.value = text
document.body.appendChild(textArea)
textArea.focus()
textArea.select()
try {
document.execCommand('copy')
} finally {
document.body.removeChild(textArea)
}
}
copyToClipboard.onclick = function(e) {
e.preventDefault()
e.stopPropagation()
copyTextToClipboard(window.location.href)
}
}
}
})()
2 changes: 1 addition & 1 deletion docs/playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<script type="text/javascript">(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');ga('create','UA-52808982-2','auto');ga('send','pageview');</script>
</head>
<body class="markdown-body">
<h1>Partial Lenses Playground &middot; <a href="https://gitter.im/calmm-js/chat"><img src="https://img.shields.io/gitter/room/calmm-js/chat.js.svg" alt="Gitter"></a> <a href="https://github.com/calmm-js/partial.lenses"><img src="https://img.shields.io/github/stars/calmm-js/partial.lenses.svg?style=social" alt="GitHub stars"></a> <a href="https://www.npmjs.com/package/partial.lenses"><img src="https://img.shields.io/npm/dm/partial.lenses.svg" alt="npm"></a></h1>
<h1><a id="copy-to-clipboard" title="Click to copy link to clipboard">Partial Lenses Playground</a> &middot; <a href="https://gitter.im/calmm-js/chat"><img src="https://img.shields.io/gitter/room/calmm-js/chat.js.svg" alt="Gitter"></a> <a href="https://github.com/calmm-js/partial.lenses"><img src="https://img.shields.io/github/stars/calmm-js/partial.lenses.svg?style=social" alt="GitHub stars"></a> <a href="https://www.npmjs.com/package/partial.lenses"><img src="https://img.shields.io/npm/dm/partial.lenses.svg" alt="npm"></a></h1>
<pre id="playground"><code class="hljs lang-js">L.modify([L.rewrite(R.join("")), L.elems, L.when((_, i) => i)],
c => "-" + c,
"playtime")
Expand Down

0 comments on commit 0744ac5

Please sign in to comment.