mirror of
https://github.com/UnickSoft/graphonline.git
synced 2026-08-27 12:39:51 +00:00
Replace sharing buttons to copy to clipboard. Remove unnecessary files.
This commit is contained in:
@@ -36,8 +36,11 @@ SavedDialogGraphHandler.prototype.show = function(object)
|
||||
|
||||
document.getElementById('GraphName').select();
|
||||
|
||||
document.getElementById("ShareSavedGraph").innerHTML =
|
||||
document.getElementById("ShareSavedGraph").innerHTML.replace(/graph=([A-Za-z]*)/g, "graph=" + this.app.GetGraphName());
|
||||
var copyButton = document.getElementById('CopyGraphLink');
|
||||
if (copyButton) {
|
||||
copyButton.onclick = this.copyGraphLink.bind(this);
|
||||
this.setCopyButtonIcon('bi bi-copy');
|
||||
}
|
||||
|
||||
$( "#saveDialog" ).dialog({
|
||||
resizable: false,
|
||||
@@ -48,5 +51,58 @@ SavedDialogGraphHandler.prototype.show = function(object)
|
||||
buttons: dialogButtons,
|
||||
dialogClass: 'EdgeDialog'
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
SavedDialogGraphHandler.prototype.copyGraphLink = function()
|
||||
{
|
||||
var graphInput = document.getElementById('GraphName');
|
||||
if (!graphInput) {
|
||||
return;
|
||||
}
|
||||
|
||||
var text = graphInput.value;
|
||||
if (!text) {
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(text).then(function() {
|
||||
self.setCopyButtonIcon('bi bi-check2-square');
|
||||
}, function() {
|
||||
self.fallbackCopyText(text);
|
||||
});
|
||||
} else {
|
||||
if (this.fallbackCopyText(text)) {
|
||||
this.setCopyButtonIcon('bi bi-check2-square');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SavedDialogGraphHandler.prototype.fallbackCopyText = function(text)
|
||||
{
|
||||
var textarea = document.createElement('textarea');
|
||||
textarea.value = text;
|
||||
document.body.appendChild(textarea);
|
||||
textarea.select();
|
||||
|
||||
var successful = false;
|
||||
try {
|
||||
successful = document.execCommand('copy');
|
||||
} catch (err) {
|
||||
successful = false;
|
||||
}
|
||||
document.body.removeChild(textarea);
|
||||
if (successful) {
|
||||
this.setCopyButtonIcon('bi bi-check2-square');
|
||||
}
|
||||
return successful;
|
||||
};
|
||||
|
||||
SavedDialogGraphHandler.prototype.setCopyButtonIcon = function(iconClass)
|
||||
{
|
||||
var icon = document.querySelector('#CopyGraphLink span');
|
||||
if (icon) {
|
||||
icon.className = iconClass;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -34,13 +34,21 @@ SavedDialogGraphImageHandler.prototype.showDialogCallback = function (imageExten
|
||||
|
||||
document.getElementById("showSavedImageGraph").src = "/" + fileLocation;
|
||||
document.getElementById("showSavedImageGraphRef").href = "/" + fileLocation;
|
||||
//document.getElementById("showSavedImageGraph").src = document.getElementById("showSavedImageGraph").src.replace(/tmp\/saved\/([A-Za-z]*)\/([A-Za-z]*).png/g, fileLocation);
|
||||
document.getElementById("ShareSavedImageGraph").innerHTML =
|
||||
document.getElementById("ShareSavedImageGraph").innerHTML.replace(/tmp\/saved\/([A-Za-z]*)\/([A-Za-z]*).png/g, fileLocation);
|
||||
var imageUrl = window.location.protocol + "//" + window.location.host + "/" + fileLocation;
|
||||
var graphImageName = document.getElementById("GraphImageName");
|
||||
if (graphImageName) {
|
||||
graphImageName.value = imageUrl;
|
||||
}
|
||||
|
||||
document.getElementById("SaveImageLinks").innerHTML =
|
||||
document.getElementById("SaveImageLinks").innerHTML.replace(/tmp\/saved\/([A-Za-z]*)\/([A-Za-z]*).png/g, fileLocation);
|
||||
|
||||
var copyImageButton = document.getElementById('CopyGraphImageLink');
|
||||
if (copyImageButton) {
|
||||
copyImageButton.onclick = this.copyGraphImageLink.bind(this);
|
||||
this.setCopyImageButtonIcon('bi bi-copy');
|
||||
}
|
||||
|
||||
$( "#saveImageDialog" ).dialog({
|
||||
resizable: false,
|
||||
height: "auto",
|
||||
@@ -92,3 +100,57 @@ SavedDialogGraphImageHandler.prototype.showSvg = function()
|
||||
|
||||
this.imageName = this.app.SaveSVGGraphOnDisk(callback);
|
||||
}
|
||||
|
||||
SavedDialogGraphImageHandler.prototype.copyGraphImageLink = function()
|
||||
{
|
||||
var imageInput = document.getElementById('GraphImageName');
|
||||
if (!imageInput) {
|
||||
return;
|
||||
}
|
||||
|
||||
var text = imageInput.value;
|
||||
if (!text) {
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(text).then(function() {
|
||||
self.setCopyImageButtonIcon('bi bi-check2-square');
|
||||
}, function() {
|
||||
self.fallbackCopyImageText(text);
|
||||
});
|
||||
} else {
|
||||
if (this.fallbackCopyImageText(text)) {
|
||||
this.setCopyImageButtonIcon('bi bi-check2-square');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SavedDialogGraphImageHandler.prototype.fallbackCopyImageText = function(text)
|
||||
{
|
||||
var textarea = document.createElement('textarea');
|
||||
textarea.value = text;
|
||||
document.body.appendChild(textarea);
|
||||
textarea.select();
|
||||
|
||||
var successful = false;
|
||||
try {
|
||||
successful = document.execCommand('copy');
|
||||
} catch (err) {
|
||||
successful = false;
|
||||
}
|
||||
document.body.removeChild(textarea);
|
||||
if (successful) {
|
||||
this.setCopyImageButtonIcon('bi bi-check2-square');
|
||||
}
|
||||
return successful;
|
||||
};
|
||||
|
||||
SavedDialogGraphImageHandler.prototype.setCopyImageButtonIcon = function(iconClass)
|
||||
{
|
||||
var icon = document.querySelector('#CopyGraphImageLink span');
|
||||
if (icon) {
|
||||
icon.className = iconClass;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user