aboutsummaryrefslogtreecommitdiff
path: root/node_modules/prismjs/plugins/toolbar
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/prismjs/plugins/toolbar')
-rw-r--r--node_modules/prismjs/plugins/toolbar/prism-toolbar.css58
-rw-r--r--node_modules/prismjs/plugins/toolbar/prism-toolbar.js137
-rw-r--r--node_modules/prismjs/plugins/toolbar/prism-toolbar.min.js1
3 files changed, 196 insertions, 0 deletions
diff --git a/node_modules/prismjs/plugins/toolbar/prism-toolbar.css b/node_modules/prismjs/plugins/toolbar/prism-toolbar.css
new file mode 100644
index 00000000..2b234e19
--- /dev/null
+++ b/node_modules/prismjs/plugins/toolbar/prism-toolbar.css
@@ -0,0 +1,58 @@
+div.code-toolbar {
+ position: relative;
+}
+
+div.code-toolbar > .toolbar {
+ position: absolute;
+ top: .3em;
+ right: .2em;
+ transition: opacity 0.3s ease-in-out;
+ opacity: 0;
+}
+
+div.code-toolbar:hover > .toolbar {
+ opacity: 1;
+}
+
+div.code-toolbar > .toolbar .toolbar-item {
+ display: inline-block;
+}
+
+div.code-toolbar > .toolbar a {
+ cursor: pointer;
+}
+
+div.code-toolbar > .toolbar button {
+ background: none;
+ border: 0;
+ color: inherit;
+ font: inherit;
+ line-height: normal;
+ overflow: visible;
+ padding: 0;
+ -webkit-user-select: none; /* for button */
+ -moz-user-select: none;
+ -ms-user-select: none;
+}
+
+div.code-toolbar > .toolbar a,
+div.code-toolbar > .toolbar button,
+div.code-toolbar > .toolbar span {
+ color: #bbb;
+ font-size: .8em;
+ padding: 0 .5em;
+ background: #f5f2f0;
+ background: rgba(224, 224, 224, 0.2);
+ box-shadow: 0 2px 0 0 rgba(0,0,0,0.2);
+ border-radius: .5em;
+}
+
+div.code-toolbar > .toolbar a:hover,
+div.code-toolbar > .toolbar a:focus,
+div.code-toolbar > .toolbar button:hover,
+div.code-toolbar > .toolbar button:focus,
+div.code-toolbar > .toolbar span:hover,
+div.code-toolbar > .toolbar span:focus {
+ color: inherit;
+ text-decoration: none;
+}
diff --git a/node_modules/prismjs/plugins/toolbar/prism-toolbar.js b/node_modules/prismjs/plugins/toolbar/prism-toolbar.js
new file mode 100644
index 00000000..93294514
--- /dev/null
+++ b/node_modules/prismjs/plugins/toolbar/prism-toolbar.js
@@ -0,0 +1,137 @@
+(function(){
+ if (typeof self === 'undefined' || !self.Prism || !self.document) {
+ return;
+ }
+
+ var callbacks = [];
+ var map = {};
+ var noop = function() {};
+
+ Prism.plugins.toolbar = {};
+
+ /**
+ * Register a button callback with the toolbar.
+ *
+ * @param {string} key
+ * @param {Object|Function} opts
+ */
+ var registerButton = Prism.plugins.toolbar.registerButton = function (key, opts) {
+ var callback;
+
+ if (typeof opts === 'function') {
+ callback = opts;
+ } else {
+ callback = function (env) {
+ var element;
+
+ if (typeof opts.onClick === 'function') {
+ element = document.createElement('button');
+ element.type = 'button';
+ element.addEventListener('click', function () {
+ opts.onClick.call(this, env);
+ });
+ } else if (typeof opts.url === 'string') {
+ element = document.createElement('a');
+ element.href = opts.url;
+ } else {
+ element = document.createElement('span');
+ }
+
+ element.textContent = opts.text;
+
+ return element;
+ };
+ }
+
+ callbacks.push(map[key] = callback);
+ };
+
+ /**
+ * Post-highlight Prism hook callback.
+ *
+ * @param env
+ */
+ var hook = Prism.plugins.toolbar.hook = function (env) {
+ // Check if inline or actual code block (credit to line-numbers plugin)
+ var pre = env.element.parentNode;
+ if (!pre || !/pre/i.test(pre.nodeName)) {
+ return;
+ }
+
+ // Autoloader rehighlights, so only do this once.
+ if (pre.parentNode.classList.contains('code-toolbar')) {
+ return;
+ }
+
+ // Create wrapper for <pre> to prevent scrolling toolbar with content
+ var wrapper = document.createElement("div");
+ wrapper.classList.add("code-toolbar");
+ pre.parentNode.insertBefore(wrapper, pre);
+ wrapper.appendChild(pre);
+
+ // Setup the toolbar
+ var toolbar = document.createElement('div');
+ toolbar.classList.add('toolbar');
+
+ if (document.body.hasAttribute('data-toolbar-order')) {
+ callbacks = document.body.getAttribute('data-toolbar-order').split(',').map(function(key) {
+ return map[key] || noop;
+ });
+ }
+
+ callbacks.forEach(function(callback) {
+ var element = callback(env);
+
+ if (!element) {
+ return;
+ }
+
+ var item = document.createElement('div');
+ item.classList.add('toolbar-item');
+
+ item.appendChild(element);
+ toolbar.appendChild(item);
+ });
+
+ // Add our toolbar to the currently created wrapper of <pre> tag
+ wrapper.appendChild(toolbar);
+ };
+
+ registerButton('label', function(env) {
+ var pre = env.element.parentNode;
+ if (!pre || !/pre/i.test(pre.nodeName)) {
+ return;
+ }
+
+ if (!pre.hasAttribute('data-label')) {
+ return;
+ }
+
+ var element, template;
+ var text = pre.getAttribute('data-label');
+ try {
+ // Any normal text will blow up this selector.
+ template = document.querySelector('template#' + text);
+ } catch (e) {}
+
+ if (template) {
+ element = template.content;
+ } else {
+ if (pre.hasAttribute('data-url')) {
+ element = document.createElement('a');
+ element.href = pre.getAttribute('data-url');
+ } else {
+ element = document.createElement('span');
+ }
+
+ element.textContent = text;
+ }
+
+ return element;
+ });
+
+ /**
+ * Register the toolbar with Prism.
+ */
+ Prism.hooks.add('complete', hook);
+})();
diff --git a/node_modules/prismjs/plugins/toolbar/prism-toolbar.min.js b/node_modules/prismjs/plugins/toolbar/prism-toolbar.min.js
new file mode 100644
index 00000000..17cee962
--- /dev/null
+++ b/node_modules/prismjs/plugins/toolbar/prism-toolbar.min.js
@@ -0,0 +1 @@
+!function(){if("undefined"!=typeof self&&self.Prism&&self.document){var t=[],e={},n=function(){};Prism.plugins.toolbar={};var a=Prism.plugins.toolbar.registerButton=function(n,a){var o;o="function"==typeof a?a:function(t){var e;return"function"==typeof a.onClick?(e=document.createElement("button"),e.type="button",e.addEventListener("click",function(){a.onClick.call(this,t)})):"string"==typeof a.url?(e=document.createElement("a"),e.href=a.url):e=document.createElement("span"),e.textContent=a.text,e},t.push(e[n]=o)},o=Prism.plugins.toolbar.hook=function(a){var o=a.element.parentNode;if(o&&/pre/i.test(o.nodeName)&&!o.parentNode.classList.contains("code-toolbar")){var r=document.createElement("div");r.classList.add("code-toolbar"),o.parentNode.insertBefore(r,o),r.appendChild(o);var i=document.createElement("div");i.classList.add("toolbar"),document.body.hasAttribute("data-toolbar-order")&&(t=document.body.getAttribute("data-toolbar-order").split(",").map(function(t){return e[t]||n})),t.forEach(function(t){var e=t(a);if(e){var n=document.createElement("div");n.classList.add("toolbar-item"),n.appendChild(e),i.appendChild(n)}}),r.appendChild(i)}};a("label",function(t){var e=t.element.parentNode;if(e&&/pre/i.test(e.nodeName)&&e.hasAttribute("data-label")){var n,a,o=e.getAttribute("data-label");try{a=document.querySelector("template#"+o)}catch(r){}return a?n=a.content:(e.hasAttribute("data-url")?(n=document.createElement("a"),n.href=e.getAttribute("data-url")):n=document.createElement("span"),n.textContent=o),n}}),Prism.hooks.add("complete",o)}}(); \ No newline at end of file