Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a copy URI icon #211

Merged
merged 12 commits into from
Jun 7, 2021
38 changes: 34 additions & 4 deletions js/tree-edam-stand-alone.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,20 +434,26 @@ function interactive_edam_browser(){
text=value;
}
}else{
text=value;
text=value.substring(value.lastIndexOf('/')+1);
}
/* jshint -W014 */
return "<a "+
return '<div class="btn-group btn-group-xs"><a '+
'role="button" '+
'style="font-size: 1em;" '+
"href=\"#"+ value + (current_branch=="deprecated"?"&deprecated":"")+"\" "+
(
current_branch.startsWith("edam")
?"onclick=\"browser.interactive_tree().cmd().clearSelectedElements(false);browser.interactive_tree().cmd().selectElement('"+value+"',true)\""
:"onclick=\"setCookie('edam_browser_'+'"+current_branch+"','"+value+"');browser.current_branch('"+branch_of_term+"');browser.interactive_tree().cmd().clearSelectedElements(false);browser.interactive_tree().cmd().selectElement('"+value+"',true)\""
)+
"class=\"label bg-edam-"+branch_of_term+"-light fg-edam-"+branch_of_term+" border-one-solid border-edam-"+branch_of_term+"\" "+
"class=\"btn bg-edam-"+branch_of_term+"-light fg-edam-"+branch_of_term+" border-one-solid border-edam-"+branch_of_term+"\" "+
">"+
text+
"</a>"
"</a>"+
'<button class="btn bg-edam-'+branch_of_term+' fg-edam-'+branch_of_term+'-light" type="button" style="font-size: 1em;">'+
'<i class="fas fa-copy" onClick="cpyToClipboard(\'' + value + '\')" ></i> ' +
'</button>'+
'</div>'
//+' <i class="glyphicon glyphicon-stop bg-edam-'+branch_of_term+' fg-edam-'+branch_of_term+'"></i></a>'
//+'<span class="badge bg-edam-'+branch_of_term+'">'+branch_of_term+'</span>'
//+'<span class="label label-default bg-edam-'+branch_of_term+'-light fg-edam-'+branch_of_term+' border-edam-'+branch_of_term+'">'+branch_of_term+'</span>'
Expand Down Expand Up @@ -766,3 +772,27 @@ function toggleFullscreen(){
$('#go-fullscreen').show();
}
}

/**
*
* @param {string} value Copies the value of the passed uri to the clipboard
*/
function cpyToClipboard(value){
//copying the uri value to the clipboard
navigator.clipboard.writeText(value);

const element = event.srcElement;

//showing a tooltip indicating the value is copied
$(element).attr('title', "URI copied!")
bryan-brancotte marked this conversation as resolved.
Show resolved Hide resolved
.tooltip('show');

//changing the icon to a check shape indicating success
$(element).addClass("fa-check").removeClass("fa-copy");

//toggling back the icon and removing the copied tooltip
setTimeout(function(){
$(element).addClass("fa-copy").removeClass("fa-check");
$(element).tooltip('destroy');
}, 1000);
}