diff --git a/Gruntfile.js b/Gruntfile.js
index 8f8eb2c5..b7097cbe 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -66,9 +66,18 @@ module.exports = function(grunt) {
'src/js/vendor/lib/jquery.js',
'src/js/vendor/lib/jquery.dataTables.js',
'src/js/vendor/*.js',
- 'src/js/*.js'
+ 'src/js/*.js',
+ '!src/js/vendor/clipboard.js',
+ '!src/js/clipboard-init.js'
],
dest: 'build/js/plugins.js'
+ },
+ clipboard: {
+ src: [
+ 'src/js/vendor/clipboard.js',
+ 'src/js/clipboard-init.js'
+ ],
+ dest: 'build/js/clipboard.min.js'
}
},
diff --git a/src/js/clipboard-init.js b/src/js/clipboard-init.js
new file mode 100644
index 00000000..06f4c3b7
--- /dev/null
+++ b/src/js/clipboard-init.js
@@ -0,0 +1,36 @@
+/* jshint browser:true */
+/* global Clipboard:true */
+
+(function() {
+ 'use strict';
+
+ var selectors = document.querySelectorAll('pre code[class^="lang-"]');
+
+ Array.prototype.forEach.call(selectors, function(selector){
+
+ var btnHtml = '
' +
+ 'Copy' +
+ '
';
+ selector.insertAdjacentHTML('beforebegin', btnHtml);
+
+ var clipboard = new Clipboard('.btn-clipboard', {
+ target: function (trigger) {
+ return trigger.parentNode.nextElementSibling;
+ }
+ });
+
+ clipboard.on('success', function (e) {
+ e.clearSelection();
+ selector.setAttribute('title', 'Copied!');
+ //e.trigger;
+ });
+
+ clipboard.on('error', function (/*e*/) {
+ var fallbackMsg = /Mac/i.test(navigator.userAgent) ? 'Press \u2318 to copy' : 'Press Ctrl-C to copy';
+ selector.setAttribute('title', fallbackMsg);
+ //e.trigger;
+ });
+
+ });
+
+})();
diff --git a/src/js/vendor/clipboard.js b/src/js/vendor/clipboard.js
new file mode 100644
index 00000000..040c5e00
--- /dev/null
+++ b/src/js/vendor/clipboard.js
@@ -0,0 +1,742 @@
+/*!
+ * clipboard.js v1.5.12
+ * https://zenorocha.github.io/clipboard.js
+ *
+ * Licensed MIT © Zeno Rocha
+ */
+(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Clipboard = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o