Add ability to pass URL for the card title
This commit is contained in:
31
js/main.js
31
js/main.js
@@ -265,6 +265,7 @@ function parseAndCreate(jsonData) {
|
||||
function createSqr(sqrData, index) {
|
||||
// Create a new square division with the passed element
|
||||
name = sqrData["name"];
|
||||
link = sqrData["url"];
|
||||
links = sqrData["links"];
|
||||
color = sqrData["color"];
|
||||
|
||||
@@ -286,9 +287,7 @@ function createSqr(sqrData, index) {
|
||||
|
||||
div.classList.add(customClass);
|
||||
|
||||
h4 = document.createElement("h4")
|
||||
h4.textContent = name
|
||||
|
||||
h4 = getTitle(name, link);
|
||||
|
||||
div.appendChild(h4)
|
||||
|
||||
@@ -309,6 +308,32 @@ function createSqr(sqrData, index) {
|
||||
return div
|
||||
}
|
||||
|
||||
function getTitle(titleContent, linkHref=null) {
|
||||
/**
|
||||
* Create the title for the sqr card.
|
||||
*
|
||||
* The card will be optionally clicable and will open
|
||||
* a new link.
|
||||
*
|
||||
* If the link is not passed in the config then the title
|
||||
* will not be clickable.
|
||||
*/
|
||||
h4 = document.createElement("h4");
|
||||
|
||||
if (!linkHref) {
|
||||
h4.textContent = titleContent;
|
||||
return h4;
|
||||
}
|
||||
|
||||
// If the link is passed, create a nested child
|
||||
a = document.createElement("a");
|
||||
a.setAttribute("href", linkHref);
|
||||
a.textContent = titleContent;
|
||||
|
||||
h4.appendChild(a);
|
||||
return h4;
|
||||
}
|
||||
|
||||
// Utility functions
|
||||
|
||||
function isValidTimeZone(tz) {
|
||||
|
||||
Reference in New Issue
Block a user