forked from Martinomagnifico/reveal.js-copycode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Martino
committed
May 31, 2020
1 parent
a686964
commit a2b1bd2
Showing
4 changed files
with
199 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.slides { | ||
opacity: 0; | ||
-webkit-transition: opacity .5s ease; | ||
-o-transition: opacity .5s ease; | ||
transition: opacity .5s ease; } | ||
|
||
.reveal.ready .slides { | ||
opacity: 1; } | ||
|
||
.backgrounds { | ||
background: #1a1626; } | ||
|
||
@font-face { | ||
font-family: 'JetBrains Mono'; | ||
src: url("jetbrains-mono/JetBrainsMono-Regular.eot"); | ||
/* IE9 Compat Modes */ | ||
src: local("JetBrains Mono"), local("JetBrainsMono-Regular"), url("jetbrains-mono/JetBrainsMono-Regular.eot?#iefix") format("embedded-opentype"), url("jetbrains-mono/JetBrainsMono-Regular.woff2") format("woff2"), url("jetbrains-mono/JetBrainsMono-Regular.woff") format("woff"), url("jetbrains-mono/JetBrainsMono-Regular.ttf") format("truetype"); | ||
/* Safari, Android, iOS */ | ||
font-style: normal; } | ||
|
||
:root { | ||
--code-font: 'JetBrains Mono', monospace; } | ||
|
||
.reveal pre, .reveal code { | ||
font-family: 'JetBrains Mono', monospace; } | ||
|
||
.reveal code { | ||
line-height: 1.5; } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,110 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<title>CopyCode.js for Reveal.js</title> | ||
<title>CopyCode for Reveal.js</title> | ||
<meta name="description" content=""> | ||
<meta name="author" content="Martinomagnifico"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | ||
<link rel="stylesheet" href="dist/reset.css"> | ||
<link rel="stylesheet" href="dist/reveal.css"> | ||
<link rel="stylesheet" href="dist/theme/black.css"> | ||
<style> | ||
.slides { | ||
opacity: 0; | ||
transition: opacity .5s ease; | ||
} | ||
.reveal.ready .slides { | ||
opacity: 1; | ||
} | ||
</style> | ||
<link rel="stylesheet" href="plugin/highlight/monokai.css"> | ||
<link rel="stylesheet" href="css/jetbrains-mono.css"> | ||
<link rel="stylesheet" href="css/demo.css"> | ||
<!-- Styles for CopyCode button--> | ||
<link rel="stylesheet" href="plugin/copycode/copycode.css"> | ||
<style> | ||
.backgrounds { | ||
background: #1a1626; | ||
} | ||
|
||
|
||
</style> | ||
</head> | ||
<body> | ||
</head> | ||
|
||
<body> | ||
<div class="reveal"> | ||
<div class="slides"> | ||
<section> | ||
<h1>CopyCode</h1> | ||
<h3>for Reveal.js</h3><br> | ||
<pre><code class="hljs javascript" data-line-numbers>let why = `Because we always want to copy code | ||
<div class="slides"> | ||
<section> | ||
<h1>CopyCode</h1> | ||
<h3>for Reveal.js</h3><br> | ||
<pre><code class="hljs javascript" data-line-numbers>let why = `Because we always want to copy code | ||
during our presentations, right?`</code></pre> | ||
</section> | ||
<section> | ||
<h4>Works out of the box</h4> | ||
<pre><code class="hljs javascript" data-line-numbers>const http = require("http"); | ||
</section> | ||
<section> | ||
<h4>Works out of the box</h4> | ||
<pre><code class="hljs javascript" data-line-numbers>const http = require("http"); | ||
http.createServer(function (request, response) { | ||
response.writeHead(200, {"Content-Type": "text/plain"}); | ||
response.end("Hello World\n"); | ||
}).listen(8081); | ||
</code></pre> | ||
<p>A 'Copy' button is automatically added to any <pre> code block.</p> | ||
</section> | ||
<section> | ||
<h4>Override button text and timing</h4> | ||
<pre><code class="hljs javascript" data-line-numbers>… | ||
</code></pre><small>A 'Copy' button is automatically added to any <pre> code block.</small> | ||
</section> | ||
<section> | ||
<h4>Override button text and timing</h4> | ||
<pre><code class="hljs javascript" data-line-numbers>… | ||
Reveal.initialize({ | ||
copycode: { | ||
copy: "Copy", | ||
copied: "Copied!", | ||
timeout: 1000 | ||
}, | ||
plugins: [ …</code></pre> | ||
<p>Override these global default values in the Reveal.js config. The timeout is the time in milliseconds for the "Copied!"-state to revert back to "Copy".</p> | ||
</section> | ||
<section> | ||
<h4>Override styling</h4> | ||
<pre><code class="hljs javascript" data-line-numbers>… | ||
plugins: [ …</code></pre><small>Override these global default values in the Reveal.js config. The timeout is the time in milliseconds for the "Copied!"-state to revert back to "Copy".</small> | ||
</section> | ||
<section> | ||
<h4>Override styling</h4> | ||
<pre><code class="hljs javascript" data-line-numbers>… | ||
Reveal.initialize({ | ||
copycode: { | ||
copybg: "orange", | ||
copiedbg: "green", | ||
copycolor: "black", | ||
copiedcolor: "white" | ||
}, | ||
plugins: [ …</code></pre> | ||
<p>Override these global default values in the Reveal.js config.</p> | ||
</section> | ||
<section> | ||
<h4>Turn it off or customize per element</h4> | ||
<pre data-cc="false"><code class="hljs html" data-line-numbers><pre data-cc="false"> | ||
plugins: [ …</code></pre><small>Override these global default values in the Reveal.js config.</small> | ||
</section> | ||
<section> | ||
<h4>Turn it off or customize per element</h4> | ||
<pre data-cc="false"><code class="hljs html" data-line-numbers><pre data-cc="false"> | ||
<code> | ||
Here is the code | ||
</code> | ||
</pre></code></pre> | ||
<pre data-cc-copy="Copy HTML" data-cc-copied="Done"><code class="hljs html" data-line-numbers><pre data-cc-copy="Copy HTML" data-cc-copied="Done"> | ||
<pre data-cc-copy="Copy HTML" data-cc-copied="Done"><code class="hljs html" data-line-numbers><pre data-cc-copy="Copy HTML" data-cc-copied="Done"> | ||
<code> | ||
Here is the code | ||
</code> | ||
</pre> | ||
</code></pre> | ||
</section> | ||
<section> | ||
<h4>Manual styling</h4> | ||
<p>Just edit the provided stylesheet.</p> | ||
<pre style="white-space: pre-wrap"><code class="hljs html" data-line-numbers>… | ||
</section> | ||
<section> | ||
<h4>Manual styling</h4> | ||
<p>Just edit the provided stylesheet.</p> | ||
<pre style="white-space: pre-wrap"><code class="hljs html" data-line-numbers>… | ||
<link rel="stylesheet" href="assets/js/revealjs/plugin/copycode/copycode.css"> | ||
…</code></pre> | ||
</section> | ||
<section> | ||
<h4>Thanks</h4> | ||
<ul> | ||
<li>Hakim El Hattab for <a href="https://revealjs.com" target="_blank">Reveal.js</a></li> | ||
<li>Zeno Rocha, for <a href="https://clipboardjs.com" target="_blank">Clipboard.js</a></li> | ||
<li>Philipp Nurullin and Jetbrains for <a href="https://www.jetbrains.com/lp/mono/" target="_blank">JetBrains Mono</a></li> | ||
</ul> | ||
</section> | ||
</div> | ||
</section> | ||
<section> | ||
<h4>Thanks</h4> | ||
<ul> | ||
<li>Hakim El Hattab for <a href="https://revealjs.com" target="_blank">Reveal.js</a></li> | ||
<li>Zeno Rocha, for <a href="https://clipboardjs.com" target="_blank">Clipboard.js</a></li> | ||
<li>Philipp Nurullin and Jetbrains for <a href="https://www.jetbrains.com/lp/mono/" target="_blank">JetBrains Mono</a></li> | ||
</ul> | ||
</section> | ||
</div> | ||
</div> | ||
<script src="dist/reveal.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js"></script> | ||
<script src="plugin/highlight/highlight.js"></script> | ||
<script src="dist/reveal.js"></script> | ||
<script src="plugin/copycode/copycode.js"></script> | ||
<script src="plugin/highlight/highlight.js"></script> | ||
<script> | ||
Reveal.initialize({ | ||
transition: 'convex', | ||
history: true, | ||
copycode: { | ||
timeout: 1200 | ||
}, | ||
plugins: [ RevealHighlight, CopyCode ] | ||
}); | ||
Reveal.initialize({ | ||
transition: "convex", | ||
copycode: { | ||
timeout: 1200 | ||
}, | ||
plugins: [ | ||
CopyCode, | ||
RevealHighlight | ||
] | ||
}); | ||
</script> | ||
</body> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
|
||
/***************************************************************** | ||
* @author: Martijn De Jongh (Martino), [email protected] | ||
* https://github.com/Martinomagnifico | ||
* | ||
* CopyCode.js for Reveal.js | ||
* Version 1.0.1 | ||
* | ||
* @license | ||
* MIT licensed | ||
* | ||
* Thanks to: | ||
* - Hakim El Hattab, Reveal.js | ||
******************************************************************/ | ||
|
||
|
||
var Plugin = function Plugin() { | ||
var getCodeBlocks = function getCodeBlocks(codeblocks, options) { | ||
var styleButton = function styleButton(button, codeblock) { | ||
var codeblockData = codeblock.dataset; | ||
button.textContent = codeblockData.ccCopy ? codeblockData.ccCopy : options.copy; | ||
button.setAttribute("data-cc-copied", codeblockData.ccCopied ? codeblockData.ccCopied : options.copied); | ||
["data-cc-copy", "data-cc-copied"].forEach(function (attribute) { | ||
return codeblock.removeAttribute(attribute); | ||
}); | ||
button.style.backgroundColor = options.copybg; | ||
button.style.color = options.copycolor; | ||
}; | ||
|
||
var buildStructure = function buildStructure(codeblock) { | ||
var wrapper = document.createElement("div"); | ||
wrapper.classList.add("codeblock"); | ||
codeblock.parentNode.insertBefore(wrapper, codeblock); | ||
wrapper.appendChild(codeblock); | ||
var button = document.createElement("button"); | ||
styleButton(button, codeblock); | ||
wrapper.insertBefore(button, codeblock); | ||
}; | ||
|
||
codeblocks.forEach(function (codeblock) { | ||
if (codeblock.getAttribute("data-cc") && codeblock.getAttribute("data-cc") === "false") { | ||
return; | ||
} else { | ||
if (!codeblock.parentNode.classList.contains("codeblock")) { | ||
buildStructure(codeblock); | ||
} | ||
} | ||
}); | ||
var clipboard = new ClipboardJS(".codeblock > button", { | ||
target: function target(trigger) { | ||
return trigger.nextElementSibling; | ||
} | ||
}); | ||
clipboard.on("success", function (e) { | ||
var button = e.trigger; | ||
e.clearSelection(); | ||
button.setAttribute("data-text-original", button.innerHTML); | ||
button.innerHTML = button.getAttribute("data-cc-copied"); | ||
button.style.backgroundColor = options.copiedbg; | ||
button.style.color = options.copiedcolor; | ||
button.setAttribute("disabled", true); | ||
setTimeout(function () { | ||
button.style.backgroundColor = options.copybg; | ||
button.style.color = options.copycolor; | ||
button.innerHTML = button.getAttribute("data-text-original"); | ||
button.removeAttribute("disabled"); | ||
}, options.timeout); | ||
}); | ||
}; | ||
|
||
var init = function init(deck) { | ||
var defaultOptions = { | ||
timeout: 1000, | ||
copy: "Copy", | ||
copied: "Copied!", | ||
copybg: "orange", | ||
copiedbg: "green", | ||
copycolor: "black", | ||
copiedcolor: "white" | ||
}; | ||
|
||
var defaults = function defaults(options, defaultOptions) { | ||
for (var i in defaultOptions) { | ||
if (!options.hasOwnProperty(i)) { | ||
options[i] = defaultOptions[i]; | ||
} | ||
} | ||
}; | ||
|
||
var options = deck.getConfig().copycode || {}; | ||
defaults(options, defaultOptions); | ||
|
||
if (typeof ClipboardJS === "function") { | ||
var codeblocks = deck.getRevealElement().querySelectorAll("pre"); | ||
|
||
if (codeblocks.length > 0) { | ||
getCodeBlocks(codeblocks, options); | ||
} | ||
} else { | ||
console.log("Clipboard.js did not load"); | ||
} | ||
}; | ||
|
||
return { | ||
id: 'copycode', | ||
init: init | ||
}; | ||
}; | ||
|
||
export default Plugin; |