mirror of
https://github.com/twbs/bootstrap.git
synced 2025-03-01 01:54:24 +01:00
6 lines
14 KiB
JavaScript
6 lines
14 KiB
JavaScript
/*!
|
|
* clipboard.js v2.0.8
|
|
* https://clipboardjs.com/
|
|
*
|
|
* Licensed MIT © Zeno Rocha
|
|
*/!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ClipboardJS=e():t.ClipboardJS=e()}(this,function(){return n={134:function(p,e,t){"use strict";t.d(e,{default:function(){return i}});var i,c,e=t(279),f=t.n(e),e=t(370),m=t.n(e),e=t(817),l=t.n(e);function a(e){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function r(s,n){for(var e,t=0;t<n.length;t++)e=n[t],e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(s,e.key,e)}c=function(){function e(t){!function(t){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this),this.resolveOptions(t),this.initSelection()}var t,n,s;return t=e,(n=[{key:"resolveOptions",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};this.action=e.action,this.container=e.container,this.emitter=e.emitter,this.target=e.target,this.text=e.text,this.trigger=e.trigger,this.selectedText=""}},{key:"initSelection",value:function(){this.text?this.selectFake():this.target&&this.selectTarget()}},{key:"createFakeElement",value:function(){var e="rtl"===document.documentElement.getAttribute("dir");return this.fakeElem=document.createElement("textarea"),this.fakeElem.style.fontSize="12pt",this.fakeElem.style.border="0",this.fakeElem.style.padding="0",this.fakeElem.style.margin="0",this.fakeElem.style.position="absolute",this.fakeElem.style[e?"right":"left"]="-9999px",e=window.pageYOffset||document.documentElement.scrollTop,this.fakeElem.style.top="".concat(e,"px"),this.fakeElem.setAttribute("readonly",""),this.fakeElem.value=this.text,this.fakeElem}},{key:"selectFake",value:function(){var t=this,e=this.createFakeElement();this.fakeHandlerCallback=function(){return t.removeFake()},this.fakeHandler=this.container.addEventListener("click",this.fakeHandlerCallback)||!0,this.container.appendChild(e),this.selectedText=l()(e),this.copyText(),this.removeFake()}},{key:"removeFake",value:function(){this.fakeHandler&&(this.container.removeEventListener("click",this.fakeHandlerCallback),this.fakeHandler=null,this.fakeHandlerCallback=null),this.fakeElem&&(this.container.removeChild(this.fakeElem),this.fakeElem=null)}},{key:"selectTarget",value:function(){this.selectedText=l()(this.target),this.copyText()}},{key:"copyText",value:function(){var e;try{e=document.execCommand(this.action)}catch(t){e=!1}this.handleResult(e)}},{key:"handleResult",value:function(e){this.emitter.emit(e?"success":"error",{action:this.action,text:this.selectedText,trigger:this.trigger,clearSelection:this.clearSelection.bind(this)})}},{key:"clearSelection",value:function(){this.trigger&&this.trigger.focus(),document.activeElement.blur(),window.getSelection().removeAllRanges()}},{key:"destroy",value:function(){this.removeFake()}},{key:"action",set:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"copy";if(this._action=e,"copy"!==this._action&&"cut"!==this._action)throw new Error('Invalid "action" value, use either "copy" or "cut"')},get:function(){return this._action}},{key:"target",set:function(e){if(void 0!==e){if(!e||"object"!==a(e)||1!==e.nodeType)throw new Error('Invalid "target" value, use a valid Element');if("copy"===this.action&&e.hasAttribute("disabled"))throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');if("cut"===this.action&&(e.hasAttribute("readonly")||e.hasAttribute("disabled")))throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');this._target=e}},get:function(){return this._target}}])&&r(t.prototype,n),s&&r(t,s),e}();function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function d(s,n){for(var e,t=0;t<n.length;t++)e=n[t],e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(s,e.key,e)}function u(e,t){return(u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function h(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var s,i=o(e);return s=t?(s=o(this).constructor,Reflect.construct(i,arguments,s)):i.apply(this,arguments),i=this,!(s=s)||"object"!==n(s)&&"function"!=typeof s?function(e){if(void 0!==e)return e;throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}(i):s}}function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function s(e,t){if(e="data-clipboard-".concat(e),t.hasAttribute(e))return t.getAttribute(e)}i=function(){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&u(t,e)}(e,f());var t,o,i,a=h(e);function e(n,s){var t;return function(t){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this),(t=a.call(this)).resolveOptions(s),t.listenClick(n),t}return t=e,o=[{key:"isSupported",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:["copy","cut"],e="string"==typeof e?[e]:e,t=!!document.queryCommandSupported;return e.forEach(function(e){t=t&&!!document.queryCommandSupported(e)}),t}}],(i=[{key:"resolveOptions",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};this.action="function"==typeof e.action?e.action:this.defaultAction,this.target="function"==typeof e.target?e.target:this.defaultTarget,this.text="function"==typeof e.text?e.text:this.defaultText,this.container="object"===n(e.container)?e.container:document.body}},{key:"listenClick",value:function(e){var t=this;this.listener=m()(e,"click",function(e){return t.onClick(e)})}},{key:"onClick",value:function(e){e=e.delegateTarget||e.currentTarget,this.clipboardAction&&(this.clipboardAction=null),this.clipboardAction=new c({action:this.action(e),target:this.target(e),text:this.text(e),container:this.container,trigger:e,emitter:this})}},{key:"defaultAction",value:function(e){return s("action",e)}},{key:"defaultTarget",value:function(e){if(e=s("target",e),e)return document.querySelector(e)}},{key:"defaultText",value:function(e){return s("text",e)}},{key:"destroy",value:function(){this.listener.destroy(),this.clipboardAction&&(this.clipboardAction.destroy(),this.clipboardAction=null)}}])&&d(t.prototype,i),o&&d(t,o),e}()},828:function(t){var e;"undefined"==typeof Element||Element.prototype.matches||((e=Element.prototype).matches=e.matchesSelector||e.mozMatchesSelector||e.msMatchesSelector||e.oMatchesSelector||e.webkitMatchesSelector),t.exports=function(e,t){for(;e&&9!==e.nodeType;){if("function"==typeof e.matches&&e.matches(t))return e;e=e.parentNode}}},438:function(t,o,n){var s=n(828);function e(e,i,t,a,n){var o=function(e,t,o,n){return function(o){o.delegateTarget=s(o.target,t),o.delegateTarget&&n.call(e,o)}}.apply(this,arguments);return e.addEventListener(t,o,n),{destroy:function(){e.removeEventListener(t,o,n)}}}t.exports=function(t,s,n,o,i){return"function"==typeof t.addEventListener?e.apply(null,arguments):"function"==typeof n?e.bind(null,document).apply(null,arguments):("string"==typeof t&&(t=document.querySelectorAll(t)),Array.prototype.map.call(t,function(t){return e(t,s,n,o,i)}))}},879:function(t,e){e.node=function(e){return void 0!==e&&e instanceof HTMLElement&&1===e.nodeType},e.nodeList=function(t){var n=Object.prototype.toString.call(t);return void 0!==t&&("[object NodeList]"===n||"[object HTMLCollection]"===n)&&"length"in t&&(0===t.length||e.node(t[0]))},e.string=function(e){return"string"==typeof e||e instanceof String},e.fn=function(e){return"[object Function]"===Object.prototype.toString.call(e)}},370:function(n,o,t){var e=t(879),s=t(438);n.exports=function(t,n,o){if(!t&&!n&&!o)throw new Error("Missing required arguments");if(!e.string(n))throw new TypeError("Second argument must be a String");if(!e.fn(o))throw new TypeError("Third argument must be a Function");if(e.node(t))return c=n,l=o,(d=t).addEventListener(c,l),{destroy:function(){d.removeEventListener(c,l)}};if(e.nodeList(t))return i=t,a=n,r=o,Array.prototype.forEach.call(i,function(e){e.addEventListener(a,r)}),{destroy:function(){Array.prototype.forEach.call(i,function(e){e.removeEventListener(a,r)})}};if(e.string(t))return t=t,n=n,o=o,s(document.body,t,n,o);throw new TypeError("First argument must be a String, HTMLElement, HTMLCollection, or NodeList");var i,a,r,c,l,d}},817:function(e){e.exports=function(e){var n,t="SELECT"===e.nodeName?(e.focus(),e.value):"INPUT"===e.nodeName||"TEXTAREA"===e.nodeName?((n=e.hasAttribute("readonly"))||e.setAttribute("readonly",""),e.select(),e.setSelectionRange(0,e.value.length),n||e.removeAttribute("readonly"),e.value):(e.hasAttribute("contenteditable")&&e.focus(),t=window.getSelection(),(n=document.createRange()).selectNodeContents(e),t.removeAllRanges(),t.addRange(n),t.toString());return t}},279:function(t){function e(){}e.prototype={on:function(e,n,s){var t=this.e||(this.e={});return(t[e]||(t[e]=[])).push({fn:n,ctx:s}),this},once:function(t,n,s){var o=this;function e(){o.off(t,e),n.apply(s,arguments)}return e._=n,this.on(t,e,s)},emit:function(n){for(var s=[].slice.call(arguments,1),t=((this.e||(this.e={}))[n]||[]).slice(),e=0,o=t.length;e<o;e++)t[e].fn.apply(t[e].ctx,s);return this},off:function(n,s){var e,a,o=this.e||(this.e={}),t=o[n],i=[];if(t&&s)for(e=0,a=t.length;e<a;e++)t[e].fn!==s&&t[e].fn._!==s&&i.push(t[e]);return i.length?o[n]=i:delete o[n],this}},t.exports=e,t.exports.TinyEmitter=e}},t={},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,{a:n}),n},e.d=function(s,n){for(var t in n)e.o(n,t)&&!e.o(s,t)&&Object.defineProperty(s,t,{enumerable:!0,get:n[t]})},e.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},e(134).default;function e(s){if(t[s])return t[s].exports;var o=t[s]={exports:{}};return n[s](o,o.exports,e),o.exports}var t,n}),(()=>{'use strict';const e=document.querySelector(".bd-sidebar");if(e){const n=e.clientHeight,s=document.querySelector(".bd-links-nav .active"),i=s.offsetTop,o=s.clientHeight,t=i,a=t-n+o;(e.scrollTop>t||e.scrollTop<a)&&(e.scrollTop=t-n/2+o/2)}})(),(()=>{'use strict';const e="Copy to clipboard",s="Edit on StackBlitz",o=['<div class="bd-code-snippet">',' <div class="bd-clipboard">',' <button type="button" class="btn-clipboard">',' <svg class="bi" width="1em" height="1em" fill="currentColor" role="img" aria-label="Copy"><use xlink:href="#clipboard"/></svg>'," </button>"," </div>","</div>"].join('');document.querySelectorAll(".highlight").forEach(e=>{e.closest(".bd-example-snippet")||(e.insertAdjacentHTML("beforebegin",o),e.previousElementSibling.append(e))});function t(e,t){document.querySelectorAll(e).forEach(e=>{bootstrap.Tooltip.getOrCreateInstance(e,{title:t})})}t(".btn-clipboard",e),t(".btn-edit",s);const n=new ClipboardJS(".btn-clipboard",{target:e=>e.closest(".bd-code-snippet").querySelector(".highlight")});n.on("success",t=>{const n=t.trigger.querySelector(".bi").firstChild,o=bootstrap.Tooltip.getInstance(t.trigger),s="http://www.w3.org/1999/xlink",i=n.getAttributeNS(s,"href"),a=t.trigger.title;o.setContent({'.tooltip-inner':"Copied!"}),t.trigger.addEventListener("hidden.bs.tooltip",()=>{o.setContent({'.tooltip-inner':e})},{once:!0}),t.clearSelection(),n.setAttributeNS(s,"href",i.replace("clipboard","check2")),setTimeout(()=>{n.setAttributeNS(s,"href",i),t.trigger.title=a},2e3)}),n.on("error",t=>{const s=/mac/i.test(navigator.userAgent)?"\u2318":"Ctrl-",o=`Press ${s}C to copy`,n=bootstrap.Tooltip.getInstance(t.trigger);n.setContent({'.tooltip-inner':o}),t.trigger.addEventListener("hidden.bs.tooltip",()=>{n.setContent({'.tooltip-inner':e})},{once:!0})})})(),(()=>{'use strict';const e=document.getElementById("docsearch");if(!window.docsearch||!e)return;const t=e.getAttribute("data-bd-docs-version");window.docsearch({apiKey:"3151f502c7b9e9dafd5e6372b691a24e",indexName:"bootstrap",appId:"AK7KMZKZHQ",container:e,searchParameters:{facetFilters:[`version:${t}`]},transformItems(e){return e.map(e=>{const t="https://getbootstrap.com/";return e.url=window.location.origin.startsWith(t)?e.url:e.url.replace(t,"/"),e.anchor==="content"&&(e.url=e.url.replace(/#content$/,''),e.anchor=null),e})},debug:!1})})(),(()=>{'use strict';document.querySelectorAll('[data-bs-toggle="tooltip"]').forEach(e=>{new bootstrap.Tooltip(e)}),document.querySelectorAll('[data-bs-toggle="popover"]').forEach(e=>{new bootstrap.Popover(e)});const e=document.getElementById("toastPlacement");e&&document.getElementById("selectToastPlacement").addEventListener("change",function(){e.dataset.originalClass||(e.dataset.originalClass=e.className),e.className=`${e.dataset.originalClass} ${this.value}`}),document.querySelectorAll(".bd-example .toast").forEach(e=>{const t=new bootstrap.Toast(e,{autohide:!1});t.show()});const n=document.getElementById("liveToastBtn"),i=document.getElementById("liveToast");n&&n.addEventListener("click",()=>{const e=new bootstrap.Toast(i);e.show()});const a=document.getElementById("liveAlertPlaceholder"),s=document.getElementById("liveAlertBtn"),r=(t,n)=>{const e=document.createElement("div");e.innerHTML=[`<div class="alert alert-${n} alert-dismissible" role="alert">`,` <div>${t}</div>`,' <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>',"</div>"].join(''),a.append(e)};s&&s.addEventListener("click",()=>{r("Nice, you triggered this alert message!","success")}),document.querySelectorAll('.bd-example-indeterminate [type="checkbox"]').forEach(e=>{e.indeterminate=!0}),document.querySelectorAll('.bd-content [href="#"]').forEach(e=>{e.addEventListener("click",e=>{e.preventDefault()})});const t=document.getElementById("exampleModal");t&&t.addEventListener("show.bs.modal",n=>{const s=n.relatedTarget,e=s.getAttribute("data-bs-whatever"),o=t.querySelector(".modal-title"),i=t.querySelector(".modal-body input");o.textContent=`New message to ${e}`,i.value=e});const o=document.querySelector(".bd-example-offcanvas #offcanvas");o&&o.addEventListener("show.bs.offcanvas",e=>{e.preventDefault()},!1)})() |