2020-09-25 19:02:40 +02:00
"use strict" ;
// Copy to clipboard
// Source: https://codepen.io/nathanlong/pen/ZpAmjv
let copyToClipboard = ( text , el ) => {
const elOriginalText = el . attr ( 'data-original-title' ) ;
const copyTextArea = document . createElement ( "textarea" ) ;
copyTextArea . value = text ;
document . body . appendChild ( copyTextArea ) ;
copyTextArea . select ( ) ;
const successful = document . execCommand ( 'copy' ) ;
const msg = successful ? 'Copied!' : 'Whoops, not copied!' ;
el . attr ( 'data-original-title' , msg ) . tooltip ( 'show' ) ;
document . body . removeChild ( copyTextArea ) ;
el . attr ( 'data-original-title' , elOriginalText ) ;
}
2022-03-30 13:48:10 +02:00
function checkAllBoxes ( name ) {
let checkboxs = document . getElementsByName ( name ) ;
for ( let i = 0 ; i < checkboxs . length ; i ++ ) {
checkboxs [ i ] . checked = ! checkboxs [ i ] . checked ;
}
}
2024-02-20 19:53:07 +01:00
2024-11-08 20:44:53 +01:00
function openURLInNewTab ( url ) {
let win = window . open ( url , '_blank' ) ;
if ( win == null ) {
return false ;
}
win . focus ( ) ;
return true ;
}
function openTreeInNewTab ( capture _uuid , hostnode _uuid = null ) {
let url = ` /tree/ ${ capture _uuid } ` ;
if ( hostnode _uuid != null ) {
url += ` / ${ hostnode _uuid } ` ;
}
return openURLInNewTab ( url ) ;
}
2024-09-04 16:30:33 +02:00
const goBackButtons = document . querySelectorAll ( '.goBack' ) ;
goBackButtons . forEach ( el => el . addEventListener ( 'click' , event => {
window . history . back ( ) ;
} ) ) ;
2024-11-08 20:44:53 +01:00
const openNewTabButtons = document . querySelectorAll ( '.openNewTab' ) ;
openNewTabButtons . forEach ( el => el . addEventListener ( 'click' , event => {
if ( window . opener === null ) {
return openTreeInNewTab ( el . dataset . capture , el . dataset . hostnode )
} else {
2024-11-09 22:15:53 +01:00
let success = window . opener . openTreeInNewTab ( el . dataset . capture , el . dataset . hostnode ) ;
if ( ! success ) {
alert ( "Your browser doesn't allow Lookyloo to open a new tab. There should be an icon on the right side of your URL bar *in the main window* to allow it." ) ;
}
2024-11-08 20:44:53 +01:00
}
} ) ) ;
2024-11-09 22:15:53 +01:00
const locateInTree = document . querySelectorAll ( ".locateInTree" )
if ( locateInTree ) {
locateInTree . forEach ( el => el . addEventListener ( 'click' , event => {
window . opener . LocateNode ( el . dataset . hostnode ) ;
} ) ) ;
}
2024-02-20 19:53:07 +01:00
// Parameters:
// contentType: The content type of your file.
// its like application/pdf or application/msword or image/jpeg or
// image/png and so on
// base64Data: Its your actual base64 data
// fileName: Its the file name of the file which will be downloaded.
// Source: https://stackoverflow.com/questions/14011021/how-to-download-a-base64-encoded-image
function downloadBase64File ( contentType , base64Data , fileName ) {
const linkSource = ` data: ${ contentType } ;base64, ${ base64Data } ` ;
const downloadLink = document . createElement ( "a" ) ;
downloadLink . href = linkSource ;
downloadLink . download = fileName ;
downloadLink . click ( ) ;
}