Skip to content

Commit

Permalink
Adds support for custom action titles
Browse files Browse the repository at this point in the history
  • Loading branch information
alderg committed Sep 4, 2023
1 parent 6c5c707 commit 95e039d
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions tools/link.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
var link = document.getElementById('link').value;
var obj = JSON.parse(link.substring(link.indexOf(',') + 1));

var title = document.getElementById('title').value;

if (title != '')
{
obj.title = title;
}

if (obj.actions == null)
{
obj.actions = [];
}

if (type == 'link')
{
obj.actions.push({open: document.getElementById('href').value});
Expand Down Expand Up @@ -169,6 +181,14 @@
}

document.getElementById('link').value = 'data:action/json,' + JSON.stringify(obj, null, 2);

var href = getLink();
document.getElementById('anchor').href = href;
document.getElementById('anchor').innerHTML = href.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#39;");
}
catch (e)
{
Expand All @@ -193,7 +213,7 @@

function resetLink()
{
document.getElementById('link').value = 'data:action/json,' + JSON.stringify({"actions":[]}, null, 2);
document.getElementById('link').value = 'data:action/json,' + JSON.stringify({}, null, 2);
};

function validateLink(quiet)
Expand Down Expand Up @@ -263,6 +283,11 @@
}
};

function getLink()
{
return 'data:action/json,' + JSON.stringify(JSON.parse(link.value.substring(17)));
};

function copyLink()
{
try
Expand All @@ -271,7 +296,7 @@
{
var link = document.getElementById('link');
var prev = link.value;
link.value = 'data:action/json,' + JSON.stringify(JSON.parse(link.value.substring(17)));
link.value = getLink();
link.focus();
link.select();
document.execCommand('copy');
Expand Down Expand Up @@ -300,6 +325,8 @@
<span style="position:relative;display:inline-block;left:50%;transform:translate(-50%,0);">
<h2 style="text-align:center;width:100%;">Create Custom Link</h2>
<hr>
Title: <input type="text" size="16" id="title"></input>
<hr>
1. Action for Cell(s): <select id="action" onchange="actionChanged();">
<option value="toggle" selected>Toggle</option>
<option value="show">Show</option>
Expand Down Expand Up @@ -356,6 +383,8 @@ <h2 style="text-align:center;width:100%;">Create Custom Link</h2>
<button onclick="resetLink();return false;">Reset Link</button>
<button onclick="copyLink();return false;"><b>Copy Link</b></button>
<span id="confirmation" style="display:none;font-size:10pt;padding:3px;font-weight:bold;"></span>
<br><br>
<a id="anchor" href="#" onclick="copyLink();return false;"></a>
</span>
</body>
</html>

1 comment on commit 95e039d

@davidjgraph
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed.

Please sign in to comment.