08-27-周三_17-09-29
This commit is contained in:
64
node_modules/prismjs/plugins/toolbar/prism-toolbar.css
generated
vendored
Normal file
64
node_modules/prismjs/plugins/toolbar/prism-toolbar.css
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
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;
|
||||
}
|
||||
|
||||
/* Separate line b/c rules are thrown out if selector is invalid.
|
||||
IE11 and old Edge versions don't support :focus-within. */
|
||||
div.code-toolbar:focus-within > .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;
|
||||
}
|
178
node_modules/prismjs/plugins/toolbar/prism-toolbar.js
generated
vendored
Normal file
178
node_modules/prismjs/plugins/toolbar/prism-toolbar.js
generated
vendored
Normal file
@@ -0,0 +1,178 @@
|
||||
(function(){
|
||||
if (typeof self === 'undefined' || !self.Prism || !self.document) {
|
||||
return;
|
||||
}
|
||||
|
||||
var callbacks = [];
|
||||
var map = {};
|
||||
var noop = function() {};
|
||||
|
||||
Prism.plugins.toolbar = {};
|
||||
|
||||
/**
|
||||
* @typedef ButtonOptions
|
||||
* @property {string} text The text displayed.
|
||||
* @property {string} [url] The URL of the link which will be created.
|
||||
* @property {Function} [onClick] The event listener for the `click` event of the created button.
|
||||
* @property {string} [className] The class attribute to include with element.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Register a button callback with the toolbar.
|
||||
*
|
||||
* @param {string} key
|
||||
* @param {ButtonOptions|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');
|
||||
}
|
||||
|
||||
if (opts.className) {
|
||||
element.classList.add(opts.className);
|
||||
}
|
||||
|
||||
element.textContent = opts.text;
|
||||
|
||||
return element;
|
||||
};
|
||||
}
|
||||
|
||||
if (key in map) {
|
||||
console.warn('There is a button with the key "' + key + '" registered already.');
|
||||
return;
|
||||
}
|
||||
|
||||
callbacks.push(map[key] = callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the callback order of the given element.
|
||||
*
|
||||
* @param {HTMLElement} element
|
||||
* @returns {string[] | undefined}
|
||||
*/
|
||||
function getOrder(element) {
|
||||
while (element) {
|
||||
var order = element.getAttribute('data-toolbar-order');
|
||||
if (order != null) {
|
||||
order = order.trim();
|
||||
if (order.length) {
|
||||
return order.split(/\s*,\s*/g);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
element = element.parentElement;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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');
|
||||
|
||||
// order callbacks
|
||||
var elementCallbacks = callbacks;
|
||||
var order = getOrder(env.element);
|
||||
if (order) {
|
||||
elementCallbacks = order.map(function (key) {
|
||||
return map[key] || noop;
|
||||
});
|
||||
}
|
||||
|
||||
elementCallbacks.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);
|
||||
})();
|
1
node_modules/prismjs/plugins/toolbar/prism-toolbar.min.js
generated
vendored
Normal file
1
node_modules/prismjs/plugins/toolbar/prism-toolbar.min.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(){if("undefined"!=typeof self&&self.Prism&&self.document){var i=[],l={},c=function(){};Prism.plugins.toolbar={};var e=Prism.plugins.toolbar.registerButton=function(e,n){var t;t="function"==typeof n?n:function(e){var t;return"function"==typeof n.onClick?((t=document.createElement("button")).type="button",t.addEventListener("click",function(){n.onClick.call(this,e)})):"string"==typeof n.url?(t=document.createElement("a")).href=n.url:t=document.createElement("span"),n.className&&t.classList.add(n.className),t.textContent=n.text,t},e in l?console.warn('There is a button with the key "'+e+'" registered already.'):i.push(l[e]=t)},t=Prism.plugins.toolbar.hook=function(a){var e=a.element.parentNode;if(e&&/pre/i.test(e.nodeName)&&!e.parentNode.classList.contains("code-toolbar")){var t=document.createElement("div");t.classList.add("code-toolbar"),e.parentNode.insertBefore(t,e),t.appendChild(e);var r=document.createElement("div");r.classList.add("toolbar");var n=i,o=function(e){for(;e;){var t=e.getAttribute("data-toolbar-order");if(null!=t)return(t=t.trim()).length?t.split(/\s*,\s*/g):[];e=e.parentElement}}(a.element);o&&(n=o.map(function(e){return l[e]||c})),n.forEach(function(e){var t=e(a);if(t){var n=document.createElement("div");n.classList.add("toolbar-item"),n.appendChild(t),r.appendChild(n)}}),t.appendChild(r)}};e("label",function(e){var t=e.element.parentNode;if(t&&/pre/i.test(t.nodeName)&&t.hasAttribute("data-label")){var n,a,r=t.getAttribute("data-label");try{a=document.querySelector("template#"+r)}catch(e){}return a?n=a.content:(t.hasAttribute("data-url")?(n=document.createElement("a")).href=t.getAttribute("data-url"):n=document.createElement("span"),n.textContent=r),n}}),Prism.hooks.add("complete",t)}}();
|
Reference in New Issue
Block a user