xref: /aosp_15_r20/external/tinyxml2/docs/clipboard.js (revision 7485b22521f577cf944e5687361548d8993d8d2c)
1*7485b225SElliott Hughes/**
2*7485b225SElliott Hughes
3*7485b225SElliott HughesThe code below is based on the Doxygen Awesome project, see
4*7485b225SElliott Hugheshttps://github.com/jothepro/doxygen-awesome-css
5*7485b225SElliott Hughes
6*7485b225SElliott HughesMIT License
7*7485b225SElliott Hughes
8*7485b225SElliott HughesCopyright (c) 2021 - 2022 jothepro
9*7485b225SElliott Hughes
10*7485b225SElliott HughesPermission is hereby granted, free of charge, to any person obtaining a copy
11*7485b225SElliott Hughesof this software and associated documentation files (the "Software"), to deal
12*7485b225SElliott Hughesin the Software without restriction, including without limitation the rights
13*7485b225SElliott Hughesto use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14*7485b225SElliott Hughescopies of the Software, and to permit persons to whom the Software is
15*7485b225SElliott Hughesfurnished to do so, subject to the following conditions:
16*7485b225SElliott Hughes
17*7485b225SElliott HughesThe above copyright notice and this permission notice shall be included in all
18*7485b225SElliott Hughescopies or substantial portions of the Software.
19*7485b225SElliott Hughes
20*7485b225SElliott HughesTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21*7485b225SElliott HughesIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22*7485b225SElliott HughesFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23*7485b225SElliott HughesAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24*7485b225SElliott HughesLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25*7485b225SElliott HughesOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26*7485b225SElliott HughesSOFTWARE.
27*7485b225SElliott Hughes
28*7485b225SElliott Hughes*/
29*7485b225SElliott Hughes
30*7485b225SElliott Hugheslet clipboard_title = "Copy to clipboard"
31*7485b225SElliott Hugheslet clipboard_icon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg>`
32*7485b225SElliott Hugheslet clipboard_successIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z"/></svg>`
33*7485b225SElliott Hugheslet clipboard_successDuration = 1000
34*7485b225SElliott Hughes
35*7485b225SElliott Hughes$(function() {
36*7485b225SElliott Hughes  if(navigator.clipboard) {
37*7485b225SElliott Hughes    const fragments = document.getElementsByClassName("fragment")
38*7485b225SElliott Hughes    for(const fragment of fragments) {
39*7485b225SElliott Hughes      const clipboard_div = document.createElement("div")
40*7485b225SElliott Hughes      clipboard_div.classList.add("clipboard")
41*7485b225SElliott Hughes      clipboard_div.innerHTML = clipboard_icon
42*7485b225SElliott Hughes      clipboard_div.title = clipboard_title
43*7485b225SElliott Hughes      $(clipboard_div).click(function() {
44*7485b225SElliott Hughes        const content = this.parentNode.cloneNode(true)
45*7485b225SElliott Hughes        // filter out line number and folded fragments from file listings
46*7485b225SElliott Hughes        content.querySelectorAll(".lineno, .ttc, .foldclosed").forEach((node) => { node.remove() })
47*7485b225SElliott Hughes        let text = content.textContent
48*7485b225SElliott Hughes        // remove trailing newlines and trailing spaces from empty lines
49*7485b225SElliott Hughes        text = text.replace(/^\s*\n/gm,'\n').replace(/\n*$/,'')
50*7485b225SElliott Hughes        navigator.clipboard.writeText(text);
51*7485b225SElliott Hughes        this.classList.add("success")
52*7485b225SElliott Hughes        this.innerHTML = clipboard_successIcon
53*7485b225SElliott Hughes        window.setTimeout(() => { // switch back to normal icon after timeout
54*7485b225SElliott Hughes            this.classList.remove("success")
55*7485b225SElliott Hughes            this.innerHTML = clipboard_icon
56*7485b225SElliott Hughes        }, clipboard_successDuration);
57*7485b225SElliott Hughes      })
58*7485b225SElliott Hughes      fragment.insertBefore(clipboard_div, fragment.firstChild)
59*7485b225SElliott Hughes    }
60*7485b225SElliott Hughes  }
61*7485b225SElliott Hughes})
62